From e8107f07486ce9dffdc020baf12836e55bf90ce5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 3 Mar 2022 21:59:28 +0800 Subject: [PATCH] vim-patch:8.2.4498: using with "noremap" does not work Problem: Using with "noremap" does not work. Solution: Always remap . (closes vim/vim#9879, closes vim/vim#9789) https://github.com/vim/vim/commit/1fc34225acbee5ddca2b9ec3f82b3014d385b7f8 --- runtime/doc/map.txt | 4 ++-- runtime/doc/vim_diff.txt | 4 ---- src/nvim/getchar.c | 7 +++---- src/nvim/testdir/test_mapping.vim | 30 ++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index 8715c3231c..b874d6dc61 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -65,8 +65,8 @@ modes. where the map command applies. Disallow mapping of {rhs}, to avoid nested and recursive mappings. Often used to redefine a command. - Note: A mapping whose {lhs} starts with is - always applied even if mapping is disallowed. + Note: When appears in the {rhs} this part is + always applied even if remapping is disallowed. :unm[ap] {lhs} |mapmode-nvo| *:unm* *:unmap* diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 90f56e2566..5ea6a9c5dd 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -358,10 +358,6 @@ Macro/|recording| behavior macros and 'keymap' at the same time. This also means you can use |:imap| on the results of keys from 'keymap'. -Mappings: -- A mapping whose {lhs} starts with is always applied even if mapping - is disallowed by |nore|. - Motion: The |jumplist| avoids useless/phantom jumps. diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 85a5c176bb..8426cdb98c 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1712,11 +1712,10 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) int local_State = get_real_state(); bool is_plug_map = false; - // Check if typehead starts with a mapping. - // In that case we will ignore nore flag on it. + // If typehead starts with then remap, even for a "noremap" mapping. 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) { + && typebuf.tb_buf[typebuf.tb_off + 1] == KS_EXTRA + && typebuf.tb_buf[typebuf.tb_off + 2] == KE_PLUG) { is_plug_map = true; } diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index 1080a3c85b..98440ccdd7 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -646,4 +646,34 @@ func Test_abbreviate_multi_byte() bwipe! endfunc +" Test for always being mapped, even when used with "noremap". +func Test_plug_remap() + let g:foo = 0 + nnoremap (Increase_x) let g:foo += 1 + nmap (Increase_x) + nnoremap (Increase_x) + call feedkeys("\", 'xt') + call assert_equal(1, g:foo) + call feedkeys("\", 'xt') + call assert_equal(2, g:foo) + nnoremap x + nmap x(Increase_x)x + nnoremap x(Increase_x)x + call setline(1, 'Some text') + normal! gg$ + call feedkeys("\", 'xt') + call assert_equal(3, g:foo) + call assert_equal('Some text', getline(1)) + call feedkeys("\", 'xt') + call assert_equal(4, g:foo) + call assert_equal('Some te', getline(1)) + nunmap (Increase_x) + nunmap + nunmap + nunmap + nunmap + unlet g:foo + %bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab