title: How to automatically re-indent a YAML file?
body: <p>Let's consider this example:</p>
  
  <pre><code>---
  foo:
    alice: female
    bob:   male
  bar:
    - node: 42
      name: none
    - node: 43
      name: none
  </code></pre>
  
  <p>If I decide to reindent everything and start from this:</p>
  
  <pre><code>---
  foo:
  alice: female
  bob:   male
  bar:
  - node: 42
  name: none
  - node: 43
  name: none
  </code></pre>
  
  <p>I don't have enough information to do it. Actually vim's attempt is this:</p>
  
  <pre><code>---
  foo:
      alice: female
  bob:   male
  bar:
      - node: 42
  name: none
  - node: 43
  name: none
  </code></pre>
  
  <p>Ansible cannot make it as well:</p>
  
  <pre><code>---
  foo:
  
  alice: female
  bob:   male
  bar:
  
  - node: 42
    name: none
    - node: 43
      name: none
  </code></pre>
  
  <p>I think a possible workaround would be to add a blank line when indentation is increased: </p>
  
  <pre><code>---
  foo:
  
    alice: female
    bob:   male
  bar:
  
    - node: 42
      name: none
    - node: 43
      name: none
  </code></pre>
  
  <p>In my opinion, the main problem with YAML is that people are still fighting with tabs, spaces and indent size. For large YAML files that are edited by several people, the resulting file cannot be properly parsed anymore. The two solutions I see are:</p>
  
  <ol>
  <li>Use only tabs and force tabs identation as this is the case with Makefiles</li>
  <li>The above solution </li>
  </ol>