如何在 VS Code 中为多个主题自定义 textMateRules?

cat*_*yes 8 visual-studio-code vscode-settings

VS Code 中,我想textMateRules为多个主题自定义一些相同的内容。例如,对于Atom One DarkDefault Dark+但不影响任何其他主题,我想将keywords设为斜体。我可以通过为每个主题分别复制相同的设置两次来实现这一点,如下所示

  "editor.tokenColorCustomizations": {
    "[Atom One Dark]": {
      "textMateRules": [
        {
          "scope": [ "keyword" ],
          "settings": { "fontStyle": "italic" }
        }
      ]
    },
    "[Default Dark+]": {
      "textMateRules": [
        {
          "scope": [ "keyword" ],
          "settings": { "fontStyle": "italic" }
        }
      ]
    }
  }
Run Code Online (Sandbox Code Playgroud)

我如何只需要为两者设置一次,而无需重复规则,尤其是如果多个主题有很多相同的规则?类似于下面的东西(但它不起作用

  "editor.tokenColorCustomizations": {
    "[Atom One Dark] [Default Dark+]": {
      "textMateRules": [
        {
          "scope": [ "keyword" ],
          "settings": { "fontStyle": "italic" }
        }
      ]
    }
  }
Run Code Online (Sandbox Code Playgroud)

Mr.*_*uvo 10

这个 Github 页面

\n\n

首先将此代码复制到用户设置。

\n\n
"editor.tokenColorCustomizations": {\n  "textMateRules": [\n    {\n      "scope": [\n        //following will be in italic (=FlottFlott)\n        "comment",\n        "entity.name.type.class", //class names\n        "keyword", //import, export, return\xe2\x80\xa6\n        "constant", //String, Number, Boolean\xe2\x80\xa6, this, super\n        "storage.modifier", //static keyword\n        "storage.type.class.js", //class keyword\n      ],\n      "settings": {\n        "fontStyle": "italic"\n      }\n    },\n    {\n      "scope": [\n        //following will be excluded from italics (VSCode has some defaults for italics)\n        "invalid",\n        "keyword.operator",\n        "constant.numeric.css",\n        "keyword.other.unit.px.css",\n        "constant.numeric.decimal.js",\n        "constant.numeric.json"\n      ],\n      "settings": {\n        "fontStyle": ""\n      }\n    }\n  ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

现在仔细观察,在 textMateRules 中您必须定义一个范围。\n在作用域数组中,你必须提到要修改哪些选项,然后,在同一作用域的设置数组中你可以添加你的样式,例如,你想添加 fontStyle italic。\n像这样。

\n\n
"editor.tokenColorCustomizations": {\n  "textMateRules": [\n    {\n      "scope": [\n        //following will be in italic (=FlottFlott)\n        "comment",\n        "entity.name.type.class", //class names\n        "keyword", //import, export, return\xe2\x80\xa6\n        "constant", //String, Number, Boolean\xe2\x80\xa6, this, super\n        "storage.modifier", //static keyword\n        "storage.type.class.js", //class keyword\n      ],\n      "settings": {\n        "fontStyle": "italic"\n      }\n    }\n  ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n


小智 4

microsoft/vscode#103694如果获得足够的支持,微软将添加此功能。除非您自定义每个主题,否则您想要的行为是不可能的。

{
  "editor.tokenColorCustomizations": {
    "textMateRules": [
      {
        "scope": [ "keyword" ],
        "settings": { "fontStyle": "italic" }
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)