自动缩进不';使用vim编码python时无法工作
我想使用vim编写python代码,但在自动缩进方面存在问题。 首先,我从下载了最新的python.vim,并将其放入正确的目录中。 然后我编辑了我的vimrc自动缩进不';使用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
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”时,我得到了正确的自动缩进功能。非常感谢。