You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VS Code中启用并自定义括号对指南?

在VS Code中启用并自定义括号对指南的操作步骤

一、启用括号对指南

两种方式任选其一:

  • 界面操作:点击左下角齿轮图标进入「设置」,在搜索框输入bracket pair colorization,勾选「Editor: Bracket Pair Colorization」;同时勾选「Editor: Guides: Bracket Pairs」,这是显示括号连线指南的核心开关。
  • 配置文件操作:按Ctrl+,(Windows/Linux)或Cmd+,(Mac)打开设置面板,点击右上角「打开设置(JSON)」图标,添加以下配置:
    "editor.bracketPairColorization.enabled": true,
    "editor.guides.bracketPairs": true
    

二、自定义括号对显示效果

1. 自定义括号颜色

打开设置JSON文件,在workbench.colorCustomizations中配置不同层级的括号颜色,示例如下:

"workbench.colorCustomizations": {
  "editorBracketHighlight.foreground1": "#ff0000",
  "editorBracketHighlight.foreground2": "#00ff00",
  "editorBracketHighlight.foreground3": "#0000ff",
  // 括号连线的半透明颜色,后缀数值为透明度,越小越淡
  "editorBracketGuide.background1": "#ff000040",
  "editorBracketGuide.background2": "#00ff0040"
}

最多支持6层级的颜色配置,对应foreground1到foreground6。

2. 调整括号指南样式

根据需求添加以下配置修改连线样式或显示逻辑:

// 显示函数上下括号这类水平方向的连线
"editor.guides.bracketPairsHorizontal": true,
// 高亮当前光标所在的括号对
"editor.guides.highlightActiveBracketPair": true,
// 将连线改为虚线,默认是实线
"editor.guides.bracketPairStyle": "dashed"

3. 针对特定语言单独设置

如果只想在某类代码中生效,用语言ID包裹配置即可,比如仅给JavaScript自定义括号颜色:

"[javascript]": {
  "editor.bracketPairColorization.enabled": true,
  "workbench.colorCustomizations": {
    "editorBracketHighlight.foreground1": "#ff9800"
  }
}

内容的提问来源于stack exchange,提问作者starball

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 14:52:37