I often have to manually indent, but when I enter a visual mode, select my lines to indent, and press < or >, I leave visual mode whether I want to or not.

I would rather have it so I stay in visual mode, and keep my selection and cursor position intact.

How can I achieve this?

  • 1
    Is there any chance a remapping would do the trick ? Something like :vmap < <a ?
    – Feffe
    Commented Jun 24, 2016 at 14:04

3 Answers 3


I have this in my vimrc:

"keep visual mode after indent
vnoremap > >gv
vnoremap < <gv

Note that you could also simply use . (dot) to repeat the last indent action.

  • 1
    Almost perfect, save that my cursor does not move with the row.
    – Anon
    Commented Jun 24, 2016 at 14:17
  • 1
    @Akiva Maybe you want to add a ^ at the end of that mapping? i.e. >gv^? Commented Jun 24, 2016 at 14:21
  • 2
    The cursor seems to move (or not) depending on its position with respect to the indented text. It's not clear for me where do you want the cursor to stay: at the same column number, or on the same character? Also, you know that you can still move the cursor e.g. with j, k, l etc. while in visual mode?
    – VanLaser
    Commented Jun 24, 2016 at 14:32
  • 3
    Honestly, I just put <Right> And <Left> after the commands, and that worked fine.
    – Anon
    Commented Jun 24, 2016 at 14:42

I know this isn't an automatic solution, but you can accomplish this by using gv after the visual indent.

This will go into visual mode with the previous selection selected, and your cursor at the last line. See :h gv for more info.


I tried adding the following mapping to my vimrc :

vmap < <a
vmap > >a

It seems to have interesting results, maybe that's what you're looking for ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.