Thursday, April 16, 2009

vim: seeking %

I use vim for my text editing needs. And I've recently been coding a lot in Python. Python, as you may well know, is a "{}"-less language. It depends on semantic whitespace to mark out blocks of code.

I find this to be very intuitive. But the one place I miss the braces is when I need to find the beginning (or end) of a block. Normally one can use the "%" command in vim to do this in C code. Alas no such luck for Python. (Remember the semantic whitespace? :)

(Note: I'm misusing the term "command" here. The more accurate description is cursor motion command, but that seems rather long. ;)

I found a little hack to get around this obstacle. Just make sure that Python blocks don't have empty lines in them. The aptly named "{" and "}" commands take you to the beginning and ending of a paragraph respectively. (Just make sure there are no empty lines.)

No comments: