问题描述
我在 CentOS 5 上安装了 Vim 7(增强版),它附带所有常用的 Vim 插件/脚本.
I have Vim 7 (enhanced) on CentOS 5, and it comes with all the usual Vim plugins/scripts ready to go.
$ find /usr/share/vim/vim70/ -name \*python\*
/usr/share/vim/vim70/syntax/python.vim
/usr/share/vim/vim70/ftplugin/python.vim
/usr/share/vim/vim70/indent/python.vim
/usr/share/vim/vim70/autoload/pythoncomplete.vim
我认为当打开以 .py (vim file.py
) 结尾的文件时,它会自动加载这些插件,但我不确定是否是这种情况.我想要的是:
I would think that when opening a file ending in .py (vim file.py
) it would automatically load these plugins, but I am not sure that is the case. What I want is:
按 并收到四个空格.套件、条件等的下一行自动缩进
Press and receive four spaces. Auto indent next line for suites, conditionals, etc.
我通过在我的 .vimrc 文件中明确设置 tabstop、shiftwidth 等来实现这一点.这不是上面的 Python 文件的用途吗?为什么我必须在 .vimrc
中设置这些东西?我如何从 Vim 插件中获取这些功能?
I have this working by explicitly setting tabstop, shiftwidth, etc. in my .vimrc file. Isn't this what the above Python files are for? Why do I have to set these things in my .vimrc
? How do I get these features from the Vim plugins instead?
当前的.vimrc:
syntax on
set hls
set expandtab
set textwidth=0
set tabstop=4
set softtabstop=4
set shiftwidth=4
set autoindent
set backspace=indent,eol,start
set incsearch
set ignorecase
set ruler
set wildmenu
set smarttab
filetype indent on
filetype on
filetype plugin on
推荐答案
在 vimrc 中设置 tabstop、shiftwidth 等是正确的.这些设置您的全局设置,并用作特定于文件类型的缩进支持的参数.
Setting tabstop, shiftwidth, etc... in your vimrc is correct. These set your global settings, as well as serve as parameters to the filetype-specific indentation support.
语言缩进插件使用这些设置,但通常也会设置适合语言的缩进表达式 (:he inde
).因此,Python 缩进应该在块开始语句(def、class、for...)之后自动缩进,并在关闭语句(return、pass、continue...)之后自动缩进,并根据 ts、sw、...你已经设置了.
The language indentation plugins use these settings, but typically also set an indent expression (:he inde
) appropriate for the language. Thus the Python indenter should be automatically indenting after a block opening statement (def, class, for...), and dedenting after a closing one (return, pass, continue...) and doing so according to the ts,sw,... you have set.
如果您仍然不确定插件是否正在加载缓冲区,只需执行 :filetype
以显示检测、插件和缩进设置,然后执行 :set ft?
代码>查看检测到的类型.
If you're still unsure if the plugin is loading for a buffer, simply do :filetype
to show the detection, plugin, and indent settings, and :set ft?
to see the detected type.
这篇关于Vim Python 缩进不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!