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

我想改变集成终端的 CMDER我使用 VS 代码在 Windows 8.1。

我检查了文档和偏好文件,但我很困惑 要改哪一行。


外部终端

// 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"
],
157310 次浏览

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

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

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

它可以在 VS 代码中工作,并且可以集成 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然后键入“ 违约”来快速完成这个任务——它会显示一个选项,上面写着:

终端: 选择默认外壳

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

对于 OP 的终端 Cmder有一个 综合指南,也暗示 在 VS 代码文档中

如果您想使用 VS 代码 任务,并且在切换到 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执行任务-查看源代码 给你。因此,您可以忽略在 tasks.json中配置单独的终端以使任务正常工作。

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

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

来自 官方文件

在 Windows 上正确配置 shell 是一个定位问题 正确的可执行文件并更新设置 公共 shell 可执行文件及其默认位置。

还可以使用方便的命令 选择 Default Shell 通过命令面板访问,可以检测和设置这个 你。

因此,你可以使用 ctrl+shift+p打开一个命令面板,使用命令 选择 Default Shell,然后它显示所有可用的命令行接口,选择任何你想要的,VS 代码集,作为默认的集成终端自动为您。

如果您想手动设置它,请找到您的 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 的路径,从默认的 [ em >/bin/bash ][ em >/bin/zsh

  • 还有 OSX 和 Windows 的选项

screencap of vs settings view

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

enter image description here

也许为时已晚,但下面的方法对我有效:

  1. Open Settings —— > 这将打开 setings.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 终端,这里是 怎么做

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

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

请参见取自 医生的 Powershell 示例

{
"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日。

设置: 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

更换外部端子

enter image description here

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

VScode所述,Cmder 是一个 shell,就像 Powershell 或 bash 一样。

enter image description here

"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",

enter image description here

指挥官 回购的说法是误导性的

enter image description here

终端下的不同外壳:

enter image description here 如果您想将外部终端更改为新的 Windows 终端,以下是方法。