aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/keymap.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2022-12-14 19:58:18 +0100
committerJustin M. Keyes <justinkz@gmail.com>2023-02-22 16:23:49 +0100
commit6752f1005d26c93a033d856a60b7b296f3e51634 (patch)
tree5681d87457d1409b848947efc637dcc8eced2a81 /runtime/lua/vim/keymap.lua
parent0b36145c696fb58e002169edd4f9a1d9a8176fc3 (diff)
downloadrneovim-6752f1005d26c93a033d856a60b7b296f3e51634.tar.gz
rneovim-6752f1005d26c93a033d856a60b7b296f3e51634.tar.bz2
rneovim-6752f1005d26c93a033d856a60b7b296f3e51634.zip
docs: naming conventions, guidelines
close #21063
Diffstat (limited to 'runtime/lua/vim/keymap.lua')
-rw-r--r--runtime/lua/vim/keymap.lua50
1 files changed, 17 insertions, 33 deletions
diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua
index ef1c66ea20..911b584c14 100644
--- a/runtime/lua/vim/keymap.lua
+++ b/runtime/lua/vim/keymap.lua
@@ -1,51 +1,35 @@
local keymap = {}
---- Add a new |mapping|.
+--- Adds a new |mapping|.
--- Examples:
--- <pre>lua
---- -- Can add mapping to Lua functions
+--- -- Map to a Lua function:
--- vim.keymap.set('n', 'lhs', function() print("real lua function") end)
----
---- -- Can use it to map multiple modes
+--- -- Map to multiple modes:
--- vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, { buffer=true })
----
---- -- Can add mapping for specific buffer
+--- -- Buffer-local mapping:
--- vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", { silent = true, buffer = 5 })
----
---- -- Expr mappings
+--- -- Expr mapping:
--- vim.keymap.set('i', '<Tab>', function()
--- return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>"
--- end, { expr = true })
---- -- <Plug> mappings
+--- -- <Plug> mapping:
--- vim.keymap.set('n', '[%%', '<Plug>(MatchitNormalMultiBackward)')
--- </pre>
---
---- Note that in a mapping like:
---- <pre>lua
---- vim.keymap.set('n', 'asdf', require('jkl').my_fun)
---- </pre>
----
---- the ``require('jkl')`` gets evaluated during this call in order to access the function.
---- If you want to avoid this cost at startup you can wrap it in a function, for example:
---- <pre>lua
---- vim.keymap.set('n', 'asdf', function() return require('jkl').my_fun() end)
---- </pre>
----
----@param mode string|table Same mode short names as |nvim_set_keymap()|.
+---@param mode string|table Mode short-name, see |nvim_set_keymap()|.
--- Can also be list of modes to create mapping on multiple modes.
---@param lhs string Left-hand side |{lhs}| of the mapping.
----@param rhs string|function Right-hand side |{rhs}| of the mapping. Can also be a Lua function.
---
----@param opts table|nil A table of |:map-arguments|.
---- + Accepts options accepted by the {opts} parameter in |nvim_set_keymap()|,
---- with the following notable differences:
---- - replace_keycodes: Defaults to `true` if "expr" is `true`.
---- - noremap: Always overridden with the inverse of "remap" (see below).
---- + In addition to those options, the table accepts the following keys:
---- - buffer: (number or boolean) Add a mapping to the given buffer.
---- When `0` or `true`, use the current buffer.
---- - remap: (boolean) Make the mapping recursive.
---- This is the inverse of the "noremap" option from |nvim_set_keymap()|.
+---@param rhs string|function Right-hand side |{rhs}| of the mapping, can be a Lua function.
+---
+---@param opts table|nil Table of |:map-arguments|.
+--- - Same as |nvim_set_keymap()| {opts}, except:
+--- - "replace_keycodes" defaults to `true` if "expr" is `true`.
+--- - "noremap": inverse of "remap" (see below).
+--- - Also accepts:
+--- - "buffer" number|boolean Creates buffer-local mapping, `0` or `true`
+--- for current buffer.
+--- - remap: (boolean) Make the mapping recursive. Inverses "noremap".
--- Defaults to `false`.
---@see |nvim_set_keymap()|
function keymap.set(mode, lhs, rhs, opts)