Wednesday, December 2, 2009

Indent From Normal Mode

From normal mode, pressing == will indent the current line.

3 comments:

Rob Britton said...

Actually it will indent it to what your indentation settings are for the file type - not so good if you don't have a file type set.
Pressing >> will indent it to the right by one, << will indent it to the left by one.
On another note, doing =G from the top line of your program will properly indent the entire file. That's nice for people who don't use spaces/tabs properly.

Wayne said...

I knew about the >> and << but =G is super useful! (Especially for those of us who code in Python... )

Douglas said...

={motion} filter a set of lines through the first of:

1. equalprg (blank by default)
2. indentexpr, or
3. The C-indenting rules

Typically, non-C syntax files set indentexpr to a function of their own, for instance, when editing a Python file, indentexpr=GetPythonIndent(v:lnum).

== is a shorthand for "filter this line only", in the spirit of yy, dd, etc.

gg=G means "Go to the top of the file, and filter all lines down to the very last one".

<< and >> are entirely different. They force an increase or decrease of indentation on the current line, regardless of the indentexpr.

See :help =