Vim syntax highlighting 'else:' for Python

可紊 提交于 2019-12-01 02:38:42

问题


I'm getting annoyed with the default python syntax highlighting in Vim.

It does not highlight the else: statement correctly. Vim only highlights the else statement if I have some white space between the else and the colon :, so else : works, but else: does not.

It must be easy to fix.

I'm using Vim 7.2


回答1:


I had below statement in my vimrc file. This made else: be tokenized as one word. After removing that else: syntax highlighting works just fine.

set iskeyword+=:




回答2:


It should work by default.

Look for a file that is something like this:

/usr/share/vim/vim72/syntax/python.vim

There should be a line there that looks like this:

syn keyword pythonConditional   if elif else

If not, investigate further. Does elif work?




回答3:


Note that the file in

/usr/share/vim/vim72/syntax/python.vim

is not up to date for some reason.

Get the most recent version of the syntax highlight file from http://www.vim.org/scripts/script.php?script_id=790




回答4:


This periodically pops up, and I've taken to putting this in my vimrc:

" No seriously, else: is the same as else
autocmd BufEnter,BufRead,BufNewFile *.py    set iskeyword-=:



回答5:


Enable the filetype stuff so things are setup automatically. I've python auto indenting and syntax highlighting setup for vim here: http://www.pixelbeat.org/settings/.vimrc




回答6:


In my ~/.vim/syntax/python.vim file, I have a line

syn keyword pythonConditional   else:

which solves this problem.



来源:https://stackoverflow.com/questions/1393075/vim-syntax-highlighting-else-for-python

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