which-key.nvim
which-key.nvim copied to clipboard
Collapse multiple keybindings under a single label?
Is it possible to configure multiple keybindings under a single which-key label?
For example, I have the following similar bindings:
<leader>1bound to"<cmd>1wincmd w<CR>"<leader>2bound to"<cmd>2wincmd w<CR>"<leader>3bound to"<cmd>3wincmd w<CR>"...<leader>9bound to"<cmd>9wincmd w<CR>"
If I just add all the above to which-key I end up with the popup completely swamped with a multitude of similar key mappings
1 -> Select window 1 4 -> Select window 4 7 -> Select window 7
2 -> Select window 2 5 -> Select window 5 8 -> Select window 8
3 -> Select window 3 6 -> Select window 6 9 -> Select window 9
I would instead like to "collapse" them all into a single menu item
1..9 -> Select window 1..9
I would like to do something like:
require("which-key").register({ [ "<leader>1..9" ] = { "Select window 1..9" } })
However, this seems to fail somewhere - the keybinding isn't added to which-key.
Is there a way to have which-key display something like 1..9 -> Select window 1..9?
What I'm hoping for is to replicate the 1..9 in the below example image, which is taken from the spacemacs config in emacs

You can hide some entries using which_key_ignore key, for example:
...
['2'] = { '<cmd>echo 2<CR>', 'which_key_ignore'},
...
Still I don't know how to display something that looks like 1..9 or so.
You can also get some different approach, move 1..9 to a subgroup to reduce clutter:
...
w = {
name = 'Go to window',
x = '1..10', -- group has to contain some visible entry
['1'] = { '<cmd>echo 1<CR>', 'which_key_ignore'},
['2'] = { '<cmd>echo 2<CR>', 'which_key_ignore'},
['3'] = { '<cmd>echo 3<CR>', 'which_key_ignore'},
['4'] = { '<cmd>echo 4<CR>', 'which_key_ignore'},
['5'] = { '<cmd>echo 5<CR>', 'which_key_ignore'},
['6'] = { '<cmd>echo 6<CR>', 'which_key_ignore'},
['7'] = { '<cmd>echo 7<CR>', 'which_key_ignore'},
['8'] = { '<cmd>echo 8<CR>', 'which_key_ignore'},
['9'] = { '<cmd>echo 9<CR>', 'which_key_ignore'},
['10'] = { '<cmd>echo 10<CR>', 'which_key_ignore'},
},
...
Or jump one by one (repeatable):
...
w = {
name = 'Window',
j = { '<C-w>j<cmd>WhichKey <LT>Leader>w<CR>', 'Go down' },
k = { '<C-w>k<cmd>WhichKey <LT>Leader>w<CR>', 'Go up' },
h = { '<C-w>h<cmd>WhichKey <LT>Leader>w<CR>', 'Go left' },
l = { '<C-w>l<cmd>WhichKey <LT>Leader>w<CR>', 'Go right' },
d = { '<C-w>c<cmd>WhichKey <LT>Leader>w<CR>', 'Delete' },
s = { '<C-w>s<cmd>WhichKey <LT>Leader>w<CR>', 'Split horizontal' },
v = { '<C-w>v<cmd>WhichKey <LT>Leader>w<CR>', 'Split vertical' },
},
...
Let me know if there is a better way.