]> granicus.if.org Git - vim/commitdiff
patch 8.2.2914: cannot paste a block without adding padding v8.2.2914
authorChristian Brabandt <cb@256bit.org>
Sun, 30 May 2021 20:17:25 +0000 (22:17 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 30 May 2021 20:17:25 +0000 (22:17 +0200)
Problem:    Cannot paste a block without adding padding.
Solution:   Add "zp" and "zP" which paste without adding padding. (Christian
            Brabandt, closes #8289)

runtime/doc/change.txt
runtime/doc/index.txt
src/normal.c
src/register.c
src/testdir/test_normal.vim
src/testdir/test_visual.vim
src/version.c
src/vim.h

index d0b50ca9a51a2ee6c7a056776c7521697f495873..6040926f628e3ca537f365917b71feb9eeb0be83 100644 (file)
@@ -1126,6 +1126,11 @@ inside of strings can change!  Also see 'softtabstop' option. >
                        Using the mouse only works when 'mouse' contains 'n'
                        or 'a'.
 
+["x]zp             or                                  *zp* *zP*
+["x]zP                 Like "p" and "P", except without adding trailing spaces
+                       when pasting a block.  Thus the inserted text will not
+                       always be a rectangle.
+
 You can use these commands to copy text from one place to another.  Do this
 by first getting the text into a register with a yank, delete or change
 command, then inserting the register contents with a put command.  You can
@@ -1165,6 +1170,9 @@ a register, a paste on a visual selected area will paste that single line on
 each of the selected lines (thus replacing the blockwise selected region by a
 block of the pasted line).
 
+Use |zP|/|zp| to paste a blockwise yanked register without appending trailing
+spaces.
+
                                                        *blockwise-register*
 If you use a blockwise Visual mode command to get the text into the register,
 the block of text will be inserted before ("P") or after ("p") the cursor
index 545adff01af3cfe68e2a718c30b32e15586ca84e..118bc22179cded139962e792ea1d4a30bc32da30 100644 (file)
@@ -864,6 +864,8 @@ tag         char          note action in Normal mode        ~
 |zm|           zm                 subtract one from 'foldlevel'
 |zn|           zn                 reset 'foldenable'
 |zo|           zo                 open fold
+|zp|           zp                 paste in block-mode without trailing spaces
+|zP|           zP                 paste in block-mode without trailing spaces
 |zr|           zr                 add one to 'foldlevel'
 |zs|           zs                 when 'wrap' off scroll horizontally to
                                   position the cursor at the start (left
index a7b32c6499e5cb1c2a444f4c3b6a4d6e43354de1..39643bae8873bc76942d6a1a420c249b0d6dbd9a 100644 (file)
@@ -2973,6 +2973,10 @@ dozet:
                }
                break;
 
+               // "zp", "zP" in block mode put without addind trailing spaces
+    case 'P':
+    case 'p':  nv_put(cap);
+              break;
 #ifdef FEAT_FOLDING
                // "zF": create fold command
                // "zf": create fold operator
@@ -7418,11 +7422,13 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
        }
        else
            dir = (cap->cmdchar == 'P'
-                                || (cap->cmdchar == 'g' && cap->nchar == 'P'))
-                                                        ? BACKWARD : FORWARD;
+                   || ((cap->cmdchar == 'g' || cap->cmdchar == 'z')
+                       && cap->nchar == 'P')) ? BACKWARD : FORWARD;
        prep_redo_cmd(cap);
        if (cap->cmdchar == 'g')
            flags |= PUT_CURSEND;
+       else if (cap->cmdchar == 'z')
+           flags |= PUT_BLOCK_INNER;
 
        if (VIsual_active)
        {
index 6ba4e896d86d5d770f56d597d4ad59e35a377c4c..f4d934393b0a1063af9703ca57112074493b99e1 100644 (file)
@@ -1497,6 +1497,7 @@ copy_yank_reg(yankreg_T *reg)
  * "flags": PUT_FIXINDENT      make indent look nice
  *         PUT_CURSEND         leave cursor after end of new text
  *         PUT_LINE            force linewise put (":put")
+ *         PUT_BLOCK_INNER     in block mode, do not add trailing spaces
  */
     void
 do_put(
@@ -1794,7 +1795,7 @@ do_put(
        bd.textcol = 0;
        for (i = 0; i < y_size; ++i)
        {
-           int spaces;
+           int spaces = 0;
            char shortline;
 
            bd.startspaces = 0;
@@ -1845,12 +1846,16 @@ do_put(
 
            yanklen = (int)STRLEN(y_array[i]);
 
-           // calculate number of spaces required to fill right side of block
-           spaces = y_width + 1;
-           for (j = 0; j < yanklen; j++)
-               spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0);
-           if (spaces < 0)
-               spaces = 0;
+           if ((flags & PUT_BLOCK_INNER) == 0)
+           {
+               // calculate number of spaces required to fill right side of
+               // block
+               spaces = y_width + 1;
+               for (j = 0; j < yanklen; j++)
+                   spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0);
+               if (spaces < 0)
+                   spaces = 0;
+           }
 
            // insert the new text
            totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces;
index f6e60a8ae5d184d31d1056c7f501db35752a151b..48cc46e0749cf3506cebd16ec02f563fb7eb1487 100644 (file)
@@ -595,7 +595,7 @@ endfunc
 " Test for errors with z command
 func Test_normal_z_error()
   call assert_beeps('normal! z2p')
-  call assert_beeps('normal! zp')
+  call assert_beeps('normal! zq')
 endfunc
 
 func Test_normal15_z_scroll_vert()
index cd039c09fcddbc768af905adef6f2ae53972e1e6..2b3b2139ee0cd6d9a7e3420d52c43b5168c5d12c 100644 (file)
@@ -1044,4 +1044,26 @@ func Test_visual_put_in_block()
   bwipe!
 endfunc
 
+func Test_visual_put_in_block_using_zp()
+  new
+  " paste using zP
+  call setline(1, ['/path;text', '/path;text', '/path;text', '', 
+    \ '/subdir', 
+    \ '/longsubdir',
+    \ '/longlongsubdir'])
+  exe "normal! 5G\<c-v>2j$y"
+  norm! 1Gf;zP
+  call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3))
+  %d
+  " paste using zP
+  call setline(1, ['/path;text', '/path;text', '/path;text', '', 
+    \ '/subdir', 
+    \ '/longsubdir',
+    \ '/longlongsubdir'])
+  exe "normal! 5G\<c-v>2j$y"
+  norm! 1Gf;hzp
+  call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3))
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 94e94c47676c7686cd6df9f9f717aabae7ea071e..56ce53405393ffece8549dd7d7639a3fe778514c 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2914,
 /**/
     2913,
 /**/
index 515f8d5c2bf1e01487d6d2a26f86718d372f1075..10f032f2b264fe831b152ebadc16e200dcb74214 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1068,6 +1068,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #define PUT_LINE       8       // put register as lines
 #define PUT_LINE_SPLIT 16      // split line for linewise register
 #define PUT_LINE_FORWARD 32    // put linewise register below Visual sel.
+#define PUT_BLOCK_INNER 64      // in block mode, do not add trailing spaces
 
 // flags for set_indent()
 #define SIN_CHANGED    1       // call changed_bytes() when line changed