Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quickly select (inner) line-wise in Vim

Vim has some very useful text motions such as ib, i), i}, etcetera to quickly select a portion of text. But, I often need an inner block in line-wise mode. For example (with line numbers):

1:    $foo = array(
2:        'bar' => 'Bar',
3:        'quux' => 'Quux',
4:    );

Now, when my cursor is on line 2 or 3 somewhere and I hit vib or vi), Vim selects line 2, 3 and the indenting spaces on line 4. I just want line 2 and 3. I have tried with Vib and Vi) but they do the same as with a lowercase v.

Is there any easy text motion or other quick way to select an inner block in line-wise mode?

like image 817
Sander Marechal Avatar asked Jul 19 '11 10:07

Sander Marechal


2 Answers

I may get downvotes for this, but I'd just do an upward or downward motion the number of lines I need, like V3j or V2k as long as it's known.

I have a binding that switches between absolute and relative numbering (:set relativenumber) so it's visually easy to identify as long as they're all on screen.

like image 100
Michael Berkowski Avatar answered Sep 17 '22 20:09

Michael Berkowski


I agree that it would be nice to have the behaviour that you describe. If you're determined, then you could always roll your own custom text object using Kana's textobj-user framework. I used this to create a text object for working with ruby blocks, and found it surprisingly easy to do.

like image 23
nelstrom Avatar answered Sep 16 '22 20:09

nelstrom