Artificial intelligent assistant

Vim: Making XML text "pretty" Is there an easy way within `vi` to make your XML text "pretty"? For example: I want this.. <person> <name>Nick</name> <age>26</age> <gender>male</gender> <occupation>doctor</occupation> </person> to be this... <person> <name>Nick</name> <age>26</age> <gender>male</gender> <occupation>doctor</occupation> </person>

I've had the most luck with this:


:%!xmllint --format %


It's strict about your tags, though, so it will error out if your opening and closing tags don't match. It also adds an XML declaration at the top of your file, if you don't have one as well.

This page recommends the following, although I can't get it to work:


:set filetype=xml
:filetype indent on
gg=G


I tested it out, and it seems to work, somewhat. Not perfectly, but it gets the job done.

If that doesn't work well, you could use minidom in Python to format it for you.


import xml.dom.minidom

xml = xml.dom.minidom.parse(filename)
formatted_xml = xml.toprettyxml()

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 4ff729530ea31b42b4ad9e394ec6c868