8

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

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.

4

2 に答える 2

8

私はこの行を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  

それも

于 2013-05-15T16:52:44.200 に答える
2

リンク先のvimスクリプトは、自動インデントを行わず、構文の強調表示のみを行います。

あなたが観察している自動インデントはvimに組み込まれているもので、Cのコーディング用に設計されており、ここで説明されているキーワードのみを認識します:

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

そのため、and では機能しますifが、そうではありwhileませんdef( defC にはありません)。でオンにしましたset cindent

次のような別のスクリプトを試してみてください。

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

于 2013-05-15T17:07:01.853 に答える