I like Breya's answer. However, I think the following is a little more flexible since you do not need to modify your vimrc file. It is also easier to format individual parts of an XML file (something that I often do).
First select the XML you want to format.
Then in normal mode, enter ! xmllint --format - ! xmllint --format -
Your line at the bottom will look like this:
:'<,'>!xmllint --format -
Then press enter.
Technical explanation
The selected text is sent to the xmllint , then --format 'ed, and the xmllint results are placed above the selected text in vim. - at the end of the command - to accept standard input - which in this case is the selected text that vim sends to xmllint .
Jesse Hogan Jan 29 '14 at 18:27 2014-01-29 18:27
source share