简体   繁体   English

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

[英]Tabs for indentation in python files in vim

I'm trying to get vim to indent using tabs for python files.我试图让 vim 使用 python 文件的制表符缩进。 I don't want a discussion about the merits of tabs vs spaces, I just want tabs.我不想讨论制表符与空格的优点,我只想要制表符。 In my vimrc, I not only have在我的 vimrc 中,我不仅有

set shiftwidth=4
set tabstop

but I also have some python specific settings:但我也有一些特定于 python 的设置:

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

This seems like it should correctly set my indentation settings in python files but when I open one, it shows literal tabs as 8 characters wide and the TAB key inserts 4 spaces.这似乎应该在 python 文件中正确设置我的缩进设置,但是当我打开一个时,它显示文字制表符为 8 个字符宽,TAB 键插入 4 个空格。 Is there something else that I could be doing here?还有什么我可以在这里做的吗?

I just figured it out.我只是想通了。 In my augroup , I was using a capital "P" in Python, when it should be lowercase.在我的augroup ,我在 Python 中使用了大写的“P”,而它应该是小写的。 This following works perfectly:以下工作完美:

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

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

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