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

如何在VSCode中保存终端布局,实现意外终止后恢复?

保存并恢复VSCode终端布局的实用方案

1. 内置工作区文件(最简单)

把你的项目保存为.code-workspace工作区文件:

  • 配置好需要的终端布局后,通过文件 > 将工作区另存为生成工作区文件。
  • 后续直接打开这个.code-workspace文件,VSCode会自动恢复之前的终端窗口布局(包括分栏、位置)。如果终端进程没被系统彻底终止,甚至能恢复之前的运行状态。
  • 注意:意外崩溃后部分终端进程可能被系统回收,这时候只能恢复窗口结构,进程需要重启,但省去了手动创建终端的步骤。

2. 第三方扩展(功能更全)

  • Terminal Manager:安装后,通过命令面板(Ctrl+Shift+P)执行Terminal Manager: Save Terminals就能保存当前所有终端的布局、工作目录和执行过的命令;需要恢复时执行Terminal Manager: Restore Terminals即可一键还原。
  • Multi Command:适合预设固定终端布局,在settings.json中配置自定义命令序列,比如:
    "multiCommand.commands": [
      {
        "command": "multiCommand.initTerminals",
        "sequence": [
          "workbench.action.terminal.new",
          "workbench.action.terminal.split",
          {"command": "workbench.action.terminal.sendSequence", "args": {"text": "cd src && npm run dev\n"}},
          "workbench.action.terminal.focusNext",
          {"command": "workbench.action.terminal.sendSequence", "args": {"text": "cd server && go run main.go\n"}}
        ]
      }
    ]
    
    之后在命令面板调用multiCommand.initTerminals,就能快速创建带预设命令的分栏终端。

3. 自定义任务/脚本(进阶灵活)

如果需要高度自定义,可通过tasks.json或shell脚本实现:

  • 在项目的.vscode/tasks.json中添加任务:
    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "启动所有终端",
          "type": "shell",
          "command": "",
          "args": [],
          "presentation": {
            "reveal": "always",
            "panel": "new"
          },
          "dependsOn": [
            "启动前端服务",
            "启动后端服务"
          ]
        },
        {
          "label": "启动前端服务",
          "type": "shell",
          "command": "cd src && npm run dev",
          "presentation": {
            "reveal": "never",
            "panel": "dedicated"
          }
        },
        {
          "label": "启动后端服务",
          "type": "shell",
          "command": "cd server && go run main.go",
          "presentation": {
            "reveal": "never",
            "panel": "dedicated"
          }
        }
      ]
    }
    
    按下Ctrl+Shift+B选择「启动所有终端」,就能自动打开多个终端并执行对应命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 00:58:16