Skip to main content

Indent text in vim

Using VISUAL mode

before you want to ensure you prefer TABs or SPACEs (and you not prefer TABs).

set expandtab

Define depth of indention.

:set shiftwidth=2

Enable VISUAL mode V, select text, press >

without VISUAL mode

Enable numbering

:set number

Command below will indent lines 9--16 by width configured above.

9,16>

(I use it to correct 2 spaces into 4 spaces.)

undo is your friend, press u