Skip to content

Commit adb8fbe

Browse files
committed
patch 8.1.0034: cursor not restored with ":edit #"
Problem: Cursor not restored with ":edit #". Solution: Don't assume autocommands moved the cursor when it was moved to the first non-blank.
1 parent acb9eff commit adb8fbe

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/ex_cmds.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4193,11 +4193,18 @@ do_ecmd(
41934193
check_arg_idx(curwin);
41944194

41954195
/* If autocommands change the cursor position or topline, we should
4196-
* keep it. Also when it moves within a line. */
4196+
* keep it. Also when it moves within a line. But not when it moves
4197+
* to the first non-blank. */
41974198
if (!EQUAL_POS(curwin->w_cursor, orig_pos))
41984199
{
4199-
newlnum = curwin->w_cursor.lnum;
4200-
newcol = curwin->w_cursor.col;
4200+
char_u *text = ml_get_curline();
4201+
4202+
if (curwin->w_cursor.lnum != orig_pos.lnum
4203+
|| curwin->w_cursor.col != (int)(skipwhite(text) - text))
4204+
{
4205+
newlnum = curwin->w_cursor.lnum;
4206+
newcol = curwin->w_cursor.col;
4207+
}
42014208
}
42024209
if (curwin->w_topline == topline)
42034210
topline = 0;

src/testdir/test_edit.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,3 +1387,17 @@ func Test_edit_quit()
13871387
only
13881388
endfunc
13891389

1390+
func Test_edit_alt()
1391+
" Keeping the cursor line didn't happen when the first line has indent.
1392+
new
1393+
call setline(1, [' one', 'two', 'three'])
1394+
w XAltFile
1395+
$
1396+
call assert_equal(3, line('.'))
1397+
e Xother
1398+
e #
1399+
call assert_equal(3, line('.'))
1400+
1401+
bwipe XAltFile
1402+
call delete('XAltFile')
1403+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
34,
764766
/**/
765767
33,
766768
/**/

0 commit comments

Comments
 (0)