Skip to content

Commit fd8983b

Browse files
committed
patch 8.0.0296: bracketed paste can only append, not insert
Problem: Bracketed paste can only append, not insert. Solution: When the cursor is in the first column insert the text.
1 parent 7a07354 commit fd8983b

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

runtime/doc/term.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*term.txt* For Vim version 8.0. Last change: 2017 Jan 27
1+
*term.txt* For Vim version 8.0. Last change: 2017 Feb 02
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -95,7 +95,12 @@ terminal when entering "raw" mode and 't_BD' when leaving "raw" mode. The
9595
terminal is then expected to put 't_PS' before pasted text and 't_PE' after
9696
pasted text. This way Vim can separate text that is pasted from characters
9797
that are typed. The pasted text is handled like when the middle mouse button
98-
is used.
98+
is used, it is inserted literally and not interpreted as commands.
99+
100+
When the cursor is in the first column, the pasted text will be inserted
101+
before it. Otherwise the pasted text is appended after the cursor position.
102+
This means one cannot paste after the first column. Unfortunately Vim does
103+
not have a way to tell where the mouse pointer was.
99104

100105
Note that in some situations Vim will not recognize the bracketed paste and
101106
you will get the raw text. In other situations Vim will only get the first

src/normal.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9079,8 +9079,13 @@ nv_edit(cmdarg_T *cap)
90799079
beginline(BL_WHITE|BL_FIX);
90809080
break;
90819081

9082+
case K_PS: /* Bracketed paste works like "a"ppend, unless the
9083+
cursor is in the first column, then it inserts. */
9084+
if (curwin->w_cursor.col == 0)
9085+
break;
9086+
/*FALLTHROUGH*/
9087+
90829088
case 'a': /* "a"ppend is like "i"nsert on the next character. */
9083-
case K_PS: /* bracketed paste works like "a"ppend */
90849089
#ifdef FEAT_VIRTUALEDIT
90859090
/* increment coladd when in virtual space, increment the
90869091
* column otherwise, also to append after an unprintable char */

src/testdir/test_paste.vim

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,36 @@ set term=xterm
88

99
func Test_paste_normal_mode()
1010
new
11+
" In first column text is inserted
1112
call setline(1, ['a', 'b', 'c'])
12-
2
13+
call cursor(2, 1)
1314
call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt')
14-
call assert_equal('bfoo', getline(2))
15-
call assert_equal('bar', getline(3))
15+
call assert_equal('foo', getline(2))
16+
call assert_equal('barb', getline(3))
1617
call assert_equal('c', getline(4))
1718

19+
" When repeating text is appended
1820
normal .
1921
call assert_equal('barfoo', getline(3))
20-
call assert_equal('bar', getline(4))
22+
call assert_equal('barb', getline(4))
2123
call assert_equal('c', getline(5))
2224
bwipe!
25+
26+
" In second column text is appended
27+
call setline(1, ['a', 'bbb', 'c'])
28+
call cursor(2, 2)
29+
call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt')
30+
call assert_equal('bbfoo', getline(2))
31+
call assert_equal('barb', getline(3))
32+
call assert_equal('c', getline(4))
33+
34+
" In last column text is appended
35+
call setline(1, ['a', 'bbb', 'c'])
36+
call cursor(2, 3)
37+
call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt')
38+
call assert_equal('bbbfoo', getline(2))
39+
call assert_equal('bar', getline(3))
40+
call assert_equal('c', getline(4))
2341
endfunc
2442

2543
func Test_paste_insert_mode()

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
296,
767769
/**/
768770
295,
769771
/**/

0 commit comments

Comments
 (0)