[vim/vim] Macros recorded and replayed from insert normal mode insert stray 'i's into buffer (Issue #20085)

1 view
Skip to first unread message

Emilien Breton

unread,
12:45 AM (13 hours ago) 12:45 AM
to vim/vim, Subscribed
Bricktech2000 created an issue (vim/vim#20085)

Steps to reproduce

vim -u NONE then type in qqafoo<c-o>q<cr><c-o>@q

Expected behaviour

Expecting the buffer to contain

foo
foo

But instead it contains

foo
fooi

Version of Vim

9.1.1566

Environment

a

Logs and stack traces


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/20085@github.com>

zeertzjq

unread,
2:13 AM (11 hours ago) 2:13 AM
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#20085)

There is a question here. If a macro that enters Insert mode is replayed from Replace mode Ctrl-O, should Vim be in Insert mode or Replace mode when the macro finishes?


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

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

zeertzjq

unread,
2:15 AM (11 hours ago) 2:15 AM
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#20085)

This may fix the problem:

diff --git a/src/register.c b/src/register.c
index 9eeb88f44..df0b99968 100644
--- a/src/register.c
+++ b/src/register.c
@@ -787,21 +787,24 @@ do_execreg(
     static void
 put_reedit_in_typebuf(int silent)
 {
-    char_u	buf[3];
+    char_u	buf[5];
 
     if (restart_edit == NUL)
 	return;
 
+    buf[0] = Ctrl_BSL;
+    buf[1] = Ctrl_N;
+
     if (restart_edit == 'V')
     {
-	buf[0] = 'g';
-	buf[1] = 'R';
-	buf[2] = NUL;
+	buf[2] = 'g';
+	buf[3] = 'R';
+	buf[4] = NUL;
     }
     else
     {
-	buf[0] = restart_edit == 'I' ? 'i' : restart_edit;
-	buf[1] = NUL;
+	buf[2] = restart_edit == 'I' ? 'i' : restart_edit;
+	buf[3] = NUL;
     }
     if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK)
 	restart_edit = NUL;

but its final cursor position is not ideal. In the above case, it puts Vim in Replace mode.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

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

zeertzjq

unread,
2:41 AM (11 hours ago) 2:41 AM
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#20085)

Another solution:

diff --git a/src/register.c b/src/register.c
index 9eeb88f44..2601bb47b 100644
--- a/src/register.c
+++ b/src/register.c
@@ -787,22 +787,18 @@ do_execreg(
     static void
 put_reedit_in_typebuf(int silent)
 {
-    char_u	buf[3];
-
     if (restart_edit == NUL)
 	return;
 
-    if (restart_edit == 'V')
-    {
-	buf[0] = 'g';
-	buf[1] = 'R';
-	buf[2] = NUL;
-    }
-    else
-    {
-	buf[0] = restart_edit == 'I' ? 'i' : restart_edit;
-	buf[1] = NUL;
-    }
+    char_u	buf[] = { K_SPECIAL, KS_EXTRA, KE_COMMAND,
+				// :startinsert
+				's', 't', 'a', 'r', 't', 'i', CAR, NUL };
+    if (restart_edit == 'R')
+	buf[8] = 'r';  // :startreplace
+    else if (restart_edit == 'V')
+	buf[8] = 'g';  // :startgreplace
+    else if (restart_edit == 'A')
+	buf[8] = '!';  // :startinsert!
     if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK)
 	restart_edit = NUL;
 }

This doesn't have the cursor position problem, but it puts Vim in Insert mode instead of Replace mode in the Replace mode Ctrl-O case.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

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

Reply all
Reply to author
Forward
0 new messages