Indenting selected lines

You can select lines by pressing V, then moving the cursor down or up (with j or k). After selecting lines, press > to increase the indent, or < to decrease it. Then press . to repeat the action, or u to undo it.
If you want the visual selection to be retained after pressing > or <, use these mappings:

:vnoremap > >gv
:vnoremap < <gv

An alternative for anyone using :behave mswin, is to select lines by holding down Shift and pressing the cursor down or up arrow keys. However, in select mode, if you press >, the selected text will be replaced with ‘>’. Instead, you can use Tab to increase the indent, and Shift-Tab to decrease it, with these mappings:

:vnoremap <Tab> >
:vnoremap <S-Tab> <

In select mode, visual-mode mappings temporarily set visual mode (:help Select-mode-mapping).Also, the select mode will be retained. You could use the following alternative if you want to exit from select mode after pressing Tab or Shift-Tab:

:vnoremap <Tab> >gV
:vnoremap <S-Tab> <gV

1 Response to “Indenting selected lines”


  1. 1 retained mode Pingback on Apr 7th, 2010 at 4:38 am

Leave a Reply