Auto indent doesn't work when using vim coding python

喜夏-厌秋 提交于 2019-12-03 12:50:36

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

and I have

filetype plugin indent on  

too

That vim script you linked to doesn't do any auto-indentation, only syntax highlighting.

The auto-indentation you are observing is the one that's built into vim, it is designed for coding C, and it only recognizes the keywords described here:

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

That's why it works for if and while but not def (there's no def in C). You turned it on with set cindent.

You may want to try another script like this one:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!