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

feature: WhichKey command should display keymaps for current mode by default #914

Open
1 task done
andreihh opened this issue Dec 15, 2024 · 0 comments
Open
1 task done
Labels
enhancement New feature or request

Comments

@andreihh
Copy link

andreihh commented Dec 15, 2024

Did you check the docs?

  • I have read all the which-key.nvim docs

Is your feature request related to a problem? Please describe.

The :WhichKey command shows the keymaps for the provided mode parameter, or for normal mode if none is specified.

This means that running the command from other modes (e.g., insert or visual) will not show the proper keymaps and we need to provide the mode explicitly, which is a bit more cumbersome, especially if the :WhichKey command is bound to a keymap.

Describe the solution you'd like

The :WhichKey command should display keymaps for the current mode if the mode parameter is not specified.

Proposed fix: change config.lua, line 313 from mode = "n" to mode = vim.api.nvim_get_mode().mode.

Describe alternatives you've considered

It's possible to configure mode-specific keymaps that run :WhichKey with the appropriate parameter. e.g., instead of:

keys = {
  {
    "<C-\\>",
    "<cmd>WhichKey<CR>",
    mode = { "n", "i", "x", "s", "o", "t", "c" },
    desc = "Show keymaps (which-key)",
  },
},

something along the lines of:

keys = {
  {
    "<C-\\>",
    "<cmd>WhichKey i<CR>",
    mode = "i",
    desc = "Show keymaps (which-key)",
  },
  {
    "<C-\\>",
    "<cmd>WhichKey x<CR>",
    mode = "x",
    desc = "Show keymaps (which-key)",
  },
  ...
},

I've also thought about using a generic mapping similar to:

{
  "<C-\\>",
  "':WhichKey ' . mode() . '<CR>'",
  mode = { "n", "i", "x", "s", "o", "t", "c" },
  desc = "Show keymaps (which-key)",
  expr = true,
},

However, that doesn't work because entering a command from different modes requires different prefixes (: from normal, <C-o> from insert, need to remove the range prefix in visual mode, etc.).

These solutions are unnecessarily complex.

Additional context

No response

@andreihh andreihh added the enhancement New feature or request label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant