which-key.nvim icon indicating copy to clipboard operation
which-key.nvim copied to clipboard

Preserve order of the mappings defined in wk.register()

Open rainux opened this issue 3 years ago • 2 comments

Currently, the mappings were grouped by key prefixes, but for convenient use, we often use the same key prefix for completely unrelated commands, which will make WhichKey's display a bit messy.

For example I have the following configurations:

wk.register({
  c = {
    name = 'Convenient Commands',
    c = { '<Plug>NERDCommenterComment', 'NERDCommenter Comment' },
    m = { '<Plug>NERDCommenterMinimal', 'NERDCommenter Minimal' },
    n = { '<Plug>NERDCommenterNest', 'NERDCommenter Nest' },
    s = { '<Plug>NERDCommenterSexy', 'NERDCommenter Sexy' },
    u = { '<Plug>NERDCommenterUncomment', 'NERDCommenter Uncomment' },
    ['<Space>'] = { '<Plug>NERDCommenterToggle', 'NERDCommenter Toggle' },

    t = { '<cmd>Telescope<CR>', 'Telescope' },
    b = { '<cmd>Telescope buffers<CR>', 'Telescope Buffers' },
    f = { '<cmd>Telescope find_files<CR>', 'Find Files' },
    g = { '<cmd>Telescope live_grep<CR>', 'Telescope Live Grep' },
    h = { '<cmd>Telescope help_tags<CR>', 'Telescope Help Tags' },
    k = { '<cmd>Telescope keymaps<CR>', 'Telescope Keymaps' },
    l = { '<cmd>Telescope colorscheme<CR>', 'Telescope Color Scheme' },
    r = { '<cmd>Telescope oldfiles<CR>', 'Open Recent File' },
  },
}, { mode = 'n', prefix = ',' })

WhichKey will render them as following:

image

The commands are sorted by key in the alphabet, making it hard to quickly recognize commands. If the commands were rendered in the same order of the configuration, we can recognize commands much quicker.

This makes me think a bit more, if WhichKey has the ability to group commands in the same key prefix, the problem will be solved more gracefully: users can explicitly define different groups under the same key prefix, and the mappings made without WhichKey but match current key prefix can be grouped in a "Misc" group, instead of simply hiding them with ignore_missing = true.

rainux avatar Mar 20 '22 00:03 rainux

I also need this feature!

nyngwang avatar Dec 04 '22 09:12 nyngwang