Tip #349: Format your xml document using xmllint
tip karma |
Rating 20/8, Viewed by 484
|
created: |
|
October 23, 2002 17:18 |
|
complexity: |
|
basic |
author: |
|
Daniel Allen |
|
as of Vim: |
|
6.0 |
If you open an xml document that is either totally or partially unindented, you can use the GNU libxml2 libary's xmllint to reformat and align your document. This is especially good if you want to save your xml documents using as little space as possible (which would be totally unindented). Just add this under the autocmd section of your .vimrc file
au FileType xml exe ":silent 1,$!xmllint --format --recover - 2>/dev/null"
This instructs vim to take the entire contents of a *.xml file and pass it through xmllint, using the --format and --recover flags and silencing any errors that may occur. This is generally a very effective process and will only mess up on very poorly typed (a large amout of incorrect syntax) xml documents. Please note that xmllint only adds and removes structural space. It does not remove space from regular text nodes (as doing so would be incorrect).
<<Quickly insert a single word |
when 'formatoptions' has o easily enter a non commented line: go/gO mappings >>
Additional Notes
|