In my ~/.vimrc
I set tab to me 2 spaces long
set shiftwidth=2
set tabstop=2
However when I open a .py
file, tabs are 4 spaces long. I don't have specific configuration for python files. ~/.vim/after
is empty and searching for py
doesn't raise any suspect lines.
Have you ever experienced that? How to solve such a behaviour?
Specify Tab SizeYou can specify a different tab size than the default size 8. If the length of the words is equal to the tab size then expandtabs() will add the number whitespaces after each word will be equal to tab size argument passed.
To convert tabs to spaces in the currently opened file in Vim, enter the Normal mode by pressing Esc key. Now use the retab command by pressing the ':' (colon) character and Vim will convert the existing tabs to spaces.
It’s defined in the general Python filetype plugin file ($VIMRUNTIME/ftplugin/python.vim
):
" As suggested by PEP8.
setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8
It should be so in order to conform with PEP 8.
@Carpetsmoker adds:
There is a discussion about this on the vim-dev@ list.
You can reset this using this in your ~/.vimrc
; for example:
aug python
" ftype/python.vim overwrites this
au FileType python setlocal ts=4 sts=4 sw=4 noexpandtab
aug end
Or by adding config settings in $HOME/.vim/after
.
likely you have some plugin installed to ease your python editing, and those plugin re-set some vim options.
You can find out by:
4
:verbose set ts
and :verbose set sw
You can see where the options were set last time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With