diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index bada506c63..524978f523 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -366,8 +366,9 @@ Macro/|recording| behavior the results of keys from 'keymap'. Mappings: - Creating a mapping for a simplifiable key (e.g. ) doesn't replace an +- Creating a mapping for a simplifiable key (e.g. ) doesn't replace an existing mapping for its simplified form (e.g. ). +- The rhs of a mapping is not simplified when it is defined. Motion: The |jumplist| avoids useless/phantom jumps. diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index eb78317ee7..1284382fe8 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2885,8 +2885,8 @@ void set_maparg_lhs_rhs(const char_u *const orig_lhs, const size_t orig_lhs_len, mapargs->rhs_len = 0; mapargs->rhs_is_noop = true; } else { - replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, REPTERM_DO_LT, NULL, - cpo_flags); + replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, + REPTERM_DO_LT | REPTERM_NO_SIMPLIFY, NULL, cpo_flags); mapargs->rhs_len = STRLEN(replaced); mapargs->rhs_is_noop = false; mapargs->rhs = xcalloc(mapargs->rhs_len + 1, sizeof(char_u)); @@ -4861,15 +4861,21 @@ char_u *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) // special case to give nicer error message emsg(e_cmdmap_repeated); aborted = true; - } else if (IS_SPECIAL(c1)) { - if (c1 == K_SNR) { - ga_concat(&line_ga, ""); - } else { - semsg(e_cmdmap_key, get_special_key_name(c1, cmod)); - aborted = true; - } + } else if (c1 == K_SNR) { + ga_concat(&line_ga, ""); } else { - ga_append(&line_ga, (char)c1); + if (cmod != 0) { + ga_append(&line_ga, (char)K_SPECIAL); + ga_append(&line_ga, (char)KS_MODIFIER); + ga_append(&line_ga, (char)cmod); + } + if (IS_SPECIAL(c1)) { + ga_append(&line_ga, (char)K_SPECIAL); + ga_append(&line_ga, (char)K_SECOND(c1)); + ga_append(&line_ga, (char)K_THIRD(c1)); + } else { + ga_append(&line_ga, (char)c1); + } } cmod = 0; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 5983f18bb5..070d96ebb3 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -997,8 +997,8 @@ EXTERN char e_float_as_string[] INIT(= N_("E806: using Float as a String")); EXTERN char e_autocmd_err[] INIT(= N_("E5500: autocmd has thrown an exception: %s")); EXTERN char e_cmdmap_err[] INIT(= N_("E5520: mapping must end with ")); -EXTERN char e_cmdmap_repeated[] INIT(= N_("E5521: mapping must end with before second ")); -EXTERN char e_cmdmap_key[] INIT(= N_("E5522: mapping must not include %s key")); +EXTERN char e_cmdmap_repeated[] +INIT(= N_("E5521: mapping must end with before second ")); EXTERN char e_api_error[] INIT(= N_("E5555: API call: %s")); diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua index 64cf53dfa9..dbbfadabd8 100644 --- a/test/functional/ex_cmds/cmd_map_spec.lua +++ b/test/functional/ex_cmds/cmd_map_spec.lua @@ -93,19 +93,6 @@ describe('mappings with ', function() {2:E5521: mapping must end with before second } | ]]) - command('noremap let x = 2') - feed('') - screen:expect([[ - ^some short lines | - of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {2:E5522: mapping must not include key} | - ]]) - command('noremap let x = 3') feed('') screen:expect([[ @@ -121,6 +108,34 @@ describe('mappings with ', function() eq(0, eval('x')) end) + it('allows special keys and modifiers', function() + command('noremap normal! ') + feed('') + screen:expect([[ + some short lines | + ^of test text | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + + command('noremap normal! ') + feed('') + screen:expect([[ + some short lines | + of ^test text | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) + end) + it('works in various modes and sees correct `mode()` value', function() -- normal mode feed('') diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua index 0f4e97088c..07582ba602 100644 --- a/test/functional/ui/input_spec.lua +++ b/test/functional/ui/input_spec.lua @@ -313,6 +313,11 @@ it('unsimplified mapping works when there was a partial match vim-patch:8.2.4504 expect('xb') end) +it('rhs of a mapping is not simplified', function() + command('nnoremap foo ') + eq('', funcs.maparg('foo')) +end) + describe('input non-printable chars', function() after_each(function() os.remove('Xtest-overwrite')