Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a vim command or plugin that quickly "beautifies" XML?

I have a file that looks like

<parent><child attr="bla"><subitem>Hello!
</subitem></child>
</parent>

and I want to make it look like

<parent>
  <child attr="bla">
    <subitem>Hello!
    </subitem>
  <child>
<parent>
share|improve this question
add comment

1 Answer

Using only vim builtins:

First replace all >< with > [newline] < :

:%s/></>\r</g

Then to reindent:

gg=G

These steps give me the right output for your example data.

share|improve this answer
    
Not sure why but the gg=G is not working for me. I also tried it on a small bock but the = command is not working. –  sixtyfootersdude Mar 31 '11 at 14:27
    
Does == work on a single line? Maybe try :set ft=xml to set indent rules. –  redacted Apr 1 '11 at 15:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.