Last Updated: February 25, 2016
·
3.95K
· spencerwi

Set vim's equalprg for better formatting

One of vim's more useful features (sometimes) is the ability to format/indent code in the many syntax types it supports using = .

Of course, it's not always perfect. Sometimes there's a better tool for the job than vim's builtin behavior.

For times like this, you can set vim's equalprg property for the current buffer. It functions much like makeprg, in that it lets you specify an external command into which the selection (or buffer) will be piped and then replaced with the stdout of that command.

So for example, it's useful when editing xml to set equalprg to use xmllint:

set equalprg=xmllint\ --format\ -