简体   繁体   English

仅在python文件中将选项卡扩展到vim中的空格?

[英]Expand tabs to spaces in vim only in python files?

How do I have the tab key insert 4 spaces when I'm editing "*.py" files and not any other files? 当我编辑“* .py”文件而不是任何其他文件时,如何让tab键插入4个空格?

Following a recommendation from Vim and PEP 8 -- Style Guide for Python Code , I installed vim-flake8 (and vim-pathogen). 根据Vim和PEP 8 - Python Code样式指南的推荐,我安装了vim-flake8(和vim-pathogen)。 This gives warnings when PEP8 style guidelines are violated. 当违反PEP8样式指南时,这会发出警告。 This is great, but I would for tabs to be expanded automatically in the first place when editing python files. 这很棒,但我想在编辑python文件时首先自动扩展标签。 I would like to have tab key actually insert tabs when editing other types of files. 我想在编辑其他类型的文件时让tab键实际插入标签。

In other words, I want the following to apply when I'm editing python files and only python files: 换句话说,我想在编辑python文件和python文件时应用以下内容:

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
autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4

甚至更短:

au Filetype python setl et ts=4 sw=4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM