【问题标题】:How to customize docstring color for Python in VSCode's default theme?如何在 VSCode 的默认主题中为 Python 自定义文档字符串颜色?
【发布时间】:2017-10-11 13:21:04
【问题描述】:

有人可以向我解释一下如何在 VSCode 的默认主题中为 Python 自定义文档字符串颜色吗?我想通过用户设置来完成,因为希望能够保存我的配置文件。

我尝试使用 "editor.tokenColorCustomizations": {} 但它会影响所有字符串。

【问题讨论】:

    标签: python colors visual-studio-code themes


    【解决方案1】:

    将此添加到您的设置文件中:

    <!-- language: json -->
    "editor.tokenColorCustomizations": {
            "textMateRules": [
                {
                    "scope":"string.quoted.docstring.multi.python",
                    "settings": {
                        "foreground": "#69676c" //change to your preference
                    }
                }
            ]
        }
    

    附加信息: 要找出其他元素的范围,请使用命令 Developer: Inspect TM Scopes ,如此处所述 https://github.com/Microsoft/vscode/pull/29393

    更多细节: https://code.visualstudio.com/docs/getstarted/themes#_customize-a-color-theme

    【讨论】:

    • 我有一个后续问题:如何仅更改三重撇号文档字符串的颜色并为三重引号文档字符串保持正常字符串颜色?
    • @LordWolfenstein 您的意思是将撇号的颜色与文档字符串的内容分开设置吗?如果是这样,请添加:{ "scope": [ "string.quoted.docstring.multi.python punctuation.definition.string.begin.python", "string.quoted.docstring.multi.python punctuation.definition.string.end.python" ], "settings": { "foreground": "#ff0909" //change to your preference } }
    【解决方案2】:

    添加到 Leonard 的答案中,如果您也想更改三引号和转义符,请使用以下内容:

        "editor.tokenColorCustomizations": {
            "textMateRules": [
                {           
                    "scope": [
                        "string.quoted.docstring.multi.python",
                        "string.quoted.docstring.multi.python punctuation.definition.string.begin.python",
                        "string.quoted.docstring.multi.python punctuation.definition.string.end.python",
                        "string.quoted.docstring.multi.python constant.character.escape.python"
                    ],          
                    "settings": {
                        "foreground": "#aab5da" //change to your preference
                    }       
                }
            ]
        },
    

    另外,我很难找到 json 格式的用户设置文件。您可以通过以下方式找到:

    CTRL + SHIFT + P > 用户设置 > 在打开的选项卡级别最右侧 > 打开设置 (JSON) 图标 (悬停以了解哪个图标)

    【讨论】:

    • 哇,谢谢。这就是我一直在寻找的。在 mac big sur 上工作。
    【解决方案3】:

    上面伦纳德的回答很完美。

    仅针对 2020 年的谷歌员工,我要补充一点,命令面板中的命令:Developer: Inspect TM Scopes 似乎已更改为:Developer: Inspect Editor Tokens and Scopes

    此选项显示标准令牌类型以及 TextMate 范围。

    【讨论】:

      猜你喜欢
      • 2012-03-24
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多