mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
docs(lua): opts in vim.keymap.{set,del}
can be optional (#20255)
This commit is contained in:
parent
10196f1b46
commit
e762158305
@ -2212,7 +2212,7 @@ del({modes}, {lhs}, {opts}) *vim.keymap.del()*
|
|||||||
<
|
<
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
{opts} (table) A table of optional arguments:
|
{opts} (table|nil) A table of optional arguments:
|
||||||
• buffer: (number or boolean) Remove a mapping from the given
|
• buffer: (number or boolean) Remove a mapping from the given
|
||||||
buffer. When "true" or 0, use the current buffer.
|
buffer. When "true" or 0, use the current buffer.
|
||||||
|
|
||||||
@ -2257,7 +2257,7 @@ set({mode}, {lhs}, {rhs}, {opts}) *vim.keymap.set()*
|
|||||||
{lhs} (string) Left-hand side |{lhs}| of the mapping.
|
{lhs} (string) Left-hand side |{lhs}| of the mapping.
|
||||||
{rhs} string|function Right-hand side |{rhs}| of the mapping. Can
|
{rhs} string|function Right-hand side |{rhs}| of the mapping. Can
|
||||||
also be a Lua function.
|
also be a Lua function.
|
||||||
{opts} (table) A table of |:map-arguments|.
|
{opts} (table|nil) A table of |:map-arguments|.
|
||||||
• Accepts options accepted by the {opts} parameter in
|
• Accepts options accepted by the {opts} parameter in
|
||||||
|nvim_set_keymap()|, with the following notable differences:
|
|nvim_set_keymap()|, with the following notable differences:
|
||||||
• replace_keycodes: Defaults to `true` if "expr" is `true`.
|
• replace_keycodes: Defaults to `true` if "expr" is `true`.
|
||||||
|
@ -36,17 +36,17 @@ local keymap = {}
|
|||||||
---@param lhs string Left-hand side |{lhs}| of the mapping.
|
---@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 rhs string|function Right-hand side |{rhs}| of the mapping. Can also be a Lua function.
|
||||||
--
|
--
|
||||||
---@param opts table A table of |:map-arguments|.
|
---@param opts table|nil A table of |:map-arguments|.
|
||||||
--- + Accepts options accepted by the {opts} parameter in |nvim_set_keymap()|,
|
--- + Accepts options accepted by the {opts} parameter in |nvim_set_keymap()|,
|
||||||
--- with the following notable differences:
|
--- with the following notable differences:
|
||||||
--- - replace_keycodes: Defaults to `true` if "expr" is `true`.
|
--- - replace_keycodes: Defaults to `true` if "expr" is `true`.
|
||||||
--- - noremap: Always overridden with the inverse of "remap" (see below).
|
--- - noremap: Always overridden with the inverse of "remap" (see below).
|
||||||
--- + In addition to those options, the table accepts the following keys:
|
--- + In addition to those options, the table accepts the following keys:
|
||||||
--- - buffer: (number or boolean) Add a mapping to the given buffer.
|
--- - buffer: (number or boolean) Add a mapping to the given buffer.
|
||||||
--- When `0` or `true`, use the current buffer.
|
--- When `0` or `true`, use the current buffer.
|
||||||
--- - remap: (boolean) Make the mapping recursive.
|
--- - remap: (boolean) Make the mapping recursive.
|
||||||
--- This is the inverse of the "noremap" option from |nvim_set_keymap()|.
|
--- This is the inverse of the "noremap" option from |nvim_set_keymap()|.
|
||||||
--- Defaults to `false`.
|
--- Defaults to `false`.
|
||||||
---@see |nvim_set_keymap()|
|
---@see |nvim_set_keymap()|
|
||||||
function keymap.set(mode, lhs, rhs, opts)
|
function keymap.set(mode, lhs, rhs, opts)
|
||||||
vim.validate({
|
vim.validate({
|
||||||
@ -57,7 +57,6 @@ function keymap.set(mode, lhs, rhs, opts)
|
|||||||
})
|
})
|
||||||
|
|
||||||
opts = vim.deepcopy(opts) or {}
|
opts = vim.deepcopy(opts) or {}
|
||||||
local is_rhs_luaref = type(rhs) == 'function'
|
|
||||||
mode = type(mode) == 'string' and { mode } or mode
|
mode = type(mode) == 'string' and { mode } or mode
|
||||||
|
|
||||||
if opts.expr and opts.replace_keycodes ~= false then
|
if opts.expr and opts.replace_keycodes ~= false then
|
||||||
@ -73,7 +72,7 @@ function keymap.set(mode, lhs, rhs, opts)
|
|||||||
opts.remap = nil
|
opts.remap = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_rhs_luaref then
|
if type(rhs) == 'function' then
|
||||||
opts.callback = rhs
|
opts.callback = rhs
|
||||||
rhs = ''
|
rhs = ''
|
||||||
end
|
end
|
||||||
@ -99,9 +98,9 @@ end
|
|||||||
---
|
---
|
||||||
--- vim.keymap.del({'n', 'i', 'v'}, '<leader>w', { buffer = 5 })
|
--- vim.keymap.del({'n', 'i', 'v'}, '<leader>w', { buffer = 5 })
|
||||||
--- </pre>
|
--- </pre>
|
||||||
---@param opts table A table of optional arguments:
|
---@param opts table|nil A table of optional arguments:
|
||||||
--- - buffer: (number or boolean) Remove a mapping from the given buffer.
|
--- - buffer: (number or boolean) Remove a mapping from the given buffer.
|
||||||
--- When "true" or 0, use the current buffer.
|
--- When "true" or 0, use the current buffer.
|
||||||
---@see |vim.keymap.set()|
|
---@see |vim.keymap.set()|
|
||||||
---
|
---
|
||||||
function keymap.del(modes, lhs, opts)
|
function keymap.del(modes, lhs, opts)
|
||||||
|
Loading…
Reference in New Issue
Block a user