Add the following content to vimrc and then press: PrettyxmlYou can automatically format the XML. However, xmllint must be in your path variable. If you do not have one, please install the libxml2 package.
Function! Doprettyxml ()
"Save The filetype so we can restore it later
Let L: origft = & ft
Set Ft =
"Delete the xml header if it exists. This will
"Permit us to surround the document with fake tags
"Without creating invalid XML.
1 S/ // E
"Insert fake tags around the entire document.
"This will permit us to pretty-format excerpts
"XML that may contain in multiple top-level elements.
0put =' '
$ Put =' '
Silent %! Xmllint -- format-
"Xmllint will insert Header. It's easy enough to delete
"If you don't want it.
"Delete the fake tags
2d
$ D
"Restore the 'normal' indentation, which is one extra level
"Too deep due to the extra tags we wrapped around the document.
Silent % "back to home
1
"Restore The filetype
EXE "set Ft =". L: origft
Endfunction
Command! Prettyxml call doprettyxml ()
This article compiled from http://vim.wikia.com/wiki/Pretty-formatting_XML