Could someone please elucidate how "merging" specs works and what "parent specs" are? #1706
-
The docs mention that specs can be merged with "parent specs", but I can not wrap my head around what is meant by that exactly. I created a file return {
"folke/which-key.nvim",
dependencies = { "nvim-tree/nvim-web-devicons", opts = {} },
opts = {
spec = {
{ "<C-h>", "<C-w>h" },
{ "<C-j>", "<C-w>j" },
{ "<C-k>", "<C-w>k" },
{ "<C-l>", "<C-w>l" },
},
},
} and a file return {
{
"nvim-tree/nvim-tree.lua",
dependencies = {
{ "nvim-tree/nvim-web-devicons", opts = {} },
},
opts = {},
},
{
"folke/which-key.nvim",
opts = {
spec = { "<Leader>e", vim.cmd.NvimTreeFindFileToggle, desc = "explorer" },
},
},
} with the intention of having plugin configuration and keymaps close together. From the docs, I expected the which-key I think LazyVim does the same thing e.g. here, but I don't know what it does differently to make it work. Could someone please explain how I can actually merge plugin specs from different files? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The problem in your case is that only But But you should make sure that |
Beta Was this translation helpful? Give feedback.
The problem in your case is that only
key-value
tables can be merged.list-like
tables will be overridden normally (and which-keyopts.spec
is alist-like
table).But
lazy.nvim
has another fairly recent feature and that isopts_extend
. With this you can definelist-like
tables that will be merged bylazy.nvim
as well instead of overwritten. That is what LazyVim also uses (see here).But you should make sure that
opts_extend
is present in the parent spec (I believe?? Not 100% sure about that).lazy.nvim
parses the files alphabetically, so the first file that will be parsed and has awhich-key
spec in it will be considered as the parent spec.