]> granicus.if.org Git - vim/commitdiff
updated for version 7.4.064 v7.4.064
authorBram Moolenaar <Bram@vim.org>
Mon, 4 Nov 2013 00:41:17 +0000 (01:41 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 4 Nov 2013 00:41:17 +0000 (01:41 +0100)
Problem:    When replacing a character in Visual block mode, entering a CR
            does not cause a repeated line break.
Solution:   Recognize the situation and repeat the line break. (Christian
            Brabandt)

src/normal.c
src/ops.c
src/testdir/test39.in
src/testdir/test39.ok
src/version.c

index 87e979d1df35c9cbf1775d574cd76d4b49c86236..9349be2bb4ef1edc0e70c65193877a9101ac5705 100644 (file)
@@ -7036,6 +7036,13 @@ nv_replace(cap)
     {
        if (got_int)
            reset_VIsual();
+       if (had_ctrl_v)
+       {
+           if (cap->nchar == '\r')
+               cap->nchar = -1;
+           else if (cap->nchar == '\n')
+               cap->nchar = -2;
+       }
        nv_operator(cap);
        return;
     }
index 4a198487cc42865934f6d4d21281e2ba3a0df646..1f2e97eea12015b65408ef9a4b26005e3998db57 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -2074,10 +2074,15 @@ op_replace(oap, c)
     char_u             *newp, *oldp;
     size_t             oldlen;
     struct block_def   bd;
+    char_u             *after_p = NULL;
+    int                        had_ctrl_v_cr = (c == -1 || c == -2);
 
     if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty)
        return OK;          /* nothing to do */
 
+    if (had_ctrl_v_cr)
+       c = (c == -1 ? '\r' : '\n');
+
 #ifdef FEAT_MBYTE
     if (has_mbyte)
        mb_adjust_opend(oap);
@@ -2164,25 +2169,43 @@ op_replace(oap, c)
            /* insert pre-spaces */
            copy_spaces(newp + bd.textcol, (size_t)bd.startspaces);
            /* insert replacement chars CHECK FOR ALLOCATED SPACE */
-#ifdef FEAT_MBYTE
-           if (has_mbyte)
+           /* -1/-2 is used for entering CR literally. */
+           if (had_ctrl_v_cr || (c != '\r' && c != '\n'))
            {
-               n = (int)STRLEN(newp);
-               while (--num_chars >= 0)
-                   n += (*mb_char2bytes)(c, newp + n);
+#ifdef FEAT_MBYTE
+               if (has_mbyte)
+               {
+                   n = (int)STRLEN(newp);
+                   while (--num_chars >= 0)
+                       n += (*mb_char2bytes)(c, newp + n);
+               }
+               else
+#endif
+                   copy_chars(newp + STRLEN(newp), (size_t)numc, c);
+               if (!bd.is_short)
+               {
+                   /* insert post-spaces */
+                   copy_spaces(newp + STRLEN(newp), (size_t)bd.endspaces);
+                   /* copy the part after the changed part */
+                   STRMOVE(newp + STRLEN(newp), oldp);
+               }
            }
            else
-#endif
-               copy_chars(newp + STRLEN(newp), (size_t)numc, c);
-           if (!bd.is_short)
            {
-               /* insert post-spaces */
-               copy_spaces(newp + STRLEN(newp), (size_t)bd.endspaces);
-               /* copy the part after the changed part */
-               STRMOVE(newp + STRLEN(newp), oldp);
+               /* Replacing with \r or \n means splitting the line. */
+               after_p = alloc_check((unsigned)oldlen + 1 + n - STRLEN(newp));
+               if (after_p != NULL)
+                   STRMOVE(after_p, oldp);
            }
            /* replace the line */
            ml_replace(curwin->w_cursor.lnum, newp, FALSE);
+           if (after_p != NULL)
+           {
+               ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE);
+               appended_lines_mark(curwin->w_cursor.lnum, 1L);
+               oap->end.lnum++;
+               vim_free(after_p);
+           }
        }
     }
     else
index d39ba82d9e0ed84b97c15464e86045a5ff8970fe..96995e0896ad6b049b0bc29ee024f9bd81fa76bc 100644 (file)
@@ -32,6 +32,10 @@ Oblah di
 doh dut\eVkUj
 :" Uppercase part of two lines
 ddppi333\ek0i222\efyllvjfuUk
+:" visual replace using Enter or NL
+G3o123456789\e2k05l\162jr\rG3o98765\e2k02l\162jr\16\r
+G3o123456789\e2k05l\162jr
+G3o98765\e2k02l\162jr\16
 :/^the/,$w >> test.out
 :qa!
 ENDTEST
index 38a5bc3a683b375df61b0a24ff4f78a98522fb66..4ebecf6cde60bfb4f90cf2960c4ffec2011efbda 100644 (file)
Binary files a/src/testdir/test39.ok and b/src/testdir/test39.ok differ
index b46d791b45807544bb8c957a793a6122ea6cb307..6610be7bb079c02ad05c5343d7e448d0b5cc6f9f 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    64,
 /**/
     63,
 /**/