Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Quickly select rectangular blocks of text in visual-block mode

Tags:

vim

I'm looking for a fast way to select a block of text in visual-block mode. I deal with files of this nature:

aaaa bbbb cccc
aaaa bbbb cccc
aaaa bbbb cccc

dddd Xeee ffff
dddd eeee ffff
dddd eeee ffff

gggg hhhh iiii
gggg hhhh iiii
gggg hhhh iiii

My goal is to select the middle block in visual-block mode. I would do:

  1. Navigate to the corner (where the X is)
  2. Ctrl-V
  3. 'e' to extend selection to the end of block
  4. 'jj' or '2j' to extend the selection downward to the bottom of the block.

I'm looking for an alternative to (4) that, similar to 'e', would move to the last row of the block. In this simple example 'jj' is not too inconvenient, but sometimes these are large blocks.

There's a similar question here , but that involves jumping a pre-determined number of lines. Is there a way to do this, again an analog to 'e', but moving row-wise instead of column-wise? Thanks!

like image 202
user2777293 Avatar asked Sep 13 '13 17:09

user2777293


1 Answers

Starting on the X, you could do this with <C-v>}kee:

  1. <C-v> – start blockwise visual mode
  2. } – go to the end of the paragraph (that motion supposedly provides the benefit of this rather involved combo)
  3. k – one above to exclude the empty line
  4. ee – move the cursor from the first column to the end of the inner block.
like image 70
Ingo Karkat Avatar answered Nov 13 '22 22:11

Ingo Karkat