用于在 vim 中的 python 文件中缩进的选项卡

Nat*_*ara 5 python vim tabs

我试图让 vim 使用 python 文件的制表符缩进。我不想讨论制表符与空格的优点,我只想要制表符。在我的 vimrc 中,我不仅有

set shiftwidth=4
set tabstop
Run Code Online (Sandbox Code Playgroud)

但我也有一些特定于 python 的设置:

augroup python_files
    autocmd!
    autocmd FileType python setlocal noexpandtab
    autocmd FileType Python set tabstop=4
    autocmd FileType Python set shiftwidth=4
augroup END
Run Code Online (Sandbox Code Playgroud)

这似乎应该在 python 文件中正确设置我的缩进设置,但是当我打开一个时,它显示文字制表符为 8 个字符宽,TAB 键插入 4 个空格。还有什么我可以在这里做的吗?

Nat*_*ara 5

我刚刚想通了。在我的 中augroup,我在 Python 中使用了大写“P”,而它应该是小写的。以下内容完美运行:

augroup python_files
    autocmd!
    autocmd FileType python setlocal noexpandtab
    autocmd FileType python set tabstop=4
    autocmd FileType python set shiftwidth=4
augroup END
Run Code Online (Sandbox Code Playgroud)

  • 很高兴你解决了这个问题。您可能需要考虑将这些设置放在 `~/.vim/after/ftplugin/python.vim` 中。我发现使用 after 目录更简单且更易于维护。这是一篇关于它的好文章:[过渡到 vim。存在缩进问题](http://stackoverflow.com/q/27804353/438329) (2认同)