Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim syntax highlighting 'else:' for Python

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

like image 978
Stephan Avatar asked Sep 08 '09 09:09

Stephan


4 Answers

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+=:

like image 57
Stephan Avatar answered Sep 20 '22 04:09

Stephan


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-=:
like image 42
Mark Roberts Avatar answered Sep 20 '22 04:09

Mark Roberts


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?

like image 33
DisplacedAussie Avatar answered Sep 19 '22 04:09

DisplacedAussie


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

like image 32
Viktiglemma Avatar answered Sep 19 '22 04:09

Viktiglemma