title: Vim: Making XML text “pretty”
body: <p>Is there an easy way within <code>vi</code> to make your XML text "pretty"?</p>
  
  <p>For example:</p>
  
  <p>I want this..</p>
  
  <pre><code>            &lt;person&gt;
    &lt;name&gt;Nick&lt;/name&gt;
   &lt;age&gt;26&lt;/age&gt;
  
           &lt;gender&gt;male&lt;/gender&gt;
  &lt;occupation&gt;doctor&lt;/occupation&gt;
  
      &lt;/person&gt;
  </code></pre>
  
  <p>to be this (including the spaces)...</p>
  
  <pre><code>&lt;person&gt;
  
      &lt;name&gt;Nick&lt;/name&gt;
      &lt;age&gt;26&lt;/age&gt;
      &lt;gender&gt;male&lt;/gender&gt;
      &lt;occupation&gt;doctor&lt;occupation&gt;
  
  &lt;/person&gt;
  </code></pre>
  
  <p>I've tried using these commands within <code>vi</code>:</p>
  
  <pre><code>:set filetype=xml
  :filetype indent on
  gg=G
  </code></pre>
  
  <p>But it just removes all of my indentation I had. So now, everything look like this:</p>
  
  <pre><code>&lt;person&gt;
  &lt;name&gt;Nick&lt;/name&gt;
  &lt;age&gt;26&lt;/age&gt;
  &lt;gender&gt;male&lt;/gender&gt;
  &lt;occupation&gt;doctor&lt;/occupation&gt;
  &lt;/person&gt;
  </code></pre>