Wednesday, June 2, 2010

Vim tricks for Python programmers

Hi there, as many of my friends know I am a Vi enthusiast. The truth is that I am just faster using Vi than using the mouse in any graphical editor. I know many of *NIX users would agree with me when it comes to command line vs. clicking.

This post is for Vi users that may find frustrating programming Python without a mouse cursor to help on indentation and block selection. The tricks are to set these environmental variables on Vi:

autocmd BufRead *.py \
set expandtab \
set tabstop=4 \
set shiftwidth=4 \
set smarttab \
set softtabstop=4 \
set autoindent \
set textwidth=110
autocmd BufRead *.py set smartindent \

So if you put this on your ~/.vimrc you should get a Vi that is Python friendly every time you edit a *.py file.

Essentially these options will make tabs become 4 spaces and add auto-indentation after keywords of python (if, while, do, try, etc...). For more info on each command type on Vi ':help '

Have fun!

1 comment:

Locations of visitors to this page