首页 > 解决方案 > 在 VS 代码中分别更改注释和阻止注释颜色

问题描述

我试图找出如何为单行注释指定一种颜色,为块注释(多行)指定另一种颜色。

以下适用于将所有评论设置为某种颜色:

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

有没有办法单独指定它们?例如"blockComment" : "#00FF00", "commentLine" : "#FF00222"

标签: visual-studio-codevscode-settings

解决方案


用于"textMateRules"设置范围设置,"comment.block"并可"comment.line"单独设置颜色。

"editor.tokenColorCustomizations": {
    "textMateRules": [{
        "scope": "comment.block",
        "settings": {
            "foreground": "#0000"
        }
    },
    {
        "scope": "comment.line",
        "settings": {
            "foreground": "#0000FF"
        }
    }],
}

Javascript

要更改标点符号"punctuation.definition.comment.js"(js):

"editor.tokenColorCustomizations": {
    "textMateRules": [{
        "scope": "comment.line, punctuation.definition.comment.js",
        "settings": {
            "foreground": "#00FF00"
        }
    }]
}

在此处输入图像描述


推荐阅读