which-key.nvim
which-key.nvim copied to clipboard
bug: Mappings inconsistent over different modes
Did you check docs and existing issues?
- [X] I have read all the which-key.nvim docs
- [X] I have searched the existing issues of which-key.nvim
- [X] I have searched the existing issues of plugins related to this issue
Neovim version (nvim -v)
NVIM v0.9.1
Operating system/version
Windows 10 (10.0.19045)
Describe the bug
Given the following mappings:
M.wk_mappings = {
f = { "[F]ind" },
c = { name = "[C]ode" },
w = { "[W]orkplace" },
t = {
name = "[T]erminal",
s = { "[S]end" },
},
}
and the following set of keybindings:
map("n", "<leader>tsl", ":SendToTerminal line<CR>", default_opts, "[L]ine")
map("n", "<leader>tsb", ":SendToTerminal buffer<CR>", default_opts, "[B]uffer")
map("v", "<leader>tss", ":SendToTerminal selection<CR>", default_opts, "[S]election")
The normal mode mappings will work fine. Once I have a visual selection and trigger which-key with <leader>
the labels for t
don't get applied. They will show but only with the name +prefix
for t
and s
respectively. What am I missing?
Steps To Reproduce
- Take the aforementioned mappings
- Highlight text in visual mode
- Trigger which-key with
<leader>
Expected Behavior
Shows the same label names as in normal mode.
Repro
No response
This comment gave the right hint. I made to following updates to my bindings:
M.wk_register_n = {
f = { "[F]ind" },
c = { name = "[C]ode" },
w = { "[W]orkplace" },
t = {
name = "[T]erminal",
s = { "[S]end" },
},
}
M.wk_register_v = {
t = {
name = "[T]erminal",
s = { "[S]end" },
},
}
and updated my spec like so:
{
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
plugins = {
spelling = { enabled = true },
},
},
config = function()
require("which-key").register({ require("config.keymaps").wk_register_n },
{ mode = "n", prefix = "<leader>" })
require("which-key").register({ require("config.keymaps").wk_register_v },
{ mode = "v", prefix = "<leader>" })
end
}
Labels are now showing as expected. Is this how I'm supposed to do this?
For some reason it is more consistent if you're binding without explicit prefix but rather using ["<leader>"]
directly in the binding. Then if setting mode { "n", "v" }
it's binding in both modes as expected. I guess thats why it is also done this way in LazyVim
?
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.