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

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

Open andreihh opened this issue 1 year ago • 22 comments

Did you check the docs?

  • [X] 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 avatar Dec 15 '24 12:12 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jan 15 '25 01:01 github-actions[bot]

I prepared https://github.com/folke/which-key.nvim/pull/932 to fix this. I tested locally and seems to work fine. I didn't find any documentation for the WhichKey command, so I don't think there's anything else that needs updating.

andreihh avatar Jan 17 '25 10:01 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Feb 17 '25 02:02 github-actions[bot]

Bump. The issue is not stale. There is a 1-line PR ready.

andreihh avatar Feb 17 '25 20:02 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Mar 20 '25 02:03 github-actions[bot]

Bump. The issue is not stale. There is a 1-line PR ready.

andreihh avatar Mar 20 '25 23:03 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Apr 20 '25 02:04 github-actions[bot]

Bump. The issue is not stale. There is a 1-line PR ready.

andreihh avatar Apr 21 '25 11:04 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 22 '25 02:05 github-actions[bot]

Bump. The issue is not stale. There is a 1-line PR ready.

andreihh avatar May 25 '25 15:05 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jun 25 '25 02:06 github-actions[bot]

Bump. The issue is not stale. There is a 1-line PR ready.

andreihh avatar Jun 25 '25 06:06 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jul 30 '25 02:07 github-actions[bot]

This issue is not stale.

andreihh avatar Jul 30 '25 20:07 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Aug 31 '25 02:08 github-actions[bot]

Issue is not stale.

andreihh avatar Aug 31 '25 10:08 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Oct 02 '25 02:10 github-actions[bot]

Issue is not stale.

andreihh avatar Oct 03 '25 13:10 andreihh

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Nov 03 '25 02:11 github-actions[bot]

Issue is not stale.

andreihh avatar Nov 03 '25 08:11 andreihh