How do I change color of comments in visual studio code?

后端 未结 9 2156
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 10:29

I went through https://code.visualstudio.com/docs/getstarted/theme-color-reference but can\'t seem to find the setting for changing the comment color.

I am currentl

相关标签:
9条回答
  • 2020-11-27 10:55

    Looks like the token colors cannot be customized within the settings at the moment:

    The most prominent editor colors are the token colors that are based on the language grammar installed. These colors are defined by the Color Theme and can (currently) not be customized in the settings.

    Source: https://code.visualstudio.com/docs/getstarted/theme-color-reference

    I did notice that if you go into the theme folders, for example: C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\theme-monokai and edit the monokai-color-theme.json file, look for the line with "name": "Comment" and change the "foreground" color it will work. Just make sure to restart the program.

    0 讨论(0)
  • 2020-11-27 11:00

    To expand on the answer and @Johnny Derp's comment. You can change the font color and style using:

    "editor.tokenColorCustomizations": {
        "textMateRules": [
          {
            "scope": "comment",
            "settings": {
              "fontStyle": "italic",
              "foreground": "#C69650",
            }
          }
        ]
      },
    

    background cannot be changed in this way, only the color and style. As of June, 2018.


    Also in answer to a couple of comments about changing comments puntuation (like the //) colors - which now have to be separately colored with their own textmate rule, a change may be coming to fix that in the October 2019 release - at this point it is an unresolved issue but added to the October 2019 milestone. See https://github.com/microsoft/vscode/milestone/102

    0 讨论(0)
  • 2020-11-27 11:02

    While commenting on comment subject, I found "Better Comments" extension of VS Code very useful. You can give various colors ‎to your comments and hence categorize your comments based on importance etc. ‎ Default comments color can also be changed.‎ https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments
    Example:‎

    This extension can be configured in User Settings or Workspace settings.‎

    0 讨论(0)
  • 2020-11-27 11:04

    Go to your settings.

    Then search for settings.json open the file and then add this line of code:

    "editor.tokenColorCustomizations": {
    
            "comments": "#229977"
        },
    

    change the color of comments,based on your liking by hovering over the color and choosing your desired color. Then save the changes.(Ctrl+S) Exit the program. open it again, you will see the changes.

    0 讨论(0)
  • 2020-11-27 11:08

    Doc, Block, and Line settings

    To have differnet colors for Doc, Block, and Line comments:

    "editor.tokenColorCustomizations": {
        "[Cobalt2]": {
            "textMateRules": [
                {
                    "scope": [
                        "comment.block",
                        "punctuation.definition.comment.end",
                        "punctuation.definition.comment.begin"
                    ],
                    "settings": {
                        "foreground": "#85b3f8",
                        "fontStyle": "bold"
                    }
                },
                {
                    "scope": [
                        "comment.block.documentation",
                        "punctuation.definition.comment.begin.documentation",
                        "punctuation.definition.comment.end.documentation"
                    ],
                    "settings": {
                        "foreground": "#6bddb7",
                        "fontStyle": "bold"
                    }
                },{
                    "scope":["comment.line", "punctuation.definition.comment"],
                    "settings": {
                        "foreground": "#FF0000",
                        "fontStyle": "bold"
                    }
                }
            ]
        }
    }
    

    Tested with C++.

    0 讨论(0)
  • 2020-11-27 11:13

    From 1.15 (July 2017) you can change it from settings.json Ctrl+,

    "editor.tokenColorCustomizations": {
        "comments": "#d4922f"
    },
    

    From 1.20 (January 2018) you can also do it for each theme separately:

    "editor.tokenColorCustomizations": {
        "[Atom One Dark]": {
            "comments": "#d4922f"
        }
    },
    

    Finding the right scope:

    Developer: Inspect TM Scopes editor.action.inspectTMScopes

    Selector priority:

    https://code.visualstudio.com/blogs/2017/02/08/syntax-highlighting-optimizations#_textmate-themes



    Ok, more examples (for js):

    "editor.tokenColorCustomizations": {
        "textMateRules": [{
            "scope": "INSERT_SCOPE_HERE",
            "settings": {
                "foreground": "#ff0000"
            }
        }]
    }
    

    comment punctuation.definition.comment comment.block.documentation storage.type.class.jsdoc entity.name.type.instance.jsdoc variable.other.jsdoc

    0 讨论(0)
提交回复
热议问题