VSCode终端背景色必须手动在settings.json中配置terminal.integrated.background,无法通过UI设置;需配合terminal.foreground及ansi颜色、规避PowerShell劫持、注意opacity特性。

terminal.integrated.background 必须手动写进 settings.json
VSCode 终端背景色不会随 UI 主题自动变,terminal.integrated.background 是唯一生效的配置项,且不能通过图形界面设置。点开设置搜“terminal background”,UI 里显示的选项全是只读或无效占位符——它只是展示当前值,不提供编辑入口。
- 打开命令面板
Ctrl+Shift+P(Win/Linux)或Cmd+Shift+P(macOS),输入Preferences: Open Settings (JSON) - 在
"workbench.colorCustomizations"对象里加一行:"terminal.integrated.background": "#0d0d0d" - 如果该对象不存在,就新建一个:
"workbench.colorCustomizations": {"terminal.integrated.background": "#0d0d0d"} - 保存后,已打开的终端不会刷新,必须关闭再用
Ctrl+Shift+`新建一个才生效
terminal.integrated.backgroundOpacity 不是万能透明开关
terminal.integrated.backgroundOpacity 控制的是叠加层透明度,不是背景本身带 alpha。它先画纯色背景,再盖一层半透蒙版,所以和 rgba() 行为完全不同——你设 "#000000" + 0.8,实际看到的是黑底叠灰雾,不是深灰底。
- 数值建议在
0.85~0.92之间:低于0.7容易透出编辑器背景,文字边缘发虚;高于0.95几乎看不出变化 - Windows 下 ConPTY 渲染对 opacity 敏感,若出现闪烁或毛边,直接删掉这一行,改用更深的纯色(比如
#121212)更稳 - macOS 和 Linux(Wayland)效果最准,X11 可能略发灰,别强求一致
PowerShell 在 Windows 上会偷偷覆盖 terminal.integrated.background
Windows 用户常遇到:settings.json 明明写了深色,新开终端还是灰白底。大概率是 PowerShell 自身配置劫持了渲染——它读取 $PROFILE 里的 $Host.UI.RawUI.BackgroundColor,并强行覆盖 VSCode 设置。
- 在终端里运行:
echo $Host.UI.RawUI.BackgroundColor,如果返回值不是Black,就是它干的 - 临时修复:在
$PROFILE文件里删掉或注释掉类似$Host.UI.RawUI.BackgroundColor = "Gray"的行 - 永久规避:把
terminal.integrated.defaultProfile.windows改成pwsh或cmd,避开 PowerShell 启动逻辑
terminal.foreground 和 ansi 颜色必须配套调
只改背景不调文字色,大概率糊成一片。VSCode 终端默认用 terminal.foreground 控制普通文本,而 terminal.ansiWhite 等只影响显式 ANSI 转义序列(比如 \x1b[37m),zsh 提示符、git status 输出等多数走前者。
- 推荐组合:
"terminal.foreground": "#e0e0e0"(比纯白柔和)、"terminal.ansiBlack": "#222"(基础黑,常被用作普通文本底色) - 如果用了 oh-my-zsh 或 starship,提示符颜色异常,要同步检查
terminal.ansiBrightBlue、terminal.ansiGreen等对应项,插件常硬编码 ANSI 色号 - 别依赖
terminal.ansiWhite显示常规文字——它只管\x1b[37m,不管 shell 默认输出
terminal.integrated.background、Windows 下 PowerShell 的 $Host.UI.RawUI.BackgroundColor、配套的 terminal.foreground 值、以及是否误开了终端增强类插件——漏掉任何一个,都可能前功尽弃。


















