VS Code, changing color theme for variables

拈花ヽ惹草 提交于 2020-06-27 13:05:03

问题


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.


回答1:


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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/54954433/vs-code-changing-color-theme-for-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!