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 c.vim
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?
Example C code with unmatched parens:
int main(void
{ /* brace highlighted in red */
} /* brace highlighted in red */
Since python code doesn't have curly braces to highlight, we'll have to choose something else (perhaps other parentheses).
BTW, I tried out this vim plugin but I wasn't happy with the behavior.
Edit:
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 file.write()
method call. It would be nice if I could get vim to make that mistake more visually obvious.
Update:
Ok, here's what I've tried so far.
:syn region pParen transparent start="(" end=")" contains=ALL
:syn match pError display ")"
:hi def link pError Error
Unfortunately, all this does is highlight as an error the right paren of all balanced 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.
Have you tried using matchit.vim? It supports all sorts of matches, and it should work in Python.