A blog by Gary Bernhardt, Creator & Destroyer of Software

Cyclomatic Complexity in Vim: First Steps

25 Oct 2009

I've been kicking around the idea of integrating complexity analysis with vim. Tonight, I spent a couple hours getting a proof of concept working (for Python code, naturally). Each line gets highlighted based on the complexity of the function: green for low, yellow for medium, red for high.

screenshot of vim complexity plugin

A static image doesn't really do it justice – the highlighting updates whenever you write a file. There's a 15 second video of me demoing it that's much better than the picture above.

This is based on Dave Stanek's cyclomatic complexity code. It's hacked together and the complexity algorithm seems slightly wrong (unless I'm remembering it incorrectly). However, it does successfully compute the complexity and highlight the code, which is good enough for a blog post. ;)

If you're feeling adventurous, you can find the source code on BitBucket.