Autoindentation in Vim for Python

I'm attempting to switch over to VIM right now, and would like to get it to indent automatically as an IDE would for Python. I've got the following .vimrc file

syntax on
set number
autocmd FileType tex,latex,python set showmatch
nnoremap j gj
nnoremap k gk
"Python Settings
autocmd FileType python set softtabstop=4
autocmd FileType python set tabstop=4
autocmd FileType python set autoindent
autocmd FileType python set expandtab
autocmd FileType python set textwidth=80
autocmd FileType python set smartindent
autocmd FileType python set shiftwidth=4
autocmd FileType python map <buffer> <F2> :w<CR>:exec '! python' shellescape(@%, 1)<CR>
autocmd FileType python imap <buffer> <F2> <esc>:w<CR>:exec '! python' shellescape(@%, 1)<CR>

The code automatically indents in some cases. For instance, I've tried if statements and while statements, which after hitting enter are indented. So the following will indent properly.

if True: #this is where my next line automatically starts
while True: #this is where my next line automatically starts

But for class/function definitions, there is no indentation.

class Request_Form(QDialog):
#no indentation -- cursor comes here

Could anyone help me correct this behavior

1

1 Answer

Adding the following line to my vimrc file fixed the issue:

filetype plugin indent on

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like