【问题标题】:How do I change color of comments in visual studio code?如何更改 Visual Studio 代码中注释的颜色?
【发布时间】:2017-12-24 23:43:45
【问题描述】:

我浏览了https://code.visualstudio.com/docs/getstarted/theme-color-reference,但似乎找不到更改评论颜色的设置。

我目前正在使用 Atom One 深色主题,只是想将颜色调亮一点,以便更好地阅读。

【问题讨论】:

    标签: visual-studio-code vscode-settings


    【解决方案1】:

    1.15 (July 2017)你可以从settings.json更改它 Ctrl+,

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

    1.20 (January 2018)你也可以为每个主题分别做:

    "editor.tokenColorCustomizations": {
        "[Atom One Dark]": {
            "comments": "#d4922f"
        }
    },
    

    找到合适的范围:

    开发者:检查 TM Scopes editor.action.inspectTMScopes

    选择器优先级:

    https://code.visualstudio.com/blogs/2017/02/08/syntax-highlighting-optimizations#_textmate-themes



    好的,更多示例(js):

    "editor.tokenColorCustomizations": {
        "textMateRules": [{
            "scope": "INSERT_SCOPE_HERE",
            "settings": {
                "foreground": "#ff0000"
            }
        }]
    }
    

    comment punctuation.definition.comment comment.block.documentation storage.type.class.jsdoc entity.name.type.instance.jsdoc variable.other.jsdoc

    【讨论】:

    • 背景/前景的任何可能性?
    • 有人知道评论文本前的 // 和 /* 的设置是什么吗?还有 " 之前的字符串的设置是什么?
    • 您可以尝试从答案中“找到正确的范围”链接。
    • 任何改变注释块开始和结束部分颜色的方法。 /***/ 在设置评论颜色后保持不变。中间部分正在改变颜色。
    【解决方案2】:

    转到您的设置。

    然后搜索settings.json 打开文件 然后添加这行代码:

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

    根据您的喜好更改 cmets 的颜色,方法是将鼠标悬停在颜色上并选择您想要的颜色。 然后保存更改。(Ctrl+S) 退出程序。再次打开它,您将看到更改。

    【讨论】:

    • 感谢您的视觉效果。使导航更容易。
    【解决方案3】:

    扩展答案和@Johnny Derp 的评论。您可以使用以下方法更改字体颜色和样式:

    "editor.tokenColorCustomizations": {
        "textMateRules": [
          {
            "scope": "comment",
            "settings": {
              "fontStyle": "italic",
              "foreground": "#C69650",
            }
          }
        ]
      },
    

    background不能这样改,只能改颜色和样式。截至 2018 年 6 月。


    还回答了几个 cmets 关于更改 cmets puntuation(如 //)颜色的问题 - 现在必须使用自己的 textmate 规则单独着色,可能会在 10 月份进行更改以解决该问题2019 年发布 - 目前这是一个未解决的问题,但已添加到 2019 年 10 月的里程碑中。见https://github.com/microsoft/vscode/milestone/102

    【讨论】:

      【解决方案4】:

      在 VS 代码中:1.56.2

      添加到settings.json:

      "editor.tokenColorCustomizations": {
          "textMateRules": [
            {
              "scope": [
                "comment",
                "comment.block.documentation",
                "comment.block.documentation.js",
                "comment.line.double-slash.js",
                "storage.type.class.jsdoc",
                "entity.name.type.instance.jsdoc",
                "variable.other.jsdoc",
                "punctuation.definition.comment",
                "punctuation.definition.comment.begin.documentation",
                "punctuation.definition.comment.end.documentation"
              ],
              "settings": {
                "fontStyle": "italic",
                "foreground": "#287a1d"
              }
            }
          ]
        }
      

      如果仍然缺少stoff:CTRL+SHIFT+P => Developer: Inspect Editor Tokens and Scopes 将鼠标悬停在未正确着色的部分上并将它们添加到"scope"

      你来了。 :)

      【讨论】:

      • 天哪,这已经为我解决了所有问题,我不知道这是一回事。我终于可以找到我想要编辑的所有颜色。谢谢!
      【解决方案5】:

      目前无法在设置中自定义令牌颜色:

      最突出的编辑器颜色是基于的标记颜色 关于语言语法安装。这些颜色由 颜色主题,(目前)不能在设置中自定义。

      来源:https://code.visualstudio.com/docs/getstarted/theme-color-reference

      我确实注意到,如果您进入主题文件夹,例如: C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\theme-monokai 并编辑 monokai-color-theme.json 文件,查找带有 "name": "Comment" 的行并更改它可以工作的 "foreground" 颜色。只需确保重新启动程序即可。

      【讨论】:

        【解决方案6】:

        就像马克说的,但是在"comment"之后添加"scope":

        “标点符号.definition.comment”

        给标点上色,

        例如(// in javescript | /* */ in cs | <!-- --> in html)。

        "scope": ["comment", "punctuation.definition.comment"]
        

        【讨论】:

          【解决方案7】:

          Doc、Block 和 Line 设置

          为 Doc、Block 和 Line cmets 设置不同的颜色:

          "editor.tokenColorCustomizations": {
              "[Cobalt2]": {
                  "textMateRules": [
                      {
                          "scope": [
                              "comment.block",
                              "punctuation.definition.comment.end",
                              "punctuation.definition.comment.begin"
                          ],
                          "settings": {
                              "foreground": "#85b3f8",
                              "fontStyle": "bold"
                          }
                      },
                      {
                          "scope": [
                              "comment.block.documentation",
                              "punctuation.definition.comment.begin.documentation",
                              "punctuation.definition.comment.end.documentation"
                          ],
                          "settings": {
                              "foreground": "#6bddb7",
                              "fontStyle": "bold"
                          }
                      },{
                          "scope":["comment.line", "punctuation.definition.comment"],
                          "settings": {
                              "foreground": "#FF0000",
                              "fontStyle": "bold"
                          }
                      }
                  ]
              }
          }
          

          用 C++ 测试。

          【讨论】:

            【解决方案8】:

            您可以通过简单地在 VS 代码中编辑您的设置文件并按照以下 3 个步骤来修改您的 VS 代码。

            第一步:

            第二步:

            第三步:

            【讨论】:

              【解决方案9】:

              更改 VS Code 注释颜色

              文件 --> 首选项 --> 设置

              选择“工作区设置”选项卡以仅针对该项目进行更改
              选择“用户设置”选项卡为所有项目更改它

              搜索“settings.json”并寻找“在 settings.json 中编辑”的选项

              在大括号内的某处为 cmets 插入此颜色设置:

                “editor.tokenColorCustomizations”:{
              "cmets": "#ff4"
              }

              它可能会抱怨您正在覆盖当前的颜色主题,请忽略它。

              如果已经有一个“editor.tokenColorCustomizations”部分,那么只需添加该行来指定注释颜色。

              【讨论】:

                【解决方案10】:

                在评论评论主题时,我发现 VS Code 的“更好的评论”扩展非常有用。您可以为您的 cmets 赋予各种颜色,从而根据重要性等对您的 cmets 进行分类。 默认 cmets 颜色也可以更改。 https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments
                示例:‎

                可以在用户设置或工作区设置中配置此扩展。

                【讨论】: