乐闻世界logo
搜索文章和话题

VS Code 主题如何定制?

2月18日 18:27

VS Code 提供丰富的主题定制选项,允许用户根据个人喜好和工作需求自定义编辑器外观,提升使用体验。

主题类型

颜色主题

影响编辑器、状态栏、活动栏等界面元素的颜色。

文件图标主题

为文件和文件夹提供不同的图标。

产品图标主题

改变 VS Code 界面中的图标样式。

安装主题

通过扩展市场

  1. 打开扩展视图 (Ctrl+Shift+X)
  2. 搜索 "theme" 或 "color theme"
  3. 选择主题并安装
  4. 点击应用主题

通过命令面板

  1. 按 Ctrl+Shift+P
  2. 输入 "Preferences: Color Theme"
  3. 选择并应用主题

自定义颜色主题

创建自定义主题

  1. 创建 .vscode 文件夹
  2. 创建 color-theme.json 文件
  3. 定义颜色规则

主题配置示例

json
{ "name": "My Custom Theme", "type": "dark", "colors": { "editor.background": "#1e1e1e", "editor.foreground": "#d4d4d4", "activityBar.background": "#333333", "statusBar.background": "#007acc" }, "tokenColors": [ { "scope": ["keyword", "storage.type"], "settings": { "foreground": "#569cd6" } }, { "scope": ["string", "constant.other.symbol"], "settings": { "foreground": "#ce9178" } } ] }

常用颜色设置

json
{ "editor.background": "#1e1e1e", "editor.foreground": "#d4d4d4", "editor.lineHighlightBackground": "#2a2d2e", "editorCursor.foreground": "#aeafad", "editor.selectionBackground": "#264f78" }

语法高亮定制

Token Colors

定义不同语法元素的颜色:

json
{ "tokenColors": [ { "name": "Comments", "scope": ["comment", "punctuation.definition.comment"], "settings": { "foreground": "#6a9955", "fontStyle": "italic" } }, { "name": "Functions", "scope": ["entity.name.function", "support.function"], "settings": { "foreground": "#dcdcaa" } } ] }

作用域选择器

  • keyword: 关键字
  • string: 字符串
  • comment: 注释
  • variable: 变量
  • function: 函数

工作区颜色定制

在 settings.json 中配置

json
{ "workbench.colorCustomizations": { "activityBar.background": "#333333", "activityBar.foreground": "#ffffff", "statusBar.background": "#007acc", "statusBar.foreground": "#ffffff", "editorGroup.background": "#1e1e1e", "sideBar.background": "#252526" } }

语言特定颜色

json
{ "[javascript]": { "editor.tokenColorCustomizations": { "textMateRules": [ { "scope": "keyword.control.flow", "settings": { "foreground": "#c586c0" } } ] } } }

字体定制

编辑器字体

json
{ "editor.fontFamily": "'Fira Code', 'Consolas', 'Courier New'", "editor.fontSize": 14, "editor.fontWeight": "400", "editor.lineHeight": 1.5 }

终端字体

json
{ "terminal.integrated.fontFamily": "'Fira Code', monospace", "terminal.integrated.fontSize": 13 }

启用连字

json
{ "editor.fontLigatures": true }

界面布局定制

活动栏位置

json
{ "workbench.activityBar.location": "top" }

状态栏可见性

json
{ "workbench.statusBar.visible": true }

面板位置

json
{ "workbench.panel.defaultLocation": "bottom" }

推荐主题

深色主题

  • One Dark Pro
  • Dracula Official
  • Material Theme
  • Nord

浅色主题

  • Light+
  • Solarized Light
  • GitHub Light Theme

高对比度主题

  • High Contrast
  • Monokai High Contrast

主题发布

发布主题扩展

  1. 创建扩展项目
  2. 定义主题配置
  3. 添加预览截图
  4. 发布到市场

package.json 配置

json
{ "contributes": { "themes": [ { "label": "My Theme", "uiTheme": "vs-dark", "path": "./themes/my-theme.json" } ] } }

注意事项

  • 选择适合长时间工作的主题,避免眼睛疲劳
  • 考虑不同环境下的主题切换(日间/夜间)
  • 测试主题在不同语言下的表现
  • 保持主题的一致性和可读性
  • 定期更新主题以获得更好的体验
标签:VSCode