[vim/vim] '[ mark moved to end of inserted text after CTRL-R CTRL-P paste (PR #20322)

3 views
Skip to first unread message

h_east

unread,
May 24, 2026, 4:39:23 PM (9 hours ago) May 24
to vim/vim, Subscribed
Problem:  After CTRL-R CTRL-P (or CTRL-R CTRL-O) pastes a register
          into Insert mode, a follow-up edit such as backspace makes
          stop_arrow() rewrite Insstart with the post-paste cursor
          position.  As a result the '[ mark points at the end of the
          inserted text instead of its start.  Regression introduced
          by patch 9.2.0384 while fixing #20031.
Solution: In stop_arrow(), only pull Insstart back when the cursor
          moved above the previous Insstart, so a line-start backspace
          can still save the joined range (#20031) without disturbing
          the start position for inserts that advance the cursor
          (#20130).

Fixes: #20130


Notes

  • Patch 9.2.0384 unconditionally set Insstart = curwin->w_cursor after
    u_save_cursor() in stop_arrow(). That fix was needed for
    <Cmd> cursor moves above the original Insstart (issue #20031), but
    also fired for CTRL-R CTRL-P register pastes that advance the
    cursor below Insstart, corrupting the '[ mark (issue #20130).
  • The new test Test_open_square_mark_after_ctrl_r_ctrl_p_paste in
    src/testdir/test_undo.vim replays the exact key sequence from the
    bug report and checks getpos("'["). Verified that reverting the
    fix makes only the new test fail; the existing
    Test_undo_line_backspace_after_insert_cmd_cursor_movement still
    passes both with and without the fix.
  • Full test_undo, test_marks, test_edit, test_put, test_registers,
    test_normal all green after the fix.

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/20322

Commit Summary

  • 1748fb7 '[ mark moved to end of inserted text after CTRL-R CTRL-P paste

File Changes

(2 files)

Patch Links:


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/pull/20322@github.com>

zeertzjq

unread,
May 24, 2026, 7:00:39 PM (7 hours ago) May 24
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/testdir/test_undo.vim:

> @@ -967,6 +967,20 @@ func Test_undo_line_backspace_after_insert_cmd_edit()
   bwipe!
 endfunc
 
+" Issue #20130: '[ must mark the start of the paste after CTRL-R CTRL-P + edit.
+func Test_open_square_mark_after_ctrl_r_ctrl_p_paste()

I don't think test_undo.vim is the correct file for this test. It doesn't test the undo functionality. It's better to place it in test_edit.vim.


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/pull/20322/review/4353545594@github.com>

zeertzjq

unread,
May 24, 2026, 7:01:10 PM (7 hours ago) May 24
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/edit.c:

> @@ -2512,11 +2512,14 @@ stop_arrow(void)
     {
 	if (u_save_cursor() == OK)
 	{
-	    // A command or event may have moved the cursor or edited the
-	    // buffer. Update Insstart so that later edits can properly decide
-	    // whether an extra undo entry is needed.
-	    Insstart = curwin->w_cursor;
-	    Insstart_textlen = (colnr_T)linetabsize_str(ml_get_curline());
+	    // A command or event may have moved the cursor before the next
+	    // edit. Pull Insstart back only when the cursor moved above it.

The "so that later edits can properly decide whether an extra undo entry is needed" from the original comment is lost.


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/pull/20322/review/4353546163@github.com>

h_east

unread,
May 24, 2026, 9:05:30 PM (5 hours ago) May 24
to vim/vim, Push

@h-east pushed 1 commit.


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/pull/20322/before/1748fb72955e5dc3333b0860ef9d38d4479976b5/after/f797c659858f4115bca4b0b61358ca4445e87962@github.com>

h_east

unread,
May 24, 2026, 9:06:14 PM (5 hours ago) May 24
to vim/vim, Subscribed

@h-east commented on this pull request.


In src/testdir/test_undo.vim:

> @@ -967,6 +967,20 @@ func Test_undo_line_backspace_after_insert_cmd_edit()
   bwipe!
 endfunc
 
+" Issue #20130: '[ must mark the start of the paste after CTRL-R CTRL-P + edit.
+func Test_open_square_mark_after_ctrl_r_ctrl_p_paste()

Moved.


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/pull/20322/review/4353727980@github.com>

h_east

unread,
May 24, 2026, 9:07:07 PM (5 hours ago) May 24
to vim/vim, Subscribed

@h-east commented on this pull request.


In src/edit.c:

> @@ -2512,11 +2512,14 @@ stop_arrow(void)
     {
 	if (u_save_cursor() == OK)
 	{
-	    // A command or event may have moved the cursor or edited the
-	    // buffer. Update Insstart so that later edits can properly decide
-	    // whether an extra undo entry is needed.
-	    Insstart = curwin->w_cursor;
-	    Insstart_textlen = (colnr_T)linetabsize_str(ml_get_curline());
+	    // A command or event may have moved the cursor before the next
+	    // edit. Pull Insstart back only when the cursor moved above it.

Fixed.


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/pull/20322/review/4353729299@github.com>

Reply all
Reply to author
Forward
0 new messages