How to keep in visual mode after identing by shift+> in vim?

16

4

Current it quits the visual mode after indenting once,which is very annoying.

new_perl

Posted 2011-07-14T08:58:44.520

Reputation: 225

Using . is good. But sometimes you need to do a different operation with the selected code after indentig, like yanking, for instance. And you have to select all over again, which sucks – Santi – 2019-04-01T14:25:17.280

5For indenting more than once, simply use the . key to repeat the last operation – barbaz – 2011-07-14T09:47:26.230

Answers

23

You can use the normal mode command gv to highlight the previous visual selection. Therefore, you could use the following mappings:

:vnoremap < <gv
:vnoremap > >gv

The :vnoremap command sets up a mapping that will work only in visual mode. You are therefore rebinding the < and > visual mode commands to perform the indent and immediately re-select the previous visual selection.

user89061

Posted 2011-07-14T08:58:44.520

Reputation:

4It is not correct. Should use vnoremap because vmap will recursively map and it would break – texasbruce – 2014-08-16T18:27:52.660

3@texasbruce: It works fine for me with vmap, however I have edited the answer (and my own .vimrc) to use vnoremap since it is obviously safer. – None – 2015-02-06T15:03:56.600

4

Using period "." will repeat the indentation of the previously selected text if it was the newest edit of the text. This does not reselect the text, but does the job just as well.

Hannes

Posted 2011-07-14T08:58:44.520

Reputation: 41