title: Highlighting unmatched brackets in vim
body: <p>I'm getting burned repeatedly by unmatched parentheses while writing python code in vim.  I like how they're handled for C code - vim highlights in red all of the curly braces following the unmatched paren.  I looked at the <code>c.vim</code> syntax file briefly to try to understand it, but the section that handles bracket errors is very complex.  Can anyone explain how that code works and suggest how I might write something similar for python code?</p>
  
  <p>Example C code with unmatched parens:</p>
  
  <pre><code>int main(void
  {  /* brace highlighted in red */
  }  /* brace highlighted in red */
  </code></pre>
  
  <p>Since python code doesn't have curly braces to highlight, we'll have to choose something else (perhaps other parentheses).</p>
  
  <p>BTW, I tried out <a href="http://www.vim.org/scripts/script.php?script_id=350" rel="noreferrer">this vim plugin</a> but I wasn't happy with the behavior.</p>
  
  <p>Edit:</p>
  
  <p>I'm using python to generate C++ code (a language that likes parentheses and semicolons).  I have a nasty habit of leaving the trailing paren off a <code>file.write()</code> method call.  It would be nice if I could get vim to make that mistake more visually obvious.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Ok, here's what I've tried so far.</p>
  
  <pre><code>:syn region pParen transparent start="(" end=")" contains=ALL
  :syn match pError display ")"
  :hi def link pError Error
  </code></pre>
  
  <p>Unfortunately, all this does is highlight as an error the right paren of all <strong>balanced</strong> parentheses, the opposite of what I want to do.  I really don't understand what I'm doing here (just copied off of the existing C syntax file).  If anyone could explain what I did (wrong), I would appreciate it.</p>