From c031e038df8429e14b0aa608aaa77068daa680f0 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Fri, 7 Jan 2022 18:17:19 +0600 Subject: chore: remove detection from vim.keymap --- runtime/lua/vim/keymap.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index d53b790746..df49eff4b6 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -42,7 +42,7 @@ local keymap = {} --- |nvim_replace_termcodes()| is applied to the result of Lua expr maps. --- - remap: (boolean) Make the mapping recursive. This is the --- inverse of the "noremap" option from |nvim_set_keymap()|. ---- Default `true` if `lhs` is a string starting with `` (case-insensitive), `false` otherwise. +--- Default `false`. ---@see |nvim_set_keymap()| function keymap.set(mode, lhs, rhs, opts) vim.validate { @@ -66,8 +66,8 @@ function keymap.set(mode, lhs, rhs, opts) opts.replace_keycodes = nil if opts.remap == nil then - -- remap by default on mappings and don't otherwise. - opts.noremap = is_rhs_luaref or rhs:lower():match("^") == nil + -- default remap value is false + opts.noremap = true else -- remaps behavior is opposite of noremap option. opts.noremap = not opts.remap -- cgit From a7b1c8893c602196541e94b8b24c4c70c32c25b0 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 10 Mar 2022 07:34:55 +0100 Subject: chore: fix typos (#17331) Co-authored-by: Hongyi Lyu Co-authored-by: Gregory Anders Co-authored-by: notomo Co-authored-by: zeertzjq --- runtime/lua/vim/keymap.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index df49eff4b6..7f12372502 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -25,7 +25,7 @@ local keymap = {} --- vim.keymap.set('n', 'asdf', require('jkl').my_fun) --- --- ---- the require('jkl') gets evaluated during this call in order to access the function. If you want to +--- 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: ---
 ---    vim.keymap.set('n', 'asdf', function() return require('jkl').my_fun() end)
-- 
cgit 


From d238b8f6003d34cae7f65ff7585b48a2cd9449fb Mon Sep 17 00:00:00 2001
From: dundargoc <33953936+dundargoc@users.noreply.github.com>
Date: Thu, 17 Mar 2022 06:21:24 +0100
Subject: chore: fix typos (#17670)

Co-authored-by: zeertzjq 
---
 runtime/lua/vim/keymap.lua | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'runtime/lua/vim/keymap.lua')

diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua
index 7f12372502..1be40b0081 100644
--- a/runtime/lua/vim/keymap.lua
+++ b/runtime/lua/vim/keymap.lua
@@ -25,8 +25,8 @@ local keymap = {}
 ---    vim.keymap.set('n', 'asdf', require('jkl').my_fun)
 --- 
--- ---- 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: +--- 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: ---
 ---    vim.keymap.set('n', 'asdf', function() return require('jkl').my_fun() end)
 --- 
-- cgit From 58140a94283b1c6e45099c89e66a0c94e9d90931 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 24 Mar 2022 13:22:58 +0000 Subject: feat(keymap): return nil from an expr keymap For Lua callback expr keymaps, returning `nil` or `false` is equivalent to an empty string --- runtime/lua/vim/keymap.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index 1be40b0081..c193a13a7b 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -35,6 +35,8 @@ local 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. +--- If a Lua function and `opts.expr == true`, returning `nil` or `false` +--- is equivalent to an empty string. -- ---@param opts table A table of |:map-arguments| such as "silent". In addition to the options --- listed in |nvim_set_keymap()|, this table also accepts the following keys: @@ -56,10 +58,18 @@ function keymap.set(mode, lhs, rhs, opts) local is_rhs_luaref = type(rhs) == "function" mode = type(mode) == 'string' and {mode} or mode - if is_rhs_luaref and opts.expr and opts.replace_keycodes ~= false then + if is_rhs_luaref and opts.expr then local user_rhs = rhs rhs = function () - return vim.api.nvim_replace_termcodes(user_rhs(), true, true, true) + local res = user_rhs() + if not res then + -- TODO(lewis6991): Handle this in C? + return '' + elseif opts.replace_keycodes ~= false then + return vim.api.nvim_replace_termcodes(res, true, true, true) + else + return res + end end end -- clear replace_keycodes from opts table -- cgit From 3cc29b7f0d6e1661f39d28716c6a63603a93c11c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 1 Apr 2022 09:09:30 +0100 Subject: fix(keymap): don't coerce false to '' --- runtime/lua/vim/keymap.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index c193a13a7b..0986d21196 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -35,8 +35,8 @@ local 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. ---- If a Lua function and `opts.expr == true`, returning `nil` or `false` ---- is equivalent to an empty string. +--- If a Lua function and `opts.expr == true`, returning `nil` is +--- equivalent to an empty string. -- ---@param opts table A table of |:map-arguments| such as "silent". In addition to the options --- listed in |nvim_set_keymap()|, this table also accepts the following keys: @@ -62,7 +62,7 @@ function keymap.set(mode, lhs, rhs, opts) local user_rhs = rhs rhs = function () local res = user_rhs() - if not res then + if res == nil then -- TODO(lewis6991): Handle this in C? return '' elseif opts.replace_keycodes ~= false then -- cgit From 5ecbbba6ee4364dd2ad8ae4bebd0b004ae20deaf Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Thu, 21 Apr 2022 10:15:19 +0900 Subject: docs: vim.keymap.set can specify buffer as an option --- runtime/lua/vim/keymap.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index 0986d21196..0511584526 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -40,6 +40,8 @@ local keymap = {} -- ---@param opts table A table of |:map-arguments| such as "silent". In addition to the options --- listed in |nvim_set_keymap()|, this table also accepts the following keys: +--- - buffer: (number or boolean) Add a mapping to the given buffer. When "true" +--- or 0, use the current buffer. --- - replace_keycodes: (boolean, default true) When both this and expr is "true", --- |nvim_replace_termcodes()| is applied to the result of Lua expr maps. --- - remap: (boolean) Make the mapping recursive. This is the -- cgit From 4e4914ab2e523f100c06fc5fb253f8625cc67232 Mon Sep 17 00:00:00 2001 From: Andrey Mishchenko Date: Fri, 22 Apr 2022 20:01:08 -0400 Subject: fix(lua): don't mutate opts parameter of vim.keymap.del (#18227) `vim.keymap.del` takes an `opts` parameter that lets caller refer to and delete buffer-local mappings. For some reason the implementation of `vim.keymap.del` mutates the table that is passed in, setting `opts.buffer` to `nil`. This is wrong and also undocumented. --- runtime/lua/vim/keymap.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index 0511584526..d07232f52f 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -130,7 +130,6 @@ function keymap.del(modes, lhs, opts) local buffer = false if opts.buffer ~= nil then buffer = opts.buffer == true and 0 or opts.buffer - opts.buffer = nil end if buffer == false then -- cgit From aefdc6783cb77f09786542c90901a9e7120bea42 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 9 May 2022 11:23:51 +0200 Subject: chore: format runtime with stylua --- runtime/lua/vim/keymap.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'runtime/lua/vim/keymap.lua') diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua index d07232f52f..f4c2b507a9 100644 --- a/runtime/lua/vim/keymap.lua +++ b/runtime/lua/vim/keymap.lua @@ -49,20 +49,20 @@ local keymap = {} --- Default `false`. ---@see |nvim_set_keymap()| function keymap.set(mode, lhs, rhs, opts) - vim.validate { - mode = {mode, {'s', 't'}}, - lhs = {lhs, 's'}, - rhs = {rhs, {'s', 'f'}}, - opts = {opts, 't', true} - } + vim.validate({ + mode = { mode, { 's', 't' } }, + lhs = { lhs, 's' }, + rhs = { rhs, { 's', 'f' } }, + opts = { opts, 't', true }, + }) opts = vim.deepcopy(opts) or {} - local is_rhs_luaref = type(rhs) == "function" - mode = type(mode) == 'string' and {mode} or mode + local is_rhs_luaref = type(rhs) == 'function' + mode = type(mode) == 'string' and { mode } or mode if is_rhs_luaref and opts.expr then local user_rhs = rhs - rhs = function () + rhs = function() local res = user_rhs() if res == nil then -- TODO(lewis6991): Handle this in C? @@ -118,14 +118,14 @@ end ---@see |vim.keymap.set()| --- function keymap.del(modes, lhs, opts) - vim.validate { - mode = {modes, {'s', 't'}}, - lhs = {lhs, 's'}, - opts = {opts, 't', true} - } + vim.validate({ + mode = { modes, { 's', 't' } }, + lhs = { lhs, 's' }, + opts = { opts, 't', true }, + }) opts = opts or {} - modes = type(modes) == 'string' and {modes} or modes + modes = type(modes) == 'string' and { modes } or modes local buffer = false if opts.buffer ~= nil then -- cgit