]> granicus.if.org Git - vim/commitdiff
patch 8.2.4242: put in Visual mode cannot be repeated v8.2.4242
authorShougo Matsushita <Shougo.Matsu@gmail.com>
Fri, 28 Jan 2022 16:01:13 +0000 (16:01 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 28 Jan 2022 16:01:13 +0000 (16:01 +0000)
Problem:    Put in Visual mode cannot be repeated.
Solution:   Use "P" to put without yanking the deleted text into the unnamed
            register. (Shougo Matsushita, closes #9591)

runtime/doc/visual.txt
src/normal.c
src/register.c
src/testdir/test_visual.vim
src/version.c

index 3db506e35379d922b6dbf5391ddb80cb1bcce064..d61d5d8bb53bc8ba1ddbc00e60d96b7f7b2106c6 100644 (file)
@@ -265,6 +265,7 @@ Additionally the following commands can be used:
        X       delete (2)                                      |v_X|
        Y       yank (2)                                        |v_Y|
        p       put                                             |v_p|
+       P       put without unnamed register overwrite          |v_P|
        J       join (1)                                        |v_J|
        U       make uppercase                                  |v_U|
        u       make lowercase                                  |v_u|
index 2d5f8a5f764997a07892ed8a0cd9409231f59863..412700ae1aafe2c67859950106ed5c73a46fc3cf 100644 (file)
@@ -4661,8 +4661,8 @@ nv_bracket_block(cmdarg_T *cap, pos_T *old_pos)
                    }
                    // found start/end of other method: go to match
                    else if ((pos = findmatchlimit(cap->oap, findc,
-                                   (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD,
-                                   0)) == NULL)
+                             (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD,
+                                                                  0)) == NULL)
                        n = 0;
                    else
                        curwin->w_cursor = *pos;
@@ -7505,6 +7505,8 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
     int                was_visual = FALSE;
     int                dir;
     int                flags = 0;
+    int                save_unnamed = FALSE;
+    yankreg_T  *old_y_current, *old_y_previous;
 
     if (cap->oap->op_type != OP_NOP)
     {
@@ -7551,6 +7553,7 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
            // overwrites if the old contents is being put.
            was_visual = TRUE;
            regname = cap->oap->regname;
+           save_unnamed = cap->cmdchar == 'P';
 #ifdef FEAT_CLIPBOARD
            adjust_clip_reg(&regname);
 #endif
@@ -7568,6 +7571,11 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
            }
 
            // Now delete the selected text. Avoid messages here.
+           if (save_unnamed)
+           {
+               old_y_current = get_y_current();
+               old_y_previous = get_y_previous();
+           }
            cap->cmdchar = 'd';
            cap->nchar = NUL;
            cap->oap->regname = NUL;
@@ -7577,6 +7585,12 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
            empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
            --msg_silent;
 
+           if (save_unnamed)
+           {
+               set_y_current(old_y_current);
+               set_y_previous(old_y_previous);
+           }
+
            // delete PUT_LINE_BACKWARD;
            cap->oap->regname = regname;
 
index a3af8b337ca82f380c7b2727f2699f8c399dfdd9..2633f0238bac79fce81cb89bb9f42b73896491cc 100644 (file)
@@ -54,37 +54,29 @@ get_y_register(int reg)
 }
 #endif
 
-#if defined(FEAT_CLIPBOARD) || defined(FEAT_VIMINFO) || defined(FEAT_EVAL) || defined(PROTO)
     yankreg_T *
 get_y_current(void)
 {
     return y_current;
 }
-#endif
 
-#if defined(FEAT_CLIPBOARD) || defined(FEAT_VIMINFO) || defined(PROTO)
     yankreg_T *
 get_y_previous(void)
 {
     return y_previous;
 }
-#endif
 
-#if defined(FEAT_CLIPBOARD) || defined(PROTO)
     void
 set_y_current(yankreg_T *yreg)
 {
     y_current = yreg;
 }
-#endif
 
-#if defined(FEAT_CLIPBOARD) || defined(FEAT_VIMINFO) || defined(PROTO)
     void
 set_y_previous(yankreg_T *yreg)
 {
     y_previous = yreg;
 }
-#endif
 
     void
 reset_y_append(void)
index af54615c48a104985b203d4ae27e899a78a048f1..d336f5b38a439133635d9be663f5a914e4539cee 100644 (file)
@@ -1358,8 +1358,32 @@ func Test_visual_undo_deletes_last_line()
   exe "normal ggvjfxO"
   undo
   normal gNU
+
   bwipe!
 endfunc
 
+func Test_visual_paste()
+  new
+
+  " v_p overwrites unnamed register.
+  call setline(1, ['xxxx'])
+  call setreg('"', 'foo')
+  call setreg('-', 'bar')
+  normal 1Gvp
+  call assert_equal(@", 'x')
+  call assert_equal(@-, 'x')
+
+  if has('clipboard')
+    " v_P does not overwrite unnamed register.
+    call setline(1, ['xxxx'])
+    call setreg('"', 'foo')
+    call setreg('-', 'bar')
+    normal 1GvP
+    call assert_equal(@", 'foo')
+    call assert_equal(@-, 'x')
+  endif
+
+  bwipe!
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index eb5006b1b65222d5e6ec6ef8b9761c76ea963cb8..882fb0bf242a030f7abe24f3494af09f838f59c2 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4242,
 /**/
     4241,
 /**/