Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自动缩进不';使用vim编码python时无法工作_Python_Vim_Indentation - Fatal编程技术网

自动缩进不';使用vim编码python时无法工作

自动缩进不';使用vim编码python时无法工作,python,vim,indentation,Python,Vim,Indentation,我想使用vim编写python代码,但在自动缩进方面存在问题。 首先,我从下载了最新的python.vim,并将其放入正确的目录中。 然后我编辑了我的vimrc syntax on set nu set tabstop=4 set softtabstop=4 set shiftwidth=4 "set cindent set autoindent set smartindent set expandtab set filetype=python au BufNewFile,BufRead *.p

我想使用vim编写python代码,但在自动缩进方面存在问题。 首先,我从下载了最新的python.vim,并将其放入正确的目录中。 然后我编辑了我的vimrc

syntax on
set nu
set tabstop=4
set softtabstop=4
set shiftwidth=4
"set cindent
set autoindent
set smartindent
set expandtab
set filetype=python
au BufNewFile,BufRead *.py,*.pyw setf python
现在我发现像“for”、“if”、“while”这样的关键字可以完美地自动缩进。但它对“def”、“try”、“except”不起作用。
我该怎么办?非常感谢。

我的vimrc中有这一行很久了,不知道现在是否有更好的方法。但你至少可以试一试

set cindent
autocmd FileType python setlocal foldmethod=indent smartindent shiftwidth=4 ts=4 et cinwords=if,elif,else,for,while,try,except,finally,def,class
我有

filetype plugin indent on  

您链接到的vim脚本也不会自动缩进,只会突出显示语法

您正在观察的自动缩进是vim中内置的,它是为编码C而设计的,它只识别此处描述的关键字:

这就是为什么它适用于
if
while
但不适用于
def
(C中没有
def
)。 您使用
设置cindent
将其打开

您可能需要尝试另一个类似于以下脚本的脚本:

实际上,当我向vimrc添加“filetype plugin indent on”时,我得到了正确的自动缩进。这是否意味着我链接到的脚本具有自动缩进功能,但我没有打开它?当我向vimrc添加“filetype plugin indent on”时,我得到了正确的自动缩进功能。非常感谢。