Wednesday, December 19, 2007

Indent

This is useful for a quick and dirty indent. It works on a variety of file formats, but I typically use it on HTML or XML.

1) open a file
2) issue a :filetype command to see if indenting is ON
3) if it's not, turn it on by doing a :filetype indent on
4) filter the entire file through the program specified by "equalprg" (default is none)
by doing gg=G (no ex mode here).
5) you can set equalprg accordingly if you want to use a 3rd party program:

:setlocal equalprg=tidy\ -quiet\ -m\ -utf8\ %

or if you want to use make rather than equalprg

:setlocal makeprg=tidy\ -quiet\ -errors\ %

then just issue a :make.

2 comments:

Douglas said...

See Vim tip #18, Cleanup your HTML. It describes this in some detail.

Jaffer said...

In VI mode,

select the part of the file that is to be indented.

Press '='