【发布时间】:2017-10-11 13:21:04
【问题描述】:
有人可以向我解释一下如何在 VSCode 的默认主题中为 Python 自定义文档字符串颜色吗?我想通过用户设置来完成,因为希望能够保存我的配置文件。
我尝试使用 "editor.tokenColorCustomizations": {} 但它会影响所有字符串。
【问题讨论】:
标签: python colors visual-studio-code themes
有人可以向我解释一下如何在 VSCode 的默认主题中为 Python 自定义文档字符串颜色吗?我想通过用户设置来完成,因为希望能够保存我的配置文件。
我尝试使用 "editor.tokenColorCustomizations": {} 但它会影响所有字符串。
【问题讨论】:
标签: python colors visual-studio-code themes
将此添加到您的设置文件中:
<!-- 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
【讨论】:
{ "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 } }
添加到 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) 图标 (悬停以了解哪个图标)
【讨论】:
上面伦纳德的回答很完美。
仅针对 2020 年的谷歌员工,我要补充一点,命令面板中的命令:Developer: Inspect TM Scopes 似乎已更改为:Developer: Inspect Editor Tokens and Scopes。
此选项显示标准令牌类型以及 TextMate 范围。
【讨论】: