使用Vim编码python时自动缩进不起作用 [英] Auto indent doesn't work when using vim coding python

查看:186
本文介绍了使用Vim编码python时自动缩进不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用vim编写python代码,但是自动缩进有问题. 首先,我从 http://www.vim.org/scripts/script.php下载了最新的python.vim. ?script_id = 790 并将其放置在正确的目录中. 然后我编辑了vimrc.

I want to use vim to write python code but there is a problem on auto indention. First I downloaded the latest python.vim from http://www.vim.org/scripts/script.php?script_id=790 and putted it in the correct dir. Then I edited my 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'. 我该怎么办?非常感谢.

Now I find that keywords like 'for', 'if', 'while' can autoindent perfectly. But it doesn't work on 'def', 'try', 'except'. What should I do? Thank you very much.

推荐答案

我在vimrc中已经很长时间了,不知道现在是否有更好的方法.但您至少可以尝试一下.

I have this line in my vimrc for long time, don't know if there is better way nowadays. but you could at least give it a try.

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编码python时自动缩进不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