vimtricks.wiki Concise Vim tricks, one at a time.

How do I indent lines multiple times without reselecting in visual mode?

Answer

>gv

Explanation

Normally, pressing > in visual mode indents the selection but exits visual mode, requiring you to press gv to reselect. By combining > with gv in quick succession, you can repeatedly indent without losing your selection. Mapping this pattern makes multi-level indentation effortless.

How it works

  • > — indent the visual selection one shiftwidth
  • gv — immediately reselect the previous visual selection
  • Repeat > to indent further while maintaining the selection

Example

vnoremap > >gv
vnoremap < <gv
Before:
if (condition) {
code here
more code
}

After V + select + >>> (three indents):
if (condition) {
            code here
            more code
}

Tips

  • Add these mappings to your vimrc for permanent use
  • The same pattern works for < (dedent): vnoremap < <gv
  • Without the mapping, you can manually type >gv>gv> to indent three times
  • Use . in normal mode to repeat the last indent operation as an alternative

Next

How do I return to normal mode from absolutely any mode in Vim?