vim-python / python-syntax

Python syntax highlighting for Vim
MIT License
438 stars 84 forks source link

Builtins wrongly highlighted in variable names #88

Closed skwde closed 2 years ago

skwde commented 2 years ago

When using a builtin in a variable name it is wrongly highlighted.

Just try:

some_dict_var = {}
Narthorn commented 2 years ago

One reason this might happen is if you do set iskeyword-=_ in your .vimrc. If this is the case, you can fix the highlighting by setting syntax iskeyword to the original value of iskeyword, for example:

execute 'autocmd Syntax python syn iskeyword ' . &iskeyword
set iskeyword-=_

(This needs to be an autocmd because loading a syntax will clear the value of syn iskeyword, so it needs to be run after the syntax has been loaded.)

I guess that syntax files are all meant to set their own syn iskeyword. When it is not set, it defaults to the value of iskeyword, and there doesn't seem to be a way for the user to set a default value for syn iskeyword that's independent of the value of iskeyword, or even to check if syn iskeyword has already been set by the current syntax - so you have to do this autocmd for every single syntax file that doesn't explicitly set it.

skwde commented 2 years ago

Thanks for the explanation. This seems to work.