Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to prevent a "keyword" from being syntax highlited in MS Visual Studio

Tags:

c++

visual-c++

MS Visual Studio editor highlights some non-keyword identifiers as keywords in C++ files. Particularly "event" and "array" are treated as keywords. That's very annoying to me, because they are not C++ keywords. I know how to add my own keywords to the list of syntax-highlighted identifiers, but how to remove existing built-in ones? I'm aware that this may require patching some executable files. So does anyone know how to do this?

like image 937
robson3.14 Avatar asked Jul 15 '09 16:07

robson3.14


2 Answers

Thanks to article mentioned by Steve Guidi, I was able to find executable file that contains Colorizer and IScanner classes. It is named vcpkg.dll and located in /Microsoft Visual Studio 8/VC/vcpackages. (I'm using Visual C++ 2005 Express Edition, things may be different in other versions.)

The vcpkg.dll contains null-terminated UTF-16 encoded strings. I've opened it with hex editor, and searched for "array". There is only one such string in the file, so I've replaced it with "arrry". (It is important to maintain relative alphabetical order with respect to other keywords.) Then I've searched for "event", it shows up in several places, but there is only one that isn't part of some longer string, so I've replaced this one with "evvvt". After starting Visual Studio, it turned out that "array" and "event" weren't any longer highlighted, but "arrry" and "evvvt" were!

Of course this is an ugly hack, and it will void your warranty, and probably goes against Microsoft EULA, but what a relief for the eyes! Anyway, if you want to do it, be careful and remember to backup the file.

like image 54
robson3.14 Avatar answered Sep 24 '22 15:09

robson3.14


It doesn't look like a disable-syntax-coloring feature is exposed in a user-friendly way.

The only way I can think of selectively disabling syntax coloring is to create a new syntax coloring plugin for the IDE, and list all of the keywords you want colored. Microsoft gives information in this article on how to accomplish this task.

The drawback to this approach is that your IDE will now have two C++ languages and I'm not sure how it will select which plug-in to choose from once it loads a .h or .cpp file. However, this article suggests that you can override the existing C++ plug-ins by rewriting some registry keys.

like image 32
Steve Guidi Avatar answered Sep 20 '22 15:09

Steve Guidi