如何更改 Visual Studio 代码中的集成终端

How to change the integrated terminal in Visual Studio code

我想将集成终端更改为 CMDER 我在 Windows 8.1 上使用 VS Code。

我检查了文档和首选项文件,但我很困惑 要更改哪一行。


外部终端

// Customizes which terminal to run on Windows.
"terminal.external.windowsExec": "%COMSPEC%",

// Customizes which terminal application to run on OS X.
"terminal.external.osxExec": "Terminal.app",

// Customizes which terminal to run on Linux.
"terminal.external.linuxExec": "xterm",

综合终端

// The path of the shell that the terminal uses on Linux.
"terminal.integrated.shell.linux": "sh",

// The command line arguments to use when on the Linux terminal.
"terminal.integrated.shellArgs.linux": [],

// The path of the shell that the terminal uses on OS X.
"terminal.integrated.shell.osx": "sh",

// The command line arguments to use when on the OS X terminal.
"terminal.integrated.shellArgs.osx": [],

// The path of the shell that the terminal uses on Windows. When using shells shipped with Windows (cmd, PowerShell or Bash on Ubuntu), prefer C:\Windows\sysnative over C:\Windows\System32 to use the 64-bit versions.
"terminal.integrated.shell.windows": "C:\Windows\system32\cmd.exe",

// The command line arguments to use when on the Windows terminal.
"terminal.integrated.shellArgs.windows": [],

// Controls the font family of the terminal, this defaults to editor.fontFamily's value.
"terminal.integrated.fontFamily": "",

// Controls whether font ligatures are enabled in the terminal.
"terminal.integrated.fontLigatures": false,

// Controls the font size in pixels of the terminal, this defaults to editor.fontSize's value.
"terminal.integrated.fontSize": 0,

// Controls the line height of the terminal, this number is multipled by the terminal font size to get the actual line-height in pixels.
"terminal.integrated.lineHeight": 1.2,

// Controls whether the terminal cursor blinks.
"terminal.integrated.cursorBlinking": false,

// Controls whether locale variables are set at startup of the terminal, this defaults to true on OS X, false on other platforms.
"terminal.integrated.setLocaleVariables": false,

// A set of command IDs whose keybindings will not be sent to the shell and instead always be handled by Code. This allows the use of keybindings that would normally be consumed by the shell to act the same as when the terminal is not focused, for example ctrl+p to launch Quick Open.
"terminal.integrated.commandsToSkipShell": [
    "editor.action.toggleTabFocusMode",
    "workbench.action.debug.continue",
    "workbench.action.debug.restart",
    "workbench.action.debug.run",
    "workbench.action.debug.start",
    "workbench.action.debug.stop",
    "workbench.action.quickOpen",
    "workbench.action.showCommands",
    "workbench.action.terminal.clear",
    "workbench.action.terminal.copySelection",
    "workbench.action.terminal.focus",
    "workbench.action.terminal.focusNext",
    "workbench.action.terminal.focusPrevious",
    "workbench.action.terminal.kill",
    "workbench.action.terminal.new",
    "workbench.action.terminal.paste",
    "workbench.action.terminal.runSelectedText",
    "workbench.action.terminal.scrollDown",
    "workbench.action.terminal.scrollDownPage",
    "workbench.action.terminal.scrollToBottom",
    "workbench.action.terminal.scrollToTop",
    "workbench.action.terminal.scrollUp",
    "workbench.action.terminal.scrollUpPage",
    "workbench.action.terminal.toggleTerminal"
],

要更改 Windows 上的集成终端,您只需更改 terminal.integrated.shell.windows 行:

  1. 打开 VS 用户设置(首选项 > 用户设置)。这将打开两个并排文档。
  2. 将新的 "terminal.integrated.shell.windows": "C:\Bin\Cmder\Cmder.exe" 设置添加到右侧的用户设置文档(如果尚不存在)。这样您就不会直接编辑默认设置,而是添加它。
  3. 保存用户设置文件。

默认情况下,您可以使用 Ctrl+backtick 键访问它。

可以在 VS Code 中使用它并集成 Cmder 终端(不弹出)。

这样做:

  1. 创建一个指向你的 Cmder 的环境变量 "CMDER_ROOT" 目录。
  2. 在 VS Code 的(首选项 > 用户设置)中添加以下设置:

"terminal.integrated.shell.windows": "cmd.exe"

"terminal.integrated.shellArgs.windows": ["/k", "%CMDER_ROOT%\vendor\init.bat"]

我知道来晚了,但您只需键入 Ctrl+Shift+P[= 即可快速完成19=] 然后键入“default” - 它会显示一个选项:

Terminal: Select Default Shell

