folke / which-key.nvim

💥 Create key bindings that stick. WhichKey helps you remember your Neovim keymaps, by showing available keybindings in a popup as you type.
Apache License 2.0
5.38k stars 177 forks source link

feat(keys): `desc` in <nop> keymaps can now become prefix label #522

Closed pk-kampanart closed 5 months ago

pk-kampanart commented 1 year ago

Example:

...
map("n", "<leader>h", "<Nop>", {desc = "Help Prefix"})
map("n", "<leader>p", "<Nop>", {desc = "Projects Prefix"})
map("n", "<leader>f", "<Nop>", {desc = "File Prefix"})
map("n", "<leader>b", "<Nop>", {desc = "Buffer Prefix"})
map("n", "<leader>c", "<Nop>", {desc = "Coding Prefix"})
map("n", "<leader>g", "<Nop>", {desc = "Git Prefix"})
map("n", "<leader>d", "<Nop>", {desc = "Diagnostic Prefix"})
map("n", "<leader>t", "<Nop>", {desc = "Toggle & Setting Prefix"})
...

test

folke commented 5 months ago

This is actually really cool. Was just looking to implement something similar :)

fyi: It also works with an empty mapping like

map("n", "<leader>h", "", {desc = "Help Prefix"})
folke commented 5 months ago

Thanks!

bluss commented 5 months ago

Trying to set up a prefix like this (with updated which-key (c1958e2) and lazy.nvim (0c1ec52)). Using the keys table in lazy.nvim config:

    {"<leader>t", "<nop>", mode = "n", desc = "+terminal" },
    {"<leader>tf", "<cmd>ToggleTerm direction=float<cr>", mode = "n", desc = "Toggleterm float"},

Which-key doesn't toggle for this key mapping (if it's typed fast enough), which is a drawback. I would wish for a UX where <leader>t will open which-key and wait for the real kemap (<leader>tf for toggleterm float etc.)

folke commented 5 months ago

@bluss can you update both which-key and lazy?

bluss commented 5 months ago

updated both. Fwiw, the behaviour is still the same (before and after lazy load too); typing <leader>t quick enough is just a nop and doesn't open which-key. Don't know if that's expected. Neovim v0.10.0

folke commented 5 months ago

which-key indeed has to have run at least once, otherwise your nop keymap would be executed. You can still use register like before. That still works.

bluss commented 5 months ago

Got it, thank you!

folke commented 5 months ago

There was indeed something wrong there and should now be fixed!

https://github.com/folke/which-key.nvim/commit/ccf027625df6c4e22febfdd786c5e1f7521c2ccb

bluss commented 4 months ago

Thank you @folke. It works like I would prefer now (which-key 0099511, lazy eb49574). This case still is a minor fail: In that configuration above, if <leader>tf is pressed fast enough (no which-key trigger) then any <leader>t after that does not trigger which-key to open.