From f3b7444e6638095305d86fa96fe0b7407c9b1648 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 25 Sep 2024 07:01:27 -0700 Subject: refactor(lua): vim.keymap.set tests, docs #30511 --- runtime/lua/vim/keymap.lua | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index ec00c56c7a..50ca0d2d0e 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -15,30 +15,28 @@ local keymap = {} --- (Default: `false`) --- @field remap? boolean ---- Adds a new |mapping|. +--- Defines a |mapping| of |keycodes| to a function or keycodes. +--- --- Examples: --- --- ```lua ---- -- Map to a Lua function: ---- vim.keymap.set('n', 'lhs', function() print("real lua function") end) ---- -- Map to multiple modes: ---- vim.keymap.set({'n', 'v'}, 'lr', vim.lsp.buf.references, { buffer = true }) ---- -- Buffer-local mapping: ---- vim.keymap.set('n', 'w', "w", { silent = true, buffer = 5 }) ---- -- Expr mapping: +--- -- Map "x" to a Lua function: +--- vim.keymap.set('n', 'x', function() print("real lua function") end) +--- -- Map "x" to multiple modes for the current buffer: +--- vim.keymap.set({'n', 'v'}, 'x', vim.lsp.buf.references, { buffer = true }) +--- -- Map to an expression (|:map-|): --- vim.keymap.set('i', '', function() --- return vim.fn.pumvisible() == 1 and "" or "" --- end, { expr = true }) ---- -- mapping: +--- -- Map "[%%" to a mapping: --- vim.keymap.set('n', '[%%', '(MatchitNormalMultiBackward)') --- ``` --- ----@param mode string|string[] Mode short-name, see |nvim_set_keymap()|. ---- Can also be list of modes to create mapping on multiple modes. +---@param mode string|string[] Mode "short-name" (see |nvim_set_keymap()|), or a list thereof. ---@param lhs string Left-hand side |{lhs}| of the mapping. ---@param rhs string|function Right-hand side |{rhs}| of the mapping, can be a Lua function. ---- ---@param opts? vim.keymap.set.Opts +--- ---@see |nvim_set_keymap()| ---@see |maparg()| ---@see |mapcheck()| -- cgit