Vim, Tidy and XML - how to make them work together
BackgroundI use vim as my main IDE. I found that I often have to muck and view XML. Often this XML is from debugging logs or output that don't add whitespace (and why would they).
The following is my setup for a small vim filetype mapping to automatically clean up xml using HTML tidy. Another great tool.
How ToFirst, You'll need $HOME/.vim and $HOME/.vim/ftplugin directories.
Create them, if they don't exist:
mkdir -p $HOME/.vim/ftpluginSecond, create a new ftplugin for xml.
vim $HOME/.vim/ftplugin/xml.vimThird, add mapping for tidy (I use F3)
" tidy for xml -q makes it quietNow when you edit a file with a type of xml, you can press F3 your xml will be tidy'd. This does require that you save the xml file somewhere first (you'll need a valid filename).
map <F3> :%! tidy -q -i -xml % <CR>
- I've only used this on UN*Xs OSs
- I use vim 7.x, it will probably work on 6
- I enable filetype support in my .vimrc with command filetype plugin indent on
- On solaris I have to do some crazy function key mapping inside of .vimrc