mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #16969 from shadmansaleh/enhance/ingore_nore_on_plug_keymaps
feat: ignore nore on <Plug> maps
This commit is contained in:
commit
c65d93e60a
@ -2014,9 +2014,7 @@ set({mode}, {lhs}, {rhs}, {opts}) *vim.keymap.set()*
|
||||
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 `<plug>`
|
||||
(case-insensitive), `false` otherwise.
|
||||
|nvim_set_keymap()|. Default `false` .
|
||||
|
||||
See also: ~
|
||||
|nvim_set_keymap()|
|
||||
|
@ -65,6 +65,9 @@ modes.
|
||||
where the map command applies. Disallow mapping of
|
||||
{rhs}, to avoid nested and recursive mappings. Often
|
||||
used to redefine a command.
|
||||
Note: "nore" is ignored for a mapping whose result
|
||||
starts with <Plug>. <Plug> is always remapped even if
|
||||
"nore" is used.
|
||||
|
||||
|
||||
:unm[ap] {lhs} |mapmode-nvo| *:unm* *:unmap*
|
||||
|
@ -442,6 +442,9 @@ Working directory (Vim implemented some of these later than Nvim):
|
||||
- `getcwd(-1)` is equivalent to `getcwd(-1, 0)` instead of returning the global
|
||||
working directory. Use `getcwd(-1, -1)` to get the global working directory.
|
||||
|
||||
Mappings:
|
||||
- |nore| is ignored for rhs <Plug> mappings. <Plug> mappings are always remapped.
|
||||
|
||||
==============================================================================
|
||||
5. Missing legacy features *nvim-features-missing*
|
||||
|
||||
|
@ -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 `<plug>` (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 <plug> mappings and don't otherwise.
|
||||
opts.noremap = is_rhs_luaref or rhs:lower():match("^<plug>") == nil
|
||||
-- default remap value is false
|
||||
opts.noremap = true
|
||||
else
|
||||
-- remaps behavior is opposite of noremap option.
|
||||
opts.noremap = not opts.remap
|
||||
|
@ -1710,6 +1710,15 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
|
||||
int keylen = *keylenp;
|
||||
int i;
|
||||
int local_State = get_real_state();
|
||||
bool is_plug_map = false;
|
||||
|
||||
// Check if typehead starts with a <Plug> mapping.
|
||||
// In that case we will ignore nore flag on it.
|
||||
if (typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL
|
||||
&& typebuf.tb_buf[typebuf.tb_off+1] == KS_EXTRA
|
||||
&& typebuf.tb_buf[typebuf.tb_off+2] == KE_PLUG) {
|
||||
is_plug_map = true;
|
||||
}
|
||||
|
||||
// Check for a mappable key sequence.
|
||||
// Walk through one maphash[] list until we find an entry that matches.
|
||||
@ -1725,7 +1734,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
|
||||
tb_c1 = typebuf.tb_buf[typebuf.tb_off];
|
||||
if (no_mapping == 0 && maphash_valid
|
||||
&& (no_zero_mapping == 0 || tb_c1 != '0')
|
||||
&& (typebuf.tb_maplen == 0
|
||||
&& (typebuf.tb_maplen == 0 || is_plug_map
|
||||
|| (p_remap
|
||||
&& !(typebuf.tb_noremap[typebuf.tb_off] & (RM_NONE|RM_ABBR))))
|
||||
&& !(p_paste && (State & (INSERT + CMDLINE)))
|
||||
@ -1813,7 +1822,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (n >= 0) {
|
||||
if (!is_plug_map && n >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ local meths = helpers.meths
|
||||
local clear = helpers.clear
|
||||
local command = helpers.command
|
||||
local expect = helpers.expect
|
||||
local insert = helpers.insert
|
||||
local eval = helpers.eval
|
||||
|
||||
describe(':*map', function()
|
||||
before_each(clear)
|
||||
@ -27,6 +29,39 @@ describe(':*map', function()
|
||||
feed('i-<M-">-')
|
||||
expect('-foo-')
|
||||
end)
|
||||
|
||||
it('<Plug> keymaps ignore nore', function()
|
||||
command('let x = 0')
|
||||
eq(0, meths.eval('x'))
|
||||
command [[
|
||||
nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr>
|
||||
nmap increase_x_remap <Plug>(Increase_x)
|
||||
nnoremap increase_x_noremap <Plug>(Increase_x)
|
||||
]]
|
||||
feed('increase_x_remap')
|
||||
eq(1, meths.eval('x'))
|
||||
feed('increase_x_noremap')
|
||||
eq(2, meths.eval('x'))
|
||||
end)
|
||||
it("Doesn't auto ignore nore for keys before or after <Plug> keymap", function()
|
||||
command('let x = 0')
|
||||
eq(0, meths.eval('x'))
|
||||
command [[
|
||||
nnoremap x <nop>
|
||||
nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr>
|
||||
nmap increase_x_remap x<Plug>(Increase_x)x
|
||||
nnoremap increase_x_noremap x<Plug>(Increase_x)x
|
||||
]]
|
||||
insert("Some text")
|
||||
eq('Some text', eval("getline('.')"))
|
||||
|
||||
feed('increase_x_remap')
|
||||
eq(1, meths.eval('x'))
|
||||
eq('Some text', eval("getline('.')"))
|
||||
feed('increase_x_noremap')
|
||||
eq(2, meths.eval('x'))
|
||||
eq('Some te', eval("getline('.')"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe(':*map cursor and redrawing', function()
|
||||
|
Loading…
Reference in New Issue
Block a user