35

I love vim's visual mode. However when I select some text then do something to it the text is then unselected.

For example lets say that I select a block of code and indent it the code is then unselected so if you pressed 4 > instead of 5 > then you have to reselect the code to indent it one more tab.

Is there anyway to not deselect a block of code after preforming an operation? Alternately is there a way to select the same code again (with one keystroke) after an operation has been preformed?

Robotnik
  • 2,645

3 Answers3

55

There isn't a way to leave it selected, but there is a way to get the same selection back without all that manual labour. Select your stuff, do what you need (let's say, indent it), it will unselect itself, then gv

Rook
  • 24,289
29

Add these two (three with comment) lines to your .vimrc (_vimrc for windows):

"make < > shifts keep selection
vnoremap < <gv
vnoremap > >gv

They cause the shift commands to reselect the visual area after use. VERY handy.

lornix
  • 11,909
16

Hit the "." (period) in command mode to repeat your last edit.

Alex
  • 161