.vimrc configuration for Python

Consider having a look at the official .vimrc for following PEP 7 & 8 conventions. Present over here

http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc


The short answer is that your autocmd is missing the BufEnter trigger, so it isn't being fired when you create a new file. Try this instead:

 au BufEnter,BufRead *.py setlocal smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class

Note that I also changed the set to setlocal. This'll prevent these options from stomping on your other buffers' options.

The "right" way to do what you're trying to do is to add filetype indent on to your .vimrc. This'll turn on the built-in filetype based indentation. Vim comes with Python indentation support. See :help filetype-indent-on for more info.


You shouldn't have to explicitly indent python keywords. The $VIM/indent/python.vim file takes care of that. You just need to turn on filetype indent and autoindent.


Try this:

filetype indent on
filetype on
filetype plugin on

I primarily do Python programming and this is the brunt of my vimrc

set nobackup
set nowritebackup
set noswapfile
set lines=40
set columns=80
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent
set smarttab
filetype indent on
filetype on
filetype plugin on

Tags:

Python

Vim