Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabs for indentation in python files in vim

Tags:

python

vim

tabs

I'm trying to get vim to indent using tabs for python files. I don't want a discussion about the merits of tabs vs spaces, I just want tabs. In my vimrc, I not only have

set shiftwidth=4
set tabstop

but I also have some python specific settings:

augroup python_files
    autocmd!
    autocmd FileType python setlocal noexpandtab
    autocmd FileType Python set tabstop=4
    autocmd FileType Python set shiftwidth=4
augroup END

This seems like it should correctly set my indentation settings in python files but when I open one, it shows literal tabs as 8 characters wide and the TAB key inserts 4 spaces. Is there something else that I could be doing here?

like image 434
Lily Mara Avatar asked Jan 16 '15 21:01

Lily Mara


1 Answers

I just figured it out. In my augroup, I was using a capital "P" in Python, when it should be lowercase. This following works perfectly:

augroup python_files
    autocmd!
    autocmd FileType python setlocal noexpandtab
    autocmd FileType python set tabstop=4
    autocmd FileType python set shiftwidth=4
augroup END
like image 99
Lily Mara Avatar answered Sep 23 '22 06:09

Lily Mara