diff options
-rw-r--r-- | src/nvim/ops.c | 18 | ||||
-rw-r--r-- | src/nvim/testdir/test_put.vim | 10 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 83a7c31991..52164f6c38 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3472,6 +3472,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) curwin->w_cursor.col -= first_byte_off; } } else { + linenr_T new_lnum = new_cursor.lnum; + // Insert at least one line. When y_type is kMTCharWise, break the first // line in two. for (cnt = 1; cnt <= count; cnt++) { @@ -3488,6 +3490,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) STRCAT(newp, ptr); // insert second line ml_append(lnum, newp, (colnr_T)0, false); + new_lnum++; xfree(newp); oldp = ml_get(lnum); @@ -3503,10 +3506,11 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } for (; i < y_size; i++) { - if ((y_type != kMTCharWise || i < y_size - 1) - && ml_append(lnum, y_array[i], (colnr_T)0, false) - == FAIL) { - goto error; + if ((y_type != kMTCharWise || i < y_size - 1)) { + if (ml_append(lnum, y_array[i], (colnr_T)0, false) == FAIL) { + goto error; + } + new_lnum++; } lnum++; ++nr_lines; @@ -3556,6 +3560,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) extmark_splice(curbuf, (int)new_cursor.lnum-1, col + 1, 0, 0, 0, (int)y_size+1, 0, totsize+2, kExtmarkUndo); } + + if (cnt == 1) { + new_lnum = lnum; + } } error: @@ -3606,7 +3614,7 @@ error: } curwin->w_cursor.col = 0; } else { - curwin->w_cursor.lnum = lnum; + curwin->w_cursor.lnum = new_lnum; curwin->w_cursor.col = col; } } else if (y_type == kMTLineWise) { diff --git a/src/nvim/testdir/test_put.vim b/src/nvim/testdir/test_put.vim index 440717eaa8..aceac58493 100644 --- a/src/nvim/testdir/test_put.vim +++ b/src/nvim/testdir/test_put.vim @@ -112,6 +112,16 @@ func Test_put_p_indent_visual() bwipe! endfunc +func Test_gp_with_count_leaves_cursor_at_end() + new + call setline(1, '<---->') + call setreg('@', "foo\nbar", 'c') + exe "normal 1G3|3gpix\<Esc>" + call assert_equal(['<--foo', 'barfoo', 'barfoo', 'barx-->'], getline(1, '$')) + + bwipe! +endfunc + func Test_multibyte_op_end_mark() new call setline(1, 'ัะตัั') |