如何用斜杠更改VisualStudioCode注释颜色?

时间:2018-12-11 16:51:06

标签: visual-studio-code vscode-settings

我将此代码添加到我的setting.json

"editor.tokenColorCustomizations": {
    "comments": "#00ff00"
}

但是它不会改变斜线的颜色,因为您可以看到以下屏幕截图。
它仍然是灰色的。

如何更改包含斜杠的整个注释颜色?

enter image description here

3 个答案:

答案 0 :(得分:2)

注释定义(//或其他语言的#)可以使用punctuation.definition.comment数组中的textMateRules范围进行自定义。

示例:

"editor.tokenColorCustomizations": {
  "[Material Theme Darker High Contrast]": { // optional name of a specific theme
    "textMateRules": [
      {
        "scope": "punctuation.definition.comment",
        "settings": {
          "foreground": "#00ff00"
        }
      }
    ]
  }
}

您可以在命令面板中看到所有命令Inspect TM Scopes的作用域。

答案 1 :(得分:0)

似乎可以更正注释标点colorCustomization-也就是说,像punctuation这样的//可能包含在2018年10月发行版的comment范围内。这是一个未解决的问题,但已添加到2019年10月的里程碑中,请参阅https://github.com/microsoft/vscode/milestone/102

因此注释标点不再需要单独着色。

此问题已在2019年10月25日的《内部人员》中修复,以便

"editor.tokenColorCustomizations": {
    "comments": "#00ff00"
}

将为注释正文和标点/标记着色。

答案 2 :(得分:0)

我在几个地方都找到了相同的答案,但是无论出于何种原因,它都不适用于任何Material Theme *主题。无论我做什么,JS中的//和Ruby / Shell中的第一个#都不会改变颜色。

enter image description here

要解决此问题,我必须使用Community主题的Material Theme *版本:例如"workbench.colorTheme": "Community Material Theme Darker High Contrast"

Screenshot with fix

希望这对遇到此问题的其他人很有帮助!