How to indent multi-line in vim/gvim?

14,801

Solution 1

The indent commands =, < and > can be combined with all movement commands and text objects. For example:

>G     Indent until end of file
>}     Indent until next paragraph
>iB    Indent contents of current { } block

They also indent text selected in visual mode.

Use < to un-indent or = to re-indent ('format' using the filetype settings).

Solution 2

Yes. Try:

V             # To switch to visual mode. Select lines, and...
>             # Indent (use `<` to de-indent, or with a number just before to indent several times).
Share:
14,801
Tanky Woo
Author by

Tanky Woo

KISS @github: https://github.com/tankywoo

Updated on June 19, 2022

Comments

  • Tanky Woo
    Tanky Woo almost 2 years

    I want to indent multi-line in 'vim/gvim', is there any shortcut in the vim/gvim?

  • sehe
    sehe about 12 years
    = is the 'indent' command, but honestly I think in user-speak to 'indent' usually means > (to increase the indent level), so I'll take the liberty to change the samples to use it
  • alesplin
    alesplin about 12 years
    +1 for suggesting the = option. While usually using > or < is what is desired, it's extremely useful to know that the = re-indent is available.
  • A.Wan
    A.Wan almost 10 years
    apart from just pressing == to smart indent, using = with a movement to a block that you want to align to (e.g. =j or =k) gives a satisfying level of control.