vim's tab length is different for .py files

我与影子孤独终老i 提交于 2019-12-23 08:00:07

问题


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?


回答1:


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.




回答2:


likely you have some plugin installed to ease your python editing, and those plugin re-set some vim options.

You can find out by:

  • open one py file, verify if tabstop/shiftwidth is 4
  • then run command: :verbose set ts and :verbose set sw

You can see where the options were set last time.



来源:https://stackoverflow.com/questions/27403413/vims-tab-length-is-different-for-py-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!