6

in VS Code does anyone know how to change the color theme for variable names for C++. I can change the colors for functions, comments, keywords, but I can't get variables to work. Any help would be great Thanks.

mellis
  • 85
  • 1
  • 2
  • 6
  • 1
    Check out Mark's answer regarding textMateRules and inspecting scope here: https://stackoverflow.com/a/47274837/10209883. It might help you. – Alex Myers Mar 02 '19 at 05:16

3 Answers3

5

This has changed since the original answer was posted and it is now outdated. As @alex-myers mentioned in the comments, you can use TextMate to target intellisense tokens.

For example:

"editor.tokenColorCustomizations": {
    "[Visual Studio Dark]": {
        "textMateRules": [
            {
                "scope": "variable.other.local",
                "settings": {
                    "foreground": "#FF0000",
                }
            }
        ]
    }
}

See: https://code.visualstudio.com/docs/cpp/colorization-cpp

TheBat
  • 1,006
  • 7
  • 25
2

UPDATE: this is now possible with the C++ extension. Upvote @TheBat's answer since he originally posted the update. The scope is variable.other.local and his answer shows what to add to your settings file.

NOTE: the answer below is still accurate if you do not have the extension

I'm the maintainer of the VS Code C++ Syntax, and sadly there is not yet a way to change the color of all C++ variables, the Python syntax is the same way. You can change the color of source.cpp which will change the default color, and you can change the color of some existing variables with variable and variable.parameter, but this will still not affect many of the untagged variables.

We're working on changing this, but it is going to take quite awhile. For general scope names, look at https://macromates.com/manual/en/language_grammars#naming-conventions

Jeff Hykin
  • 1,846
  • 16
  • 25
-1

You can edit the corresponding theme *.json file. For example, if you are using the Dark+ (default dark) theme, you can find the theme json file at extensions/theme-defaults/themes/dark_plus.json. In this file we find the following text mate theme rule:

{
    "name": "Variable and parameter name",
    "scope": [
        "variable",
        "meta.definition.variable.name",
        "support.variable",
        "entity.name.variable"
    ],
    "settings": {
        "foreground": "#9CDCFE"
    }
}

Please note that some themes do not define styling for the variable scope so you would have to add your own (like the above snippet). Also not all styles of variable naming are defined in the c++ grammar file. For more details on how to add your specific naming style grammar you can see this answer.

pooya13
  • 2,060
  • 2
  • 23
  • 29