问题描述
我在 VScode 和 sublime 中使用 相同的字体(Consolas)。但在同一个地方看起来不一样:
这是我的 sublime 设置:
{
"auto_complete_selector": "source,text","color_scheme": "Packages/Material Theme/schemes/Material-Theme-Darker.tmTheme","font_face": "Consolas","font_size": 12,"ignored_packages":
[
],"theme": "Default.sublime-theme"
}
这是我的 vscode 设置:
"materialTheme.accent": "Blue","editor.fontFamily": "Consolas,'Courier New',monospace","editor.fontWeight": 520,"editor.codeLensFontSize": 11,"editor.fontSize": 15,"editor.formatOnType": true,"debug.console.fontFamily": "Cascadia Mono","python.showStartPage": false,"workbench.editorAssociations": [
{
"viewType": "jupyter.notebook.ipynb","filenamePattern": "*.ipynb"
}
],"explorer.confirmDelete": false,"todo-tree.tree.showScanModeButton": true,"editor.fontligatures": true,"editor.tokenColorCustomizations": {
"comments": "#7ea9eb"
我的问题是:如何让我的 vscode 字体像 sublime 一样倾斜?
解决方法
根据 VS Code documentation,您可以使用用户设置中的 editor.tokenColorCustomizations
规则自定义主题颜色:
-
打开您的
settings.json
并首先添加以下规则(将YOUR THEME NAME HERE
替换为您的颜色主题名称):"editor.tokenColorCustomizations": { "[YOUR THEME NAME HERE]": { "textMateRules": [] } }
-
打开您选择的 Python 文件。然后,使用 Ctrl+Shift+P 打开命令面板并运行“Developer: Inspect Editor Tokens and Scopes”
-
单击您希望将其设为斜体的关键字。例如,我们单击
class
关键字以查看其 TextMate 范围。复制突出显示的第一个 TextMate 范围 ID: -
回到你的
settings.json
。在textMateRules
数组中,插入一个新对象,其scope
属性是您刚刚复制的 TextMate 范围 ID。"editor.tokenColorCustomizations": { "[YOUR THEME NAME HERE]": { "textMateRules": [ { "scope": "storage.type.class.python","settings": { "fontStyle": "italic" } } ] } }
-
保存您的
settings.json
,您应该会看到class
键盘以斜体显示
注意
您可以在 textMateRules
数组中附加更多对象,使更多关键字的字体变为斜体。例如:
"editor.tokenColorCustomizations": {
"[YOUR THEME NAME HERE]": {
"textMateRules": [
{
"scope": "variable.parameter.function.language.special.self.python","settings": {
"fontStyle": "italic"
}
},{
"scope": "storage.type.class.python","settings": {
"fontStyle": "italic"
}
}
]
}
},