Hi Bram!
On So, 20 Okt 2013, Bram Moolenaar wrote:
>
> Christian Brabandt wrote:
>
> > Bram,
> > when using visual block_mode and replacing the selected block with=20
> > <Enter>, Vim currently does not break the line, but inserts the=20
> > linebreak literally, e.g. when doing this:
> >
> > 10o12345<ESC>9k02l<C-V>9jr<CR> you are left with:
> > 12^M45
[...]
> >
> > instead of
> > 12
> > 45
> > 12
> > 45
> > [...]
> >
> > Attached patch fixes this and adds a test.
>
> Thanks. I haven't tried it yet, but does it allow using CTRL-V <CR>
> to insert a literal CR as before?
No it doesn't. Problem is, by the time op_replace is called, one doesn't
know, whether it was typed literally. How about using -1/-2 to
distinguish between typing CR/LF literally?
regards,
Christian
--
Es gehört schon zu den Widersprüchen des Menschen, daß er welche zu
haben glaubt.
-- Jean Paul
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff --git a/src/normal.c b/src/normal.c
--- a/src/normal.c
+++ b/src/normal.c
@@ -7036,6 +7036,13 @@
{
if (got_int)
reset_VIsual();
+ if (had_ctrl_v && (cap->nchar == '\r' || cap->nchar == '\n'))
+ {
+ if (cap->nchar == '\r')
+ cap->nchar = -1;
+ else
+ cap->nchar = -2;
+ }
nv_operator(cap);
return;
}
diff --git a/src/ops.c b/src/ops.c
--- a/src/ops.c
+++ b/src/ops.c
@@ -2084,10 +2084,15 @@
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);
@@ -2174,25 +2179,41 @@
/* insert pre-spaces */
copy_spaces(newp + bd.textcol, (size_t)bd.startspaces);
/* insert replacement chars CHECK FOR ALLOCATED SPACE */
+ /* -1/-2 is used for entering CR literally! */
+ if (had_ctrl_v_cr || (c != '\r' && c != '\n'))
+ {
#ifdef FEAT_MBYTE
- if (has_mbyte)
- {
- n = (int)STRLEN(newp);
- while (--num_chars >= 0)
- n += (*mb_char2bytes)(c, newp + n);
+ 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);
+ after_p = alloc_check((unsigned)oldlen + 1 + n - STRLEN(newp));
+ 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
--- a/src/testdir/test39.in
+++ b/src/testdir/test39.in
@@ -32,6 +32,8 @@
doh dutVkUj
:" Uppercase part of two lines
ddppi333k0i222fyllvjfuUk
+:" visual replace using Enter
+G10o123456789019k05l9jr
:/^the/,$w >> test.out
:qa!
ENDTEST
diff --git a/src/testdir/test39.ok b/src/testdir/test39.ok
--- a/src/testdir/test39.ok
+++ b/src/testdir/test39.ok
@@ -11,3 +11,23 @@
DOH DUT
222the yoUTUSSEUU END
333THE YOUTUßeuu end
+12345
+78901
+12345
+78901
+12345
+78901
+12345
+78901
+12345
+78901
+12345
+78901
+12345
+78901
+12345
+78901
+12345
+78901
+12345
+78901