首页 > 解决方案 > 在 VSCode 中自定义“反引号”内的文本颜色

问题描述

我能找到的在 Visual Studio Code 中处理自定义着色的唯一选项是:

"editor.tokenColorCustomizations": {
    "[Atom One Dark]": {
        "comments": "#FF0000" // only 6 color-customizable
    },
    "workbench.colorCustomizations": {
        "statusBar.background": "#666666",
        "panel.background": "#555555",
        "sideBar.background": "#444444"
    },
},

有没有办法为这些类型的东西设置自定义颜色?一个用于注释,用于字符串(内部"string")。我相信使用正则表达式的其他东西应该可以做类似的事情。提前致谢。

标签: visual-studio-codeeditorsyntax-highlightingvscode-settingscolor-scheme

解决方案


搜索tokenColorCustomizationsandtextMateRules你会发现你可以做这样的事情(见colorizing with textmate):

"editor.tokenColorCustomizations": {

    "textMateRules": [
      {
            // works for a language that recognizes backticks as string templates
        "scope": "string.template",
        "settings": {
          "foreground": "#FF0000"
        }
      },
      {
       "scope": "punctuation.definition.template-expression.begin, punctuation.definition.template-expression.end",
       "settings": {
         "foreground": "#F0F"
       }
      },
    ]
}

使用Inspect TM Scopes...命令面板中的命令。所以我使用该命令在模板文字内单击并获得string.template.js.jsx范围。但这并没有改变 ${someVar} 所以我检查了那个范围并看到了 variable.other.readwrite.js.jsx额外的范围参数 - 仍在努力将这种变量与其他变量隔离开来。

编辑:如果string.template语言将反引号视为字符串模板,则应仅使用 来处理更多文件类型。

您还可以更改fontStyle设置。这里有一些关于使用TM Scopes命令的答案。


推荐阅读