title: Auto-indenting graphviz .dot file
body: <p>I am working on a long and complex architectural graph. The document indentation mixes tabs, spaces and indentation levels, which drives me crazy.</p>
  
  <p><strong>Is there a simple way to automatically indent graphviz <code>.dot</code> files in Linux environment?</strong></p>
  
  <p>A pure command line tool would be best, but plugins to popular editors like vim would be a good solution too.</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>The vim indentation has a bug with <code>:</code> in node names in edges. For example, <code>server_a:event -&gt; log_server;</code> causes the next line to be further indented, presumably because the <code>:</code> is parsed as a block declaration (see comments on <a href="https://stackoverflow.com/a/20961629/51197">Harry Pehkonen's answer</a>). Quoting the node name (e.g. <code>"server_a":event -&gt; log_server;</code>) solves this issue:</p>
  
  
  
  <pre><code>#!/usr/bin/python3
  
  import re
  
  dot=open('components.dot').read()
  reg=re.compile("(\s)(\S+)(\:.*\-\&gt;)")
  print(reg.sub(r'\1"\2"\3', dot))
  </code></pre>