[vim/vim] Macros don't correctly record mapped Ctrl keys (Issue #11270)

113 views
Skip to first unread message

David Briscoe

unread,
Oct 3, 2022, 8:22:29 PM10/3/22
to vim/vim, Subscribed

Steps to reproduce

Mapping C-L to Esc doesn't work correctly in macros:

  1. gvim --clean
  2. :inoremap <C-L> <Esc>
  3. populate buffer: ivim<CR>devs<C-L>
  4. record a macro using C-L: ggqqIhi <C-L>
  5. replay macro: j@q

Result:

hi vim

hi �üLdevs

Expected behaviour

When playing a macro, mappings should work the same as they while recording the macro. Using Ctrl in a mapping shouldn't replay as special characters. This was the behaviour on vim 8.2. I can verify that it works this way on 8.1.2269 (in a terminal) and I think it was also correct on 8.2.3399.

Expected:

hi vim

hi devs

Version of Vim

9.0.636

Environment

Win 10 21H2
gvim

Using build of vim from scoop (installer from https://github.com/vim/vim-win32-installer)

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11270@github.com>

zeertzjq

unread,
Oct 3, 2022, 8:41:03 PM10/3/22
to vim/vim, Subscribed

This fixes the bug:

diff --git a/src/map.c b/src/map.c
index d063e053a..3463adcf1 100644
--- a/src/map.c
+++ b/src/map.c
@@ -1753,7 +1753,11 @@ vim_strsave_escape_csi(char_u *p)
 	d = res;
 	for (s = p; *s != NUL; )
 	{
-	    if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL)
+	    if ((s[0] == K_SPECIAL
+#ifdef FEAT_GUI
+		|| s[0] == CSI
+#endif
+		) && s[1] != NUL && s[2] != NUL)
 	    {
 		// Copy special key unmodified.
 		*d++ = *s++;

Not sure if it is possible to write a test.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11270/1266255718@github.com>

David Briscoe

unread,
Oct 3, 2022, 11:58:17 PM10/3/22
to vim/vim, Subscribed

Wow, fast find! And I didn't realize it was gui-only, but testing in terminal vim9 I don't can't repro.

For tests, https://github.com/vim/vim/blob/master/src/testdir/test_gui.vim doesn't seem to have any macro tests. I was using let @q = to convert my broken macros into working ones, so that's not a valid way to test. feedkeys("qqIhi\<C-L>q@q") doesn't work and feedkeys("qqIhi\<C-L>q@q", "L") (or "t") don't exhibit the bug.

Not sure how you can test without a script that sends keys to vim.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11270/1266365287@github.com>

zeertzjq

unread,
Oct 4, 2022, 3:38:56 AM10/4/22
to vim/vim, Subscribed

Note: unlike a previous issue, the #ifdef FEAT_GUI in the patch above probably cannot be omitted.

With FEAT_GUI, CSI is just an ordinary character, so removing the #ifdef FEAT_GUI can cause problems like treating a part of a UTF-8 sequence as a part of a GUI termcap when FEAT_GUI is not defined.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11270/1266530540@github.com>

zeertzjq

unread,
Oct 4, 2022, 3:39:24 AM10/4/22
to vim/vim, Subscribed

Note: unlike a previous issue, the #ifdef FEAT_GUI in the patch above probably cannot be omitted.

Without FEAT_GUI, CSI is just an ordinary character, so removing the #ifdef FEAT_GUI can cause problems like treating a part of a UTF-8 sequence as a part of a GUI termcap when FEAT_GUI is not defined.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11270/1266530961@github.com>

zeertzjq

unread,
Oct 4, 2022, 3:58:25 AM10/4/22
to vim/vim, Subscribed

I guess the easiest way to test this is to just hardcode the register content. I've create a PR #11275.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11270/1266549382@github.com>

Bram Moolenaar

unread,
Oct 4, 2022, 3:15:19 PM10/4/22
to vim/vim, Subscribed

Closed #11270 as completed via 2cd0f27.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/11270/issue_event/7519388511@github.com>

David Briscoe

unread,
Oct 5, 2022, 1:15:17 PM10/5/22
to vim/vim, Subscribed

Fix works for me on 9.0.662. It even correctly plays macros recorded on 9.0.636.

Thanks @zeertzjq!


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11270/1268709716@github.com>

Reply all
Reply to author
Forward
0 new messages