summaryrefslogtreecommitdiff
path: root/src/register.c
diff options
context:
space:
mode:
authorChristian Brabandt <cb@256bit.org>2021-06-10 19:39:11 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-10 19:39:11 +0200
commit544a38e44db0f25ec4fa7a2a4666cf28a2336f33 (patch)
treeaa6a3da517185bbdb604f7d31bde07ef4dc36c31 /src/register.c
parent31e299c08f250b126b2c2c0ecce12ee563b70fdc (diff)
downloadvim-git-544a38e44db0f25ec4fa7a2a4666cf28a2336f33.tar.gz
patch 8.2.2971: cannot yank a block without trailing spacesv8.2.2971
Problem: Cannot yank a block without trailing spaces. Solution: Add the "zy" command. (Christian Brabandt, closes #8292)
Diffstat (limited to 'src/register.c')
-rw-r--r--src/register.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/register.c b/src/register.c
index 5dc8f2896..c30787afe 100644
--- a/src/register.c
+++ b/src/register.c
@@ -32,7 +32,7 @@ static int stuff_yank(int, char_u *);
static void put_reedit_in_typebuf(int silent);
static int put_in_typebuf(char_u *s, int esc, int colon,
int silent);
-static int yank_copy_line(struct block_def *bd, long y_idx);
+static int yank_copy_line(struct block_def *bd, long y_idx, int exclude_trailing_space);
#ifdef FEAT_CLIPBOARD
static void copy_yank_reg(yankreg_T *reg);
#endif
@@ -1208,20 +1208,20 @@ op_yank(oparg_T *oap, int deleting, int mess)
{
case MBLOCK:
block_prep(oap, &bd, lnum, FALSE);
- if (yank_copy_line(&bd, y_idx) == FAIL)
+ if (yank_copy_line(&bd, y_idx, oap->excl_tr_ws) == FAIL)
goto fail;
break;
case MLINE:
if ((y_current->y_array[y_idx] =
- vim_strsave(ml_get(lnum))) == NULL)
+ vim_strsave(ml_get(lnum))) == NULL)
goto fail;
break;
case MCHAR:
{
colnr_T startcol = 0, endcol = MAXCOL;
- int is_oneChar = FALSE;
+ int is_oneChar = FALSE;
colnr_T cs, ce;
p = ml_get(lnum);
@@ -1282,7 +1282,7 @@ op_yank(oparg_T *oap, int deleting, int mess)
else
bd.textlen = endcol - startcol + oap->inclusive;
bd.textstart = p + startcol;
- if (yank_copy_line(&bd, y_idx) == FAIL)
+ if (yank_copy_line(&bd, y_idx, FALSE) == FAIL)
goto fail;
break;
}
@@ -1443,8 +1443,12 @@ fail: // free the allocated lines
return FAIL;
}
+/*
+ * Copy a block range into a register.
+ * If "exclude_trailing_space" is set, do not copy trailing whitespaces.
+ */
static int
-yank_copy_line(struct block_def *bd, long y_idx)
+yank_copy_line(struct block_def *bd, long y_idx, int exclude_trailing_space)
{
char_u *pnew;
@@ -1458,6 +1462,16 @@ yank_copy_line(struct block_def *bd, long y_idx)
pnew += bd->textlen;
vim_memset(pnew, ' ', (size_t)bd->endspaces);
pnew += bd->endspaces;
+ if (exclude_trailing_space)
+ {
+ int s = bd->textlen + bd->endspaces;
+
+ while (VIM_ISWHITE(*(bd->textstart + s - 1)) && s > 0)
+ {
+ s = s - (*mb_head_off)(bd->textstart, bd->textstart + s - 1) - 1;
+ pnew--;
+ }
+ }
*pnew = NUL;
return OK;
}