0

In Vim you can use Ctrl+v to select a vertical block of code. This is pretty cool, as this way you can insert a rectangular block of text anywhere in your text. A feature I haven't seen anywhere else yet.

But say I have a text like:

1 abcde
2 abcdefg
3 abcdefg
4 abc

I want to select this full block as vertical block. If I'm on the a of line 1, and start selection, then move down to line 4, I can only move the cursor to the last character c in that line. So the lines above are cut off, giving me this selection:

1 abc
2 abc
3 abc
4 abc

Is there a way to get the full text selected as vertical block?

dreftymac
  • 31,404
  • 26
  • 119
  • 182
Michael Härtl
  • 8,428
  • 5
  • 35
  • 62

3 Answers3

2

if you want to select exact 4 lines (including the 1st line), you could:

Ctrl-V$3j

this selects all the texts, but they are not really in a "block", because the first line and the last line have different length.

If you do want have a "block" of text, (appending spaces on those "shorter" lines), you could:

set ve=all
Ctrl-V hhhhh... jjjjj...

by setting ve to all, your cursor could go anywhere. If you like after the selection/copying, you could set the ve back to its original value.

Kent
  • 189,393
  • 32
  • 233
  • 301
1

A minute after asking this question i found it out myself. The trick is to press $ on line 4 above. So the full series of keystrokes, if the cursor is on the a of line 1 is:

Ctrl+v3j$

Michael Härtl
  • 8,428
  • 5
  • 35
  • 62
0

a quick and dirty solution is to insert 4 spaces a the end of line 4.

Fabrice Jammes
  • 2,275
  • 1
  • 26
  • 39