folke / which-key.nvim

💥 Create key bindings that stick. WhichKey helps you remember your Neovim keymaps, by showing available keybindings in a popup as you type.
Apache License 2.0
4.99k stars 160 forks source link

feature: Excluding a mapped key #541

Closed Myzel394 closed 3 weeks ago

Myzel394 commented 8 months ago

Did you check the docs?

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

Given the following maps:

for i = 1, 10 do
    vim.keymap.set("n", "<leader>" .. i, function() ui.nav_file(i) end)
end

it's obvious for me what <leader> + number does. I'd like to be able to exclude them from showing up in which-key.

Describe the solution you'd like

Add an option to make fields hidden.

Describe alternatives you've considered

I tried to add them to hidden using:

hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "^:", "^ ", "^call ", "^lua ", "<leader>1", "^<leader>1", ... plus the other numbers }

and also tried to create a custom mapping as instructed in https://github.com/folke/which-key.nvim#%EF%B8%8F-mappings but the key was still shown.

Additional context

No response

gagiD commented 8 months ago

+1

arpangreat commented 8 months ago

If you are using custom mappings using which key itself, just pass which_key_ignore label in the name/desc of the command , it's in the mappings section of the readme.

gagiD commented 8 months ago

@arpangreat Thank you.

For the record, this works for me:

local opts = { noremap = true, silent = true, desc = "which_key_ignore" }

vim.api.nvim_set_keymap("n", "<leader>1", ":BufferLineGoToBuffer 1<CR>", opts)
github-actions[bot] commented 1 month ago

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.