Skip to content

Commit 92a3d20

Browse files
zeertzjqbrammool
authored andcommitted
patch 9.0.0341: mapset() does not restore <Nop> mapping properly
Problem: mapset() does not restore <Nop> mapping properly. Solution: Use an empty string for <Nop>. (closes #11022)
1 parent a2a8973 commit 92a3d20

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

src/map.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2658,7 +2658,10 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
26582658
return;
26592659
}
26602660
orig_rhs = rhs;
2661-
rhs = replace_termcodes(rhs, &arg_buf,
2661+
if (STRICMP(rhs, "<nop>") == 0) // "<Nop>" means nothing
2662+
rhs = (char_u *)"";
2663+
else
2664+
rhs = replace_termcodes(rhs, &arg_buf,
26622665
REPTERM_DO_LT | REPTERM_SPECIAL, NULL);
26632666

26642667
noremap = dict_get_number(d, "noremap") ? REMAP_NONE: 0;

src/testdir/test_map_functions.vim

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ func Test_range_map()
183183
call assert_equal("abcd", getline(1))
184184
endfunc
185185

186-
func One_mapset_test(keys)
187-
exe 'nnoremap ' .. a:keys .. ' original<CR>'
186+
func One_mapset_test(keys, rhs)
187+
exe 'nnoremap ' .. a:keys .. ' ' .. a:rhs
188188
let orig = maparg(a:keys, 'n', 0, 1)
189189
call assert_equal(a:keys, orig.lhs)
190-
call assert_equal('original<CR>', orig.rhs)
190+
call assert_equal(a:rhs, orig.rhs)
191191
call assert_equal('n', orig.mode)
192192

193193
exe 'nunmap ' .. a:keys
@@ -197,15 +197,16 @@ func One_mapset_test(keys)
197197
call mapset('n', 0, orig)
198198
let d = maparg(a:keys, 'n', 0, 1)
199199
call assert_equal(a:keys, d.lhs)
200-
call assert_equal('original<CR>', d.rhs)
200+
call assert_equal(a:rhs, d.rhs)
201201
call assert_equal('n', d.mode)
202202

203203
exe 'nunmap ' .. a:keys
204204
endfunc
205205

206206
func Test_mapset()
207-
call One_mapset_test('K')
208-
call One_mapset_test('<F3>')
207+
call One_mapset_test('K', 'original<CR>')
208+
call One_mapset_test('<F3>', 'original<CR>')
209+
call One_mapset_test('<F3>', '<lt>Nop>')
209210

210211
" Check <> key conversion
211212
new
@@ -228,6 +229,26 @@ func Test_mapset()
228229

229230
iunmap K
230231

232+
" Test that <Nop> is restored properly
233+
inoremap K <Nop>
234+
call feedkeys("SK\<Esc>", 'xt')
235+
call assert_equal('', getline(1))
236+
237+
let orig = maparg('K', 'i', 0, 1)
238+
call assert_equal('K', orig.lhs)
239+
call assert_equal('<Nop>', orig.rhs)
240+
call assert_equal('i', orig.mode)
241+
242+
inoremap K foo
243+
call feedkeys("SK\<Esc>", 'xt')
244+
call assert_equal('foo', getline(1))
245+
246+
call mapset('i', 0, orig)
247+
call feedkeys("SK\<Esc>", 'xt')
248+
call assert_equal('', getline(1))
249+
250+
iunmap K
251+
231252
" Test literal <CR> using a backslash
232253
let cpo_save = &cpo
233254
set cpo-=B

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,8 @@ static char *(features[]) =
707707

708708
static int included_patches[] =
709709
{ /* Add new patch number below this line */
710+
/**/
711+
341,
710712
/**/
711713
340,
712714
/**/

0 commit comments

Comments
 (0)