然后它将显示所有可用的终端。

OP 的终端 Cmder 有一个 integration guide, also hinted in the VS Code docs

如果你想使用 VS Code tasks 并在切换到 Cmder 后遇到问题,@khernand 的答案有更新。将此复制到您的 settings.json 文件中:

"terminal.integrated.shell.windows": "cmd.exe",

"terminal.integrated.env.windows": {
  "CMDER_ROOT": "[cmder_root]" // replace [cmder_root] with your cmder path
},
"terminal.integrated.shellArgs.windows": [
  "/k",
  "%CMDER_ROOT%\vendor\bin\vscode_init.cmd" // <-- this is the relevant change
  // OLD: "%CMDER_ROOT%\vendor\init.bat"
],

调用的文件将打开 Cmder 作为集成终端并切换到 cmd 以执行任务 - 查看源代码 here。所以你可以省略在 tasks.json 中配置一个单独的终端来使任务工作。

从 VS Code 1.38 开始,还有 "terminal.integrated.automationShell.windows" 设置,它允许您为全局任务设置终端并避免 Cmder.

问题
"terminal.integrated.automationShell.windows": "cmd.exe"

来自Official Docs

Correctly configuring your shell on Windows is a matter of locating the right executable and updating the setting. Below is a list of common shell executables and their default locations.

There is also the convenience command Select Default Shell that can be accessed through the command palette which can detect and set this for you.

所以你可以使用ctrl+shift+p打开命令面板,使用命令Select默认Shell,然后它会显示所有可用的命令行界面,select 无论你想要什么,VS code 都会自动将其设置为默认集成终端。

如果您想手动设置它,请找到您的 cli 的可执行文件位置并打开 vscode(ctrl+,) 的用户设置,然后设置

"terminal.integrated.shell.windows":"path/to/executable.exe"

windows7 上的 gitbash 示例:

"terminal.integrated.shell.windows":"C:\Users\stldev03\AppData\Local\Programs\Git\bin\bash.exe",

我通过设置 > 终端 > 集成 > Shell 成功了:Linux

从那里我将 shell 的路径从默认 [=] 编辑为 /bin/zsh 24=]/bin/bash

  • 还有 OSX 和 Windows 的选项以及

@charlieParker - 这是我在命令面板中看到的可用命令

可能为时已晚,但以下内容对我有用:

  1. 打开设置 --> 这将打开 settings.json
  2. 输入terminal.integrated.windows.shell
  3. 点击右上角的 {} -- 这将打开一个编辑器,您可以在其中覆盖此设置。
  4. 设置值为terminal.integrated.windows.shell: C:\Users\<user_name>\Softwares\Git\bin\bash.exe
  5. 点击 Ctrl + S

尝试打开新终端。它应该在 bash 编辑器中以集成模式打开。

如果您想将外部终端更改为新的 windows 终端,这里是 how

接受的答案中解释的方法已被弃用,现在推荐的新配置默认 shell 的方法是在 #terminal.integrated.profiles.windows# 中创建终端配置文件并将其配置文件名称设置为默认值在 #terminal.integrated.defaultProfile.windows#.

旧方法目前优先于新配置文件设置,但将来会发生变化。

查看电源示例shell,取自 docs

{
  "terminal.integrated.profiles.windows": {
    "My PowerShell": {
      "path": "pwsh.exe",
      "args": ["-noexit", "-file", "${env:APPDATA}PowerShellmy-init-script.ps1"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "My PowerShell"
}

从 2021 年 12 月 2 日开始工作。

In settings.json

 {
    "go.toolsManagement.autoUpdate":true,
    "terminal.integrated.profiles.windows":{
        "My Bash":{
            "path":"D:\1. Installed_Software\Git\bin\bash.exe"
        }
    },
    "terminal.integrated.defaultProfile.windows":"My Bash"
}

参考:https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles

更改外部终端

windows terminal 已经被别人提到了,是 alacrity 的替代品,它是一个终端(模拟器)

vscode所述,Cmder是一个shell,就像powershell或bash.

"terminal.integrated.profiles.windows": {
    "cmder": {
        //  "path": "F:\cmder\Cmder.exe",  // 这样会开external terminal
      "path": "C:\WINDOWS\System32\cmd.exe",
      "args": ["/K", "F:\cmder\vendor\bin\vscode_init.cmd"]
    }
  },
"terminal.integrated.profiles.linux": { "zsh": { "path": "zsh" }, },
"terminal.integrated.defaultProfile.windows": "PowerShell",

cmder 中的声明repo 具有误导性

不同的shell终端下:

如果您想将外部终端更改为新的 windows 终端,请按以下步骤操作。