Tip #579: Cut&Paste; without too much newlines, eg. into WORD
tip karma |
Rating 4/6, Viewed by 991
|
created: |
|
October 6, 2003 2:43 |
|
complexity: |
|
basic |
author: |
|
Siegfried Bublitz |
|
as of Vim: |
|
5.7 |
Sometimes I am forced to enter text into MS Word. Since this tool is not
reliable and fast enough for me, I often prefer to create the text in
VIM before and cut&paste; it into Word.
Unfortunately, Word creates newlines of its own and regards entered
newlines as paragraphs. So I created a mapping that deletes all single
newlines from a selected area but keeps multiple ones. Here it is:
vmap <C-C> "+y:let @+ = substitute(@+, "\n\n\n*", "±", "g")
\\|:let @+ = substitute(@+, "\n", " ", "g")<CR>
\\|:let @+ = substitute(@+, "±", "\\n", "g")<CR>
\\|'<
Just shortly what is does:
Copy the visual area into the selection register +, subsitute two and
more newlines but a strange symbol hopefully not contained in the area
(±), substitute single newlines by a blank and resubstitute the strange
symbol by one newline, then go back to the beginning of the selected area.
If you select now text in VIM with V, it is copied with <Ctrl-C> as
described and can be pasted normally into another application.
Siegfried
<<Specify Range with search patterns |
Switching back and forth between ViM and Visual Studio .NET >>
Additional Notes
|