Hello there.
This might be a bit dumb, but I have two Plugins I would like to have that just wont work together nicely.
- The first one is lazy.nvim, a nice package manager, where one of its nicest features is that it can help you lazy-load many of your packages. To achieve that, it offers you to let it manage and set your keymappings for your plugins for you. If you do, the affected package will only load after the key combo is invoked. I’d like to have that.
- On the other hand are whichkey and legendary, These two working together can create you pretty helpmenus and legends for all your commands and keybindings. These menus can even be automatically nested and labeled if you let whichkey manage and set your keymappings for you.
I would like to have both of these capabilities, but the obvious question then becomes: Who gets to manage my keybindings? I would like whichkey to do that, so that legendary has full access to the associated functionality, but then lazy has trouble properly loading my packages when required.
My current approach looks like this:
- store all my mappings stored in a big nested table that whichkey understands
- create a transformed copy of that in a format that lazy understands, without the functionality, just the key
- call
require("lazy").setup
, provide the stripped down mappings where applicable. - pass the original table over to whichkey to register.
The tables look like this:
wktable = {
undotree = {
keys = {
["<Leader>"] = {
u = { ":UndotreeToggle<CR>", "toggle undotree" }
},
},
opts = {},
},
-- ... more here
}
lazykeys = flatten(wktable)
-- -> {undotree = { { "<Leader>u", mode = "n" } }, .... }
It seems this is not enough to convince lazy to load undotree on ‘u’ when required (I get an Error: UndotreeToggle is not an Editor command). After much confusions I found that Lazy’s section about keybindings notes that, if the rhs-part of a binding is missing, the actual binding needs to be created in the plugins setup function, but I want to register the binding in whichkey beforehand, else my menus and legends would not contains this plugins bindings until it is loaded.
Is there maybe a command to manually prompt lazy to load a plugin? Then I could shift the responsibility of loading the packages at the right time away from lazy and into the actual keybindings.
This all seems a bit extra silly since all these packages are from the same author. Am I doing something wrong? Any help is appreciated. If you need I can give you my full config, bit its a bit lengthy at this point.