Index ¦ Archives ¦ Atom

Adding Tidy to VIM

I currently am using MarkLogic and by association use XML heavily in my job. I often get an XML file that is all jumbled into one line - a really long line. I knew that html/xml tidy could format this better so I installed tidy and added this mapping to my .vimrc file:

map <leader>x :%!tidy -i -q -xml -raw<CR>

I have <leader> mapped as my comma character so in normal mode I just press ,x and my xml is now all tidied up.

Update 2014-12-28:

Another way to validate an XML document in VIM using xmllint:

noremap <leader>pp :%!xmllint --xmlout --format -<CR>

I still have <leader> mapped as my comma character so in normal mode I just press ,pp and my xml is now all cleaned up. This will also validate any problems and if there are problems I can see what the errors are, undo the change and clean-up the XML.

© Steve Spigarelli. Built using Pelican. Theme by Giulio Fidente on github.