如何在Visual Studio代码或VSCode中更改集成终端

Mad*_*lus 48 preference visual-studio-code

我想改变集成终端, CMDER我在Windows 8.1上使用Vscode我检查了文档和偏好文件,但我混淆了所以从下面这行将改变它

//外部终端

// 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",
Run Code Online (Sandbox Code Playgroud)

//集成终端

// 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"
],
Run Code Online (Sandbox Code Playgroud)

mbe*_*eau 39

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

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

然后,您可以使用键Ctrl+ backtick默认访问它.

  • 这仍然会弹出Cmder窗口而不是它被集成 (8认同)
  • @Martin正如本期所述,https://github.com/Microsoft/vscode/issues/12006,由于Cmder是终端模拟器,因此无法集成.你可以改用Clink. (4认同)
  • 我意识到.这是为了澄清那些找到这个答案的人 (4认同)
  • 不要错过@khernand 的回答,它使 Cmder 能够按照我到达这里时所希望的方式进行整合。 (2认同)
  • 只需将设置 `terminal.integrated.shell.linux` 设置为终端可执行文件的路径 (2认同)

khe*_*and 37

可以在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"]

  • 这适用于Windows 10,但是我需要更改参数路径中的斜杠:`["/ k","%CMDER_ROOT%\\ vendor \\ init.bat"]` (7认同)
  • 在@Lodybo的建议下效果很好。谢谢! (2认同)
  • 注意实际上我必须创建一个CMDER_ROOT环境变量。仅将配置文件中的%CMDER_ROOT%替换为init.bat的路径是行不通的 (2认同)
  • 我唯一的问题是,在集成终端中不会保存命令历史记录。重新启动VS Code后,我无法在外部cmder.exe shell中重新选择命令a)b)。任何想法如何解决这个问题? (2认同)

小智 21

我知道已经晚了但你只需输入Ctrl + Shift + p然后输入默认即可快速完成,它会显示一个选项

终端:选择默认Shell

,它将显示所有可用的终端.

  • 有两种终端 - 控制台和集成控制台。后者在调试代码时使用。这个答案不影响它,所以它并没有真正回答OP的问题。 (3认同)
  • 很好的建议。使用这个我可以轻松地从 cmd.exe 切换到 bash。很好很简单。 (2认同)

Moh*_*mpu 9

来自官方文件

在Windows上正确配置shell需要找到正确的可执行文件并更新设置.下面是常见的shell可执行文件及其默认位置的列表.

还有一个便捷命令Select Default Shell,可以通过命令选项板访问,它可以为您检测和设置.

因此,您可以ctrl+shift+p使用命令选项打开命令选项板,使用命令Select Default Shell,然后显示所有可用的命令行界面,选择您想要的任何内容,VS代码会自动为您设置默认的集成终端.

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

"terminal.integrated.shell.windows":"path/to/executable.exe"
Run Code Online (Sandbox Code Playgroud)

在windows7上gitbash的示例:

"terminal.integrated.shell.windows":"C:\\Users\\stldev03\\AppData\\Local\\Programs\\Git\\bin\\bash.exe",
Run Code Online (Sandbox Code Playgroud)