Cleaning up XML using VIM

Here is a quick function for cleaning up XML without any line breaks. This is a quick and dirty solution with some minor issues (e.g. turning <test></test> to <test>\n</test>), but the goal of this it not to be too accurate, but to quickly put a non-readable XML into a readable form for reference.

1
2
3
4
5
6
function! PrettifyXML()
	set ft=xml
	:%s/></>\r</g
	:0
	:norm =G
endfunction

Put this in your vimrc file and call it using :call PrettifyXML()

Comments

5:10 p.m. Sunday May. 8, 2011 (about 1 hour, 6 minutes after publishing)
Can you provide a sample input and output file? Rehman Masood
Can you provide a sample input and output file?
5:11 p.m. Sunday May. 8, 2011 (about 1 hour, 8 minutes after publishing)
RE: Can you provide a sample input and output file? farhan
This is a VIM function so you have to run it with the file open (i.e. in the active buffer).
Add new comment