【问题标题】:Tabs for indentation in python files in vimvim中python文件中的缩进选项卡
【发布时间】:2015-01-16 21:39:52
【问题描述】:

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

set shiftwidth=4
set tabstop

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

augroup python_files
    autocmd!
    autocmd FileType python setlocal noexpandtab
    autocmd FileType Python set tabstop=4
    autocmd FileType Python set shiftwidth=4
augroup END

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

【问题讨论】:

    标签: python vim tabs


    【解决方案1】:

    我刚刚想通了。在我的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
    

    【讨论】:

    • 很高兴你解决了这个问题。您可能需要考虑将这些设置放入~/.vim/after/ftplugin/python.vim。我发现使用 after 目录更简单,更易于维护。这是一篇关于它的好帖子:Transitioning to vim. Having issues with indentation
    • 我在尝试augroup 之前确实这样做了,但这对我不起作用。
    • 使用setlocal 而不是set
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多