Use require("which-key").add() to define mappings or groups. This method can be called multiple times.
Mapping Attributes:
lhs (string, required): The key sequence.rhs (string|fun, optional): The command or function to execute.desc (string|fun, required for non-groups): The description shown in the popup.group (string|fun, optional): The name of the group this mapping belongs to.mode (string|string[], optional): The mode (defaults to "n").cond (boolean|fun, optional): Condition to enable the mapping.hidden (boolean, optional): If true, hides the mapping from the popup.icon (string|wk.Icon|fun, optional): Icon specification.proxy (string, optional): Proxy to another mapping.expand (fun, optional): Function to create dynamic nested mappings.
Note: desc, group, and icon can be functions that are evaluated every time the popup is shown.
local wk = require("which-key")
wk.add({
{ "<leader>f", group = "file" }, -- group
{ "<leader>ff", "<cmd>Telescope find_files<cr>", desc = "Find File", mode = "n" },
{ "<leader>fb", function() print("hello") end, desc = "Foobar" },
{ "<leader>fn", desc = "New File" },
{ "<leader>f1", hidden = true }, -- hide this keymap
{ "<leader>w", proxy = "<c-w>", group = "windows" }, -- proxy to window mappings
{ "<leader>b", group = "buffers", expand = function()
return require("which-key.extras").expand.buf()
end
},
{
-- Nested mappings are allowed and can be added in any order
-- Most attributes can be inherited or overridden on any level
-- There's no limit to the depth of nesting
mode = { "n", "v" }, -- NORMAL and VISUAL mode
{ "<leader>q", "<cmd>q<cr>", desc = "Quit" }, -- no need to specify mode since it's inherited
{ "<leader>w", "<cmd>w<cr>", desc = "Write" },
}
})