2

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 (including the spaces)...

<person>

    <name>Nick</name>
    <age>26</age>
    <gender>male</gender>
    <occupation>doctor<occupation>

</person>

I've tried using these commands within vi:

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

But it just removes all of my indentation I had. So now, everything look like this:

<person>
<name>Nick</name>
<age>26</age>
<gender>male</gender>
<occupation>doctor</occupation>
</person>
Rob Avery IV
  • 3,562
  • 10
  • 48
  • 72
  • See the following question: http://stackoverflow.com/questions/7600860/getting-vim-to-recognize-xml – Mauritz Hansen Feb 12 '13 at 18:55
  • One issue with the xml you provided is that the occupation tag is not properly closed. If it is a well formed XML, vim should do its job given the options you tried. – amit Apr 02 '13 at 10:33

0 Answers0