【问题标题】:Is there a way to italicize comments in Visual Studio Code?有没有办法让 Visual Studio Code 中的注释变成斜体?
【发布时间】:2017-09-25 05:58:01
【问题描述】:

我使用的是 Visual Studio Code 1.11.2 版。我需要能够在任何语言文件中看到斜体 cmets,或者至少是 JavaScript、Python、C 和 C++。是否有一个通用设置,或者我目前可以通过编程方式实现它吗?

【问题讨论】:

    标签: visual-studio-code vscode-settings


    【解决方案1】:

    感谢维克多为我指明了正确的方向。把它放在我的设置文件(Visual Studio Code 1.42.1)中就可以了:

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

    您可以通过按ctrl/cmd + shift + p 并查找Developer: Inspect Editor Tokens and Scopes 来查看选择器范围。

    您可以通过提供数组将设置应用于多个范围:

    "editor.tokenColorCustomizations": {
      "textMateRules": [
        {
          "name": "Comment",
          "scope": [
            "comment",
            "comment.block",
            "comment.block.documentation",
            "comment.line",
            "comment.line.double-slash",
            "punctuation.definition.comment",
          ],
          "settings": {
            "fontStyle": "italic",
            // "fontStyle": "italic underline",
            // "fontStyle": "italic bold underline",
          }
        },
      ]
    },
    

    相关:How do I get Visual Studio Code to display italic fonts in formatted code?

    【讨论】:

    • 这在任何主题中都更容易操作和工作,谢谢。
    • 喜欢这个!非常感谢!
    【解决方案2】:

    是的,有办法做到这一点。

    此答案适用于 Microsoft Windows(版本 10.0.14393)和 Visual Studio Code 1.14.2。

    如果您使用的是来自 Extension MarketPlace 的已安装主题,则它们的文件位于 C:\Users\<YourUsername>\.vscode\extensions\

    假设您正在使用 Kal.theme-glacier。主题文件是这样的:

    C:\Users\<YourUsername>\.vscode\extensions\Kal.theme-glacier-0.0.1\themes\glacier.tmTheme

    在任何文本编辑器中编辑文件(推荐使用 Notepad++) 编辑主题文件时不应运行 Visual Studio Code,否则您可能需要重新启动 Visual Studio Code。

    找到密钥名称Comment 并将FontStyle 更改为italic。最后的代码块应该是这样的:

    <dict>
        <key>name</key>
        <string>Comment</string>
        <key>scope</key>
        <string>comment</string>
        <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string>italic</string>
                <key>foreground</key>
                <string>#515c68</string>
            </dict>
    </dict>
    

    如果您使用的是默认主题(不是从 Extension MarketPlace 安装的),那么位置在这里:

    C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\theme-&lt;name&gt;.

    假设您正在使用 Light+(默认灯光)主题。

    首先要查看的文件是 C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\theme-defaults\themes\light_plus.json

    您会发现这里没有Comment 键,但您会注意到"include": "./light_vs.json" 然后这是您要编辑的实际文件。 C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\theme-defaults\themes\light_vs.json中的最后一个块应该是这样的:

    {
        "scope": "comment",
        "settings": {
            "foreground": "#009000",
            "fontStyle": "italic"
        }
    },
    

    【讨论】:

    • Edit the file in any text editor (Notepad++ recommended) ... or you may need to restart VS-Code 好吧,我想我可以做到。
    【解决方案3】:

    更完整的答案发布在 Visual Studio Code GitHub 问题跟踪器上: Disable Italic Option Feature Request #32579 (Themes)

    例如:

    punctuation.definition.comment 在创建 cmets 的字符上禁用斜体(例如: // 和其他)。

    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": [
                    "comment",
                    "punctuation.definition.comment",
                    "variable.language"
                ],
                "settings": {
                    "fontStyle": ""
                }
            }
        ]
    }
    

    【讨论】:

      【解决方案4】:

      您可以查看Optimizations in Syntax Highlighting

      它没有提到 cmets 是一个合格的 Visual Studio Code 主题范围。

      【讨论】:

      • 投了反对票,因为这篇文章是一篇技术文章,解释了如何呈现主题,而不是如何设置它们。
      猜你喜欢
      • 2016-03-17
      • 2018-02-07
      • 2015-07-27
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多