如何在VS Code中为C#的接口、using及变量/属性设置不同颜色?
解决VS Code中C#语法高亮自定义问题
要在VS Code里给C#的接口、using语句、局部变量/类属性设置不同高亮颜色,需通过自定义settings.json的语法高亮规则实现,步骤如下:
- 进入设置编辑模式:按下
Ctrl+,(Windows/Linux)或Cmd+,(Mac)打开设置面板,点击右上角的{}图标,进入settings.json直接编辑。 - 添加自定义高亮规则:在配置中插入
editor.tokenColorCustomizations节点,针对不同元素设置颜色。示例配置如下:"editor.tokenColorCustomizations": { "textMateRules": [ // 自定义using语句颜色 { "scope": "keyword.control.using.cs", "settings": { "foreground": "#0066cc" } }, // 自定义接口颜色 { "scope": "entity.name.type.interface.cs", "settings": { "foreground": "#7744aa" } }, // 自定义局部变量颜色 { "scope": "variable.other.local.cs", "settings": { "foreground": "#ff6600" } }, // 自定义类属性颜色 { "scope": "variable.other.property.cs", "settings": { "foreground": "#009900" } } ] } - 获取准确的元素Scope值:如果不清楚目标元素对应的Scope,按下
Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(Mac),执行Developer: Inspect Editor Tokens and Scopes命令,鼠标悬停在要自定义的代码元素上,就能查看对应的Scope名称,替换到上述配置中即可。
当前配色方案:
期望达到的效果:
参考的修改后设置界面:
内容的提问来源于stack exchange,提问作者Soerx
相关产品推荐
相关产品推荐

