Skip to content

Commit cd94277

Browse files
committed
patch 8.2.1511: putting a string in Visual block mode ignores multi-byte
Problem: Putting a string in Visual block mode ignores multi-byte characters. Solution: Adjust the column for Visual block mode. (closes #6767)
1 parent 5390099 commit cd94277

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/register.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,23 +1937,46 @@ do_put(
19371937
--lnum;
19381938
new_cursor = curwin->w_cursor;
19391939

1940-
// simple case: insert into current line
1940+
// simple case: insert into one line at a time
19411941
if (y_type == MCHAR && y_size == 1)
19421942
{
1943-
linenr_T end_lnum = 0; // init for gcc
1943+
linenr_T end_lnum = 0; // init for gcc
1944+
linenr_T start_lnum = lnum;
19441945

19451946
if (VIsual_active)
19461947
{
19471948
end_lnum = curbuf->b_visual.vi_end.lnum;
19481949
if (end_lnum < curbuf->b_visual.vi_start.lnum)
19491950
end_lnum = curbuf->b_visual.vi_start.lnum;
1951+
if (end_lnum > start_lnum)
1952+
{
1953+
pos_T pos;
1954+
1955+
// "col" is valid for the first line, in following lines
1956+
// the virtual column needs to be used. Matters for
1957+
// multi-byte characters.
1958+
pos.lnum = lnum;
1959+
pos.col = col;
1960+
pos.coladd = 0;
1961+
getvcol(curwin, &pos, NULL, &vcol, NULL);
1962+
}
19501963
}
19511964

19521965
do {
19531966
totlen = count * yanklen;
19541967
if (totlen > 0)
19551968
{
19561969
oldp = ml_get(lnum);
1970+
if (lnum > start_lnum)
1971+
{
1972+
pos_T pos;
1973+
1974+
pos.lnum = lnum;
1975+
if (getvpos(&pos, vcol) == OK)
1976+
col = pos.col;
1977+
else
1978+
col = MAXCOL;
1979+
}
19571980
if (VIsual_active && col > (int)STRLEN(oldp))
19581981
{
19591982
lnum++;

src/testdir/test_visual.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,4 +922,13 @@ func Test_visual_inner_block()
922922
close!
923923
endfunc
924924

925+
func Test_visual_put_in_block()
926+
new
927+
call setline(1, ['xxxx', 'y∞yy', 'zzzz'])
928+
normal 1G2yl
929+
exe "normal 1G2l\<C-V>jjlp"
930+
call assert_equal(['xxxx', 'y∞xx', 'zzxx'], getline(1, 3))
931+
bwipe!
932+
endfunc
933+
925934
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1511,
757759
/**/
758760
1510,
759761
/**/

0 commit comments

Comments
 (0)