aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/keymap.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-01-14 23:10:03 -0700
committerJosh Rahm <joshuarahm@gmail.com>2023-01-14 23:10:03 -0700
commit396c48d54ef313ca02e2e97849e51721094400cd (patch)
tree87857ac4a5a7f88e2ebc519e73df061f9ed2f8e1 /runtime/lua/vim/keymap.lua
parent968aa6e3ed0497ea99f123c74c5fd0f3880ccc63 (diff)
parent6134c1e8a39a5e61d0593613343a5923a86e3545 (diff)
downloadrneovim-396c48d54ef313ca02e2e97849e51721094400cd.tar.gz
rneovim-396c48d54ef313ca02e2e97849e51721094400cd.tar.bz2
rneovim-396c48d54ef313ca02e2e97849e51721094400cd.zip
Merge remote-tracking branch 'upstream/master' into userreg
Diffstat (limited to 'runtime/lua/vim/keymap.lua')
-rw-r--r--runtime/lua/vim/keymap.lua39
1 files changed, 19 insertions, 20 deletions
diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua
index 219de16b5c..ef1c66ea20 100644
--- a/runtime/lua/vim/keymap.lua
+++ b/runtime/lua/vim/keymap.lua
@@ -2,7 +2,7 @@ local keymap = {}
--- Add a new |mapping|.
--- Examples:
---- <pre>
+--- <pre>lua
--- -- Can add mapping to Lua functions
--- vim.keymap.set('n', 'lhs', function() print("real lua function") end)
---
@@ -21,13 +21,13 @@ local keymap = {}
--- </pre>
---
--- Note that in a mapping like:
---- <pre>
+--- <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>
+--- <pre>lua
--- vim.keymap.set('n', 'asdf', function() return require('jkl').my_fun() end)
--- </pre>
---
@@ -36,17 +36,17 @@ local keymap = {}
---@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 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()|.
---- Defaults to `false`.
+---@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()|.
+--- Defaults to `false`.
---@see |nvim_set_keymap()|
function keymap.set(mode, lhs, rhs, opts)
vim.validate({
@@ -57,7 +57,6 @@ function keymap.set(mode, lhs, rhs, opts)
})
opts = vim.deepcopy(opts) or {}
- local is_rhs_luaref = type(rhs) == 'function'
mode = type(mode) == 'string' and { mode } or mode
if opts.expr and opts.replace_keycodes ~= false then
@@ -73,7 +72,7 @@ function keymap.set(mode, lhs, rhs, opts)
opts.remap = nil
end
- if is_rhs_luaref then
+ if type(rhs) == 'function' then
opts.callback = rhs
rhs = ''
end
@@ -94,14 +93,14 @@ end
--- Remove an existing mapping.
--- Examples:
---- <pre>
+--- <pre>lua
--- vim.keymap.del('n', 'lhs')
---
--- vim.keymap.del({'n', 'i', 'v'}, '<leader>w', { buffer = 5 })
--- </pre>
----@param opts table A table of optional arguments:
---- - buffer: (number or boolean) Remove a mapping from the given buffer.
---- When "true" or 0, use the current buffer.
+---@param opts table|nil A table of optional arguments:
+--- - buffer: (number or boolean) Remove a mapping from the given buffer.
+--- When "true" or 0, use the current buffer.
---@see |vim.keymap.set()|
---
function keymap.del(modes, lhs, opts)