How to indent Python with VIM

Today I solved the problem of properly indenting my Python code with my favorite editor (Vim 7.2).

I’ve had this issue for some time, because I had tuned Vim for writing in C/C++, which of course proves quite annoying when trying to write Python code (no braces darling!).

Googling the issue I came up with the article “Indenting Python with VIM” which proves quite useful, but unfortunately did not work out of the box for me.

The issue was that the “ftplugin” solution suggested in the article was not enabled on my Vim. After some searching I found out that I should enter the following commands in my .gvimrc:

“enable filetype plugin and indentation filetype plugin on filetype indent on

After that the settings in ~/.vim/ftplugin/python.vim and ~/.vim/indent/python.vim (downloaded from http://www.vim.org/scripts/script.php?script_id=974) script files worked as described.

Problem solved. Now let’s write some code!

This post has been mirrored on my posterous blog Gnosis