每当我在 Visual Studio Code 中打开终端时,我会得到一个 Bash shell。我想添加 CMD 作为第二个 shell。为了做到这一点,我浏览了 VS Code 文档,并找到了这个命令:
CTRL+SHIFT+`
但它只会打开第二个 Bash shell。是否有快捷键可以在集成的终端中打开 CMD,而不是在外部控制台中打开呢?
![Screengrab showing console window in VSCode](https://istack.dev59.com/1yLHA.webp)
![Screengrab showing console window in VSCode](https://istack.dev59.com/1yLHA.webp)
如果您想始终打开cmd,可以使用设置进行配置。
根据文档:
在Windows上正确配置您的shell是找到正确的可执行文件并更新设置的问题。 以下是常见shell可执行文件及其默认位置的列表:
// Command Prompt
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
// PowerShell
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
// Git Bash
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\git-cmd.exe",
"terminal.integrated.shellArgs.windows": [
"--command=usr/bin/bash.exe",
"-l",
"-i"
]
// Bash on Ubuntu (on Windows)
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"
如果你只想偶尔打开cmd,你可以尝试打开一个新的bash终端,然后在其中运行cmd
。
如果你经常使用两者,你可能希望使用像这个或这个这样的扩展,允许你在启动终端时选择要使用的终端。
按键映射: [{
"key": "ctrl+shift+t",
"command": "shellLauncher.launch"
}]
设置:
{
"shellLauncher.shells.windows": [
{
"shell": "bash",
"args": [],
"label": "bash"
}, {
"shell": "cmd",
"args": [],
"label": "cmd"
}
]
}
我不知道为什么其他人还没有提到,但这是在VSCode中打开CMD最简单的方法。
只需在终端中输入CMD并按Enter键即可。
在用户设置中添加以下内容注意:粘贴在顶部
{
"terminal.integrated.shell.windows": "cmd.exe"
// other settings...
}
只需要打开终端并输入cmd应用程序的链接,例如 C:\Windows\system32\cmd.exe
从VSCode打开cmd终端
Ctrl + Shift + C
@start run cmd .
或者当你想要进入上一级目录并在那里打开命令提示符时:
cd .. & @start cmd .