Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid extra whitespace when pasting vertical selection

Tags:

vim

vi

I often need to copy larger vertical selections e.g. when working with (let's stay civilized) "getter/setter"-rich interfaces, e.g

A very long line with something I would like to copy: ABC$
A short line with nothing$
A very long line with something I would like to copy: ABC$

Here I have used $ to indicated the end of the line. I now make a visual vertical selection on e.g. the A in the column 55 across all lines, yank it and paste it with P before that column and get extra whitespace inserted in the second line.

A very long line with something I would like to copy: AABC$
A short line with nothing                              $
A very long line with something I would like to copy: AABC$

Is there a way to avoid the extra whitespace? Changing characters in the vertical visual selection doesn't seem to suffer from this issue.

like image 864
Benjamin Bannier Avatar asked Jun 05 '13 14:06

Benjamin Bannier


1 Answers

This is how visual-block move works. You are copying column 55. Then pasting with P. Your second line does not extend as far as column 55. So when you paste it will extend that line for you.

Use :reg to look at your register. You will noticed A^J ^JA as the value for "", the unnamed register. The ^J symbolize line breaks. Notice the space between ^J's. This is how a visual-block mode yank works with empty space, by filling it in with spaces.

like image 200
Peter Rincker Avatar answered Nov 19 '22 09:11

Peter Rincker