Skip to content

Commit 23003e5

Browse files
committed
patch 8.2.3454: using a count with "gp" leave cursor in wrong position
Problem: Using a count with "gp" leave cursor in wrong position. (Naohiro Ono) Solution: Count the inserted lines. (closes #8899)
1 parent 40fa12a commit 23003e5

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/register.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,8 @@ do_put(
20652065
}
20662066
else
20672067
{
2068+
linenr_T new_lnum = new_cursor.lnum;
2069+
20682070
// Insert at least one line. When y_type is MCHAR, break the first
20692071
// line in two.
20702072
for (cnt = 1; cnt <= count; ++cnt)
@@ -2085,6 +2087,7 @@ do_put(
20852087
STRCAT(newp, ptr);
20862088
// insert second line
20872089
ml_append(lnum, newp, (colnr_T)0, FALSE);
2090+
++new_lnum;
20882091
vim_free(newp);
20892092

20902093
oldp = ml_get(lnum);
@@ -2103,10 +2106,13 @@ do_put(
21032106

21042107
for (; i < y_size; ++i)
21052108
{
2106-
if ((y_type != MCHAR || i < y_size - 1)
2107-
&& ml_append(lnum, y_array[i], (colnr_T)0, FALSE)
2109+
if (y_type != MCHAR || i < y_size - 1)
2110+
{
2111+
if (ml_append(lnum, y_array[i], (colnr_T)0, FALSE)
21082112
== FAIL)
21092113
goto error;
2114+
new_lnum++;
2115+
}
21102116
lnum++;
21112117
++nr_lines;
21122118
if (flags & PUT_FIXINDENT)
@@ -2138,6 +2144,8 @@ do_put(
21382144
lendiff -= (int)STRLEN(ml_get(lnum));
21392145
}
21402146
}
2147+
if (cnt == 1)
2148+
new_lnum = lnum;
21412149
}
21422150

21432151
error:
@@ -2195,7 +2203,7 @@ do_put(
21952203
}
21962204
else
21972205
{
2198-
curwin->w_cursor.lnum = lnum;
2206+
curwin->w_cursor.lnum = new_lnum;
21992207
curwin->w_cursor.col = col;
22002208
}
22012209
}

src/testdir/test_put.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,14 @@ func Test_put_visual_delete_all_lines()
122122
close!
123123
endfunc
124124

125+
func Test_gp_with_count_leaves_cursor_at_end()
126+
new
127+
call setline(1, '<---->')
128+
call setreg('@', "foo\nbar", 'c')
129+
exe "normal 1G3|3gpix\<Esc>"
130+
call assert_equal(['<--foo', 'barfoo', 'barfoo', 'barx-->'], getline(1, '$'))
131+
132+
bwipe!
133+
endfunc
134+
125135
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

758758
static int included_patches[] =
759759
{ /* Add new patch number below this line */
760+
/**/
761+
3454,
760762
/**/
761763
3453,
762764
/**/

0 commit comments

Comments
 (0)