diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 15c0836cbe..d51929583e 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2206,6 +2206,9 @@ int stop_arrow(void) new_insert_skip = 2; } else if (ins_need_undo) { if (u_save_cursor() == OK) { + // A command or event may have moved the cursor after syncing undo. + Insstart = curwin->w_cursor; + Insstart_textlen = (colnr_T)linetabsize_str(get_cursor_line_ptr()); ins_need_undo = false; } } diff --git a/test/old/testdir/test_undo.vim b/test/old/testdir/test_undo.vim index fe3d5f8209..0cf2ca4b37 100644 --- a/test/old/testdir/test_undo.vim +++ b/test/old/testdir/test_undo.vim @@ -923,5 +923,19 @@ func Test_restore_cursor_position_after_undo() bw! endfunc +func Test_undo_line_backspace_after_insert_cmd_cursor_movement() + new + setlocal backspace=eol undolevels=100 + call setline(1, ['', '', 'abc', 'def']) + call cursor(4, 1) + + let v:errmsg = '' + call feedkeys("i\setlocal undolevels=101 | call cursor(3, 1)\" + \ .. "\\\u", 'xt') + + call assert_equal('', v:errmsg) + call assert_equal(['', '', 'abc', 'def'], getline(1, '$')) + bwipe! +endfunc " vim: shiftwidth=2 sts=2 expandtab