Posted by virantha on Fri 01 March 2013

Better VIM for Python

As someone who spends a large fraction of their day editing text and code, I've often thought about just investing a few days learning the more advanced time-saving features of my text-editor, VIM. Unfortunately, "a few days" just doesn't happen, and the few times I did learn some new tips, I ended up forgetting them after a few days through disuse. So I'm going to start a new series of blog posts, mainly for my own reference, that I'll try to come back to often and refresh my memory.

Most of this is based on the excellent resources already out there on the web, most notably these posts:


At work, we try to enforce pretty strict guidelines on the readability of python code You only write a specific piece of code a few times, but you or someone else will have to read it many times over, so it makes sense to optimize readability over getting it written as quickly as possible.  The Align plugin makes some of these readability guidelines simple to implement and maintain, by allowing you to align function arguments, variable assignments, etc.

For example, if you have code like in the following nonsensical example:

a = 1 # set a
nextvar = "kdjf" # hmmm
cdk = 2

Selecting ("V") and typing Align = # will reformat your text as:

a       = 1 # set a
nextvar = "kdjf" # hmmm
cdk     = 2

© Virantha Ekanayake. Built using Pelican. Modified svbhack theme, based on theme by Carey Metcalfe