Change color of characters surrounding comments in VS Code

Viewed 1813

how can I change the color of the characters that come before and after a comment in vs code. Im Talking about or /* */ or # characters. I know how to change the comment color

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

but couldn’t find anything regarding the „framing“ characters.

2 Answers

You can do this rather simply. Use "Inspect TM Scopes" in the command palette to inspect those characters. It will give a different scope for each language, something like :

punctuation.definition.comment.js

for javascript comments. Now you can use that in your user settings like so:

"editor.tokenColorCustomizations": {
    "textMateRules": [

      {
        "scope": "punctuation.definition.comment.js",
        "settings": {
          "foreground": "#f00",
        }
      }
   ]
}

You will obviously have a different but similar scope for other languages.


And see the short answer added to How to change VisualStudioCode comment color with it's slashes? about possible plans to fix this in the October, 2019 release. So the punctuation would not have to be independently colored. [It is now fixed in the Insider's Build.]

You can use the following to fully define the comment colors globally. You do not have to do one for each language!

settings.json

"editor.tokenColorCustomizations": {
    "comments": "#636363",
    "textMateRules": [{
        "scope": "punctuation.definition.comment",
        "settings": {
            "foreground": "#636363",
        }
    }]
},

Notice I omitted the language, ie: .php, from the end of the scope line.

This will do both the beginning/end of the comment block, and the comment itself. I was baffled when I changed my comment colors and the /** and */ where not changed. This solved it and made the comments all one color.

Related