Michael Kristofik
Michael Kristofik

Reputation: 35178

Turn off vim syntax highlighting inside C++ comments

I recently downloaded vim 8.0. I don't know if I messed something up or a default changed, but in this code...

int foo()
{
    // This is a comment containing a "string" and the number 5.
    return 42;
}

...the "string" and 5 are in a different color. It's the same color as when they appear in normal code. I've never seen that before. How can I turn it off?

Upvotes: 20

Views: 2183

Answers (2)

SergeyA
SergeyA

Reputation: 62553

Well, I understand the self-answering, but I strongly suggest for anybody being serious about using Vim as a C++ coding tool to look into vim color_coded plugin. There is no way one can achieve satisfactory colorizing with simple refgexp-based scheme. While not without the issues, this plugin (in my view) is as closest as it gets to doing proper colorizing in Vim.

Upvotes: 3

Michael Kristofik
Michael Kristofik

Reputation: 35178

This was unusually hard to search for, but the answer is in vim's help files. It's a feature of the syntax highlighting for C and C++ code that ships with vim. From :h ft-c-syntax:

A few things in C highlighting are optional. To enable them assign any value to the respective variable. Example:
:let c_comment_strings = 1
To disable them use ":unlet". Example:
:unlet c_comment_strings

The c_comment_strings variable controls the highlighting of strings, characters, and numbers inside of comments. It must have been enabled somewhere in my setup. If I :unlet it, comments are all highlighted in one color again.

Upvotes: 20

Related Questions