首页 > 解决方案 > 使用 settings.json 在 VSCODE 中设置集成终端名称

问题描述

有一些与重命名或设置终端配置文件相关的问题:

但是如果你想通过每个文件夹的 settings.json 来定义它,你会怎么做呢?

标签: vscode-settings

解决方案


答案是只能为工作区做。

Workspace.code-workspace 例如:

{
    "settings": {
        "powershell.powerShellDefaultVersion": "PowerShell (x64)",
        "python.envFile": "${workspaceFolder}/.venv",
        "terminal.integrated.profiles.windows": {
            "myprofilename": {
                "source": "PowerShell",
                "overrideName": true,
                "icon": "terminal-powershell"
            }
        }
    }
}

这将创建myprofilename作为新终端选项的选择。

但是,如果要在多根工作区中设置默认值,请在文件夹级别:

例如:somefolder_in_workspace/.vscode/settings.json:

{
  "terminal.integrated.defaultProfile.windows": "myprofilename"
}

如果您将鼠标悬停,您会看到该行显示为灰色并显示一条消息:This setting cannot be applied in this workspace. It will be applied when you open the containing workspace folder directly.

这是文档解释行为的方式:

为避免设置冲突,使用多根工作区时仅应用资源(文件、文件夹)设置。影响整个编辑器的设置(例如 UI 布局)将被忽略。例如,两个项目不能同时设置缩放级别。

因此,对于多根工作区中的文件夹,答案是否定的,但是如果您想要工作区终端的名称,则答案是肯定的


推荐阅读