Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto indent doesn't work when using vim coding python

I want to use vim to write python code but there is a problem on auto indention. First I downloaded the latest python.vim from http://www.vim.org/scripts/script.php?script_id=790 and putted it in the correct dir. Then I edited my vimrc.

syntax on
set nu
set tabstop=4
set softtabstop=4
set shiftwidth=4
"set cindent
set autoindent
set smartindent
set expandtab
set filetype=python
au BufNewFile,BufRead *.py,*.pyw setf python

Now I find that keywords like 'for', 'if', 'while' can autoindent perfectly. But it doesn't work on 'def', 'try', 'except'. What should I do? Thank you very much.

like image 384
Non-native English Speaker Avatar asked May 15 '13 16:05

Non-native English Speaker


1 Answers

I have this line in my vimrc for long time, don't know if there is better way nowadays. but you could at least give it a try.

set cindent
autocmd FileType python setlocal foldmethod=indent smartindent shiftwidth=4 ts=4 et cinwords=if,elif,else,for,while,try,except,finally,def,class

and I have

filetype plugin indent on  

too

like image 90
Kent Avatar answered Oct 10 '22 19:10

Kent