如何在VS Code中修改Python的global关键字颜色?
修改VS Code中Python global关键字的颜色
要单独修改Python里global关键字的颜色,你需要在settings.json的textMateRules中添加一条针对其专属作用域的规则:
- 打开VS Code的设置JSON文件(快捷键
Ctrl+,打开设置面板后,点击右上角的打开设置(JSON)图标) - 在
editor.tokenColorCustomizations的textMateRules数组中插入以下规则:
{ "scope": "keyword.control.global.python", "settings": { "foreground": "#你的颜色码" } }
- 替换
#你的颜色码为你想要的颜色(比如#ff0000表示红色)
修改后的完整editor.tokenColorCustomizations配置示例:
{ "editor.tokenColorCustomizations": { "comments": "#00af0c", "strings": "#c7884a", "variables": "#91e2ff", "functions": "#fff07a", "keywords": "#d981ff", "types": "#ff73d3", "numbers": "#beffac", "textMateRules": [ { "scope": "keyword.operator", "settings": { "foreground": "#786831" } }, { "scope": [ "source.python", "punctuation.definition.variable.python" ], "settings": { "foreground": "#ffcaca" } }, { "scope": "keyword.control.global.python", "settings": { "foreground": "#ff0000" } } ] } }
说明
global关键字对应的TextMate作用域是keyword.control.global.python,这个作用域比通用的keywords更具体,优先级更高,能单独覆盖它的颜色设置,解决你之前尝试其他作用域无效的问题。
内容的提问来源于stack exchange,提问作者Hollo
相关产品推荐
相关产品推荐

