Every time I have a '0' character in a #define preprocessor directive in C, I get a change of color. Neither the font nor color scheme have influence on it. It is starting to annoy me. Does anyone know how to solve it?

Color change

Reproducible on Vim 7.4 with a .vimrc containing only syntax on.


That looks like issue 281 and should be fixed with newer versions of Vim 7.4

  • Here I've written a perfectly good troubleshooting answer, and you come and sideline me with a simple issue reference ;-) +1 (Though, since you patched it, would you consider adding the relevant part of the patch to your answer for those who will not or cannot easily build/acquire a newer version of vim?)
    – jjaderberg
    Jul 29 '15 at 20:06
  • I am neither reponsible for the bug nor the fix. I just remembered the issue. But the easiest fix is get a newer Vim, because it will contain updated runtime files. The second best option is to manually download the file from github/googlecode/ftp.vim.org and put it into your ~/.vim/syntax/ directory. This has the disadvantage, that you don't get updated syntax files, once you update your vim later. Jul 30 '15 at 18:57
  • My bad, I saw that you closed the issue with reference to a revision (at least I think that was you). I assumed you submitted the revision as well. In general I think an explanation to go with the link would enhance understanding, but since the question is put on hold as duplicate it probably doesn't matter.
    – jjaderberg
    Aug 1 '15 at 9:06

I don't know why that happens but you can find out where it happens by moving the cursor to the culprit '0' and issuing the following command

:execute "verbose highlight ".synIDattr(synID(line("."),col("."),1),"name")
  1. excecute allows you to build a string and execute it as a command
  2. verbose followed by some setting will let you know where that setting was last set
  3. highlight is usually used to set highlighting for a syntax item but, like many other settings, if you execute it without any highlighting instructions for the item, it will instead tell you about what instructions are already set
  4. synIDattr() will for some syntax item retrieve some attribute
  5. synID() will get the ID of the syntax item at some line,column position in your buffer
  6. line(".") will get the line which the cursor is on
  7. col(".") will get the column which the cursor is on
  8. 1 this last argument to synID() has to do with transparency when syntax items overlap-we want the effective syntax item (see :help synID())
  9. "name" this last argument to synIDattr() is which attribute to get

So, the command will "execute verbose info on highlight setting for the syntax item under the cursor," which will tell you from which file the syntax rule that annoys you is set. It won't fix it, but it'll tell you where to look.

Look at :help {x} for any of these commands/functions (i.e., not the last two) for more information.


In the file /usr/share/vim/vim74/syntax/c.vim, I changed line 466:

hi def link cCppOut        Comment


hi def link cCppOut        Macro

and everything looks fine now. I got no idea why there are some c++ highlights in c.vim.

  • "I got no idea why there are some c++ highlights in c.vim" -> C and C++ share a lot of syntax; at some point someone decided that putting them in the same syntax file was a good idea (cpp.vim sources c.vim) ... There's something to be said for that ... Jul 29 '15 at 21:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.