繁体   English   中英

使用vim编码python时,自动缩进不起作用

[英]Auto indent doesn't work when using vim coding python

我想用vim编写python代码但是自动缩进有问题。 首先,我从http://www.vim.org/scripts/script.php?script_id=790下载了最新的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','除'。 我该怎么办? 非常感谢你。

我在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而设计的,它只识别此处描述的关键字:

http://vimdoc.sourceforge.net/htmldoc/options.html#%27cinwords%27

这就是为什么它适用于ifwhile而不是def (C中没有def )。 你用set cindent打开它。

您可能想尝试像这样的另一个脚本:

http://www.vim.org/scripts/script.php?script_id=974

暂无
暂无

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

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