Vi: properly format XML on one line

During testing, I sometimes dump XML responses straight to a file for investigation. Rather than writing test code to format it properly, and then get rid of it when I don't need it anymore, I wrote me a vim macro. Keep in mind this will only work if everything is on one line.

This in my .vimrc:

nnoremap :set ft=xml:%s/\(<[^\/].\{-}>\)/\r\1/g:%s/\(<\/.\{-}>\)\(<\/\)/>\1\r\2/g:g/^$/dvG=

Et voila - F10 gets me a nicely formatted file.
Configuration 0 comments
You must be logged in as a member to add comment to this blog