diff options
author | Bram Moolenaar <bram@vim.org> | 2013-11-04 01:41:17 +0100 |
---|---|---|
committer | Bram Moolenaar <bram@vim.org> | 2013-11-04 01:41:17 +0100 |
commit | c13473f90d898988be409cd6a9e797869be30229 (patch) | |
tree | e8a373265a7176d284b0a103bebf84f4e148eb58 | |
parent | 899c56b71f968836fbaf376df08e85dc307f79b8 (diff) | |
download | vim-c13473f90d898988be409cd6a9e797869be30229.tar.gz |
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)
-rw-r--r-- | src/normal.c | 7 | ||||
-rw-r--r-- | src/ops.c | 47 | ||||
-rw-r--r-- | src/testdir/test39.in | 4 | ||||
-rw-r--r-- | src/testdir/test39.ok | bin | 244 -> 340 bytes | |||
-rw-r--r-- | src/version.c | 2 |
5 files changed, 48 insertions, 12 deletions
diff --git a/src/normal.c b/src/normal.c index 87e979d1..9349be2b 100644 --- a/src/normal.c +++ b/src/normal.c @@ -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; } @@ -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 diff --git a/src/testdir/test39.in b/src/testdir/test39.in index d39ba82d..96995e08 100644 --- a/src/testdir/test39.in +++ b/src/testdir/test39.in @@ -32,6 +32,10 @@ Oblah di doh dutVkUj :" Uppercase part of two lines ddppi333k0i222fyllvjfuUk +:" visual replace using Enter or NL +G3o1234567892k05l2jr
G3o987652k02l2jr
+G3o1234567892k05l2jr +G3o987652k02l2jr :/^the/,$w >> test.out :qa! ENDTEST diff --git a/src/testdir/test39.ok b/src/testdir/test39.ok Binary files differindex 38a5bc3a..4ebecf6c 100644 --- a/src/testdir/test39.ok +++ b/src/testdir/test39.ok diff --git a/src/version.c b/src/version.c index b46d791b..6610be7b 100644 --- a/src/version.c +++ b/src/version.c @@ -739,6 +739,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 64, +/**/ 63, /**/ 62, |