Expand tabs to spaces in vim only in python files?

只谈情不闲聊 提交于 2021-02-04 09:57:25

问题


How do I have the tab key insert 4 spaces when I'm editing "*.py" files and not any other files?

Following a recommendation from Vim and PEP 8 -- Style Guide for Python Code, I installed vim-flake8 (and vim-pathogen). This gives warnings when PEP8 style guidelines are violated. This is great, but I would for tabs to be expanded automatically in the first place when editing python files. I would like to have tab key actually insert tabs when editing other types of files.

In other words, I want the following to apply when I'm editing python files and only python files:

set expandtab       " tabs are converted to spaces
set tabstop=4       " numbers of spaces of tab character
set shiftwidth=4    " numbers of spaces to (auto)indent

回答1:


autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4

Or even shorter:

au Filetype python setl et ts=4 sw=4


来源:https://stackoverflow.com/questions/9986475/expand-tabs-to-spaces-in-vim-only-in-python-files

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