diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 28efee164b..44a5c98f00 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2311,6 +2311,9 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) if (*skipwhite(get_cursor_line_ptr() + strip_col) == NUL) { curwin->w_cursor.col = strip_col; while (true) { + if (gchar_cursor() == NUL && curwin->w_cursor.col > 0) { + curwin->w_cursor.col--; + } cc = gchar_cursor(); if (!ascii_iswhite(cc)) { break; diff --git a/test/old/testdir/test_virtualedit.vim b/test/old/testdir/test_virtualedit.vim index 83a9313198..585b4c5520 100644 --- a/test/old/testdir/test_virtualedit.vim +++ b/test/old/testdir/test_virtualedit.vim @@ -788,4 +788,18 @@ func Test_set_virtualedit_on_mode_change() bwipe! endfunc +func Test_strip_autoindent_with_virtualedit_onemore() + new + setlocal autoindent virtualedit=onemore + call feedkeys("i x\\", 'tnix') + call assert_equal([' x', ''], getline(1, '$')) + + %delete _ + setlocal virtualedit& + call feedkeys("i x\\", 'tnix') + call assert_equal([' x', ''], getline(1, '$')) + + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab