Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rainux opened this issue Mar 20, 2022 · 2 comments
Open

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

rainux opened this issue Mar 20, 2022 · 2 comments

Comments

@rainux
Copy link

rainux commented Mar 20, 2022

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.

@nyngwang
Copy link

nyngwang commented Dec 4, 2022

I also need this feature!

@t18n
Copy link

t18n commented May 16, 2024

This approved PR seems to solve the issue
#486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants