Windows上的Visual Studio Code默认使用PowerShell作为集成终端。如果你想从Visual Studio Code中使用Bash,应该遵循哪些步骤?
当前回答
更新:(2022年6月,VsCode 1.67)
这里的许多答案(就像这个,高度好评)依赖于设置“terminal.integrated.shell.windows”,现在已经弃用了。
还有许多其他的(被接受的)假设Git for Windows在PATH中安装bash.exe -这不是目前推荐/默认的安装选项。
我现在的食谱是:
添加以下到您的设置(Ctrl-Shift-P ->首选项:打开设置(JSON)),替换为您自己的bash路径:
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": "C:\\devel\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "GitBash",
关闭当前终端,重新启动VsCode。
其他回答
至少对我来说,这将使Visual Studio Code作为外部终端打开一个新的Bash窗口。
如果你想要集成环境,你需要指向Git安装的bin文件夹中的sh.exe文件。
因此,配置应该是C:\\<my-git-install>\\bin\\sh.exe。
按住Ctrl + '打开终端。 在终端中,输入bash在终端中使用Git bash。 注意:确保在您的机器上安装了Git Bash。
如果您想再次使用PowerShell,只需在终端中输入PowerShell即可。要使用Windows命令行,在终端中输入cmd。
您选择的设置将被用作默认设置。
我已经在WSL上设置了很多conda环境(Bash on Ubuntu on Windows),所以我想在Visual Studio Code上使用相同的Bash安装。
要做到这一点,我只需要在Visual Studio Code的设置中指定这个特定的Bash可执行文件(而不是Git-Bash)的路径:
“terminal.integrated.shell.windows”: “C:\\Windows\\System32\\bash.exe”
PS:为了确保你的Ubuntu on Bash可执行文件安装在你的Windows机器上,打开命令提示符(搜索:cmd)并运行:
在bash.exe
最新的VS代码:
如果你看不到设置。进入菜单文件->首选项->设置(或按Ctrl+,) 设置出现,见两个选项卡用户(默认选择)和工作空间。进入“用户->功能->终端” 终端部分出现,请参见settings.json中的链接编辑。点击并添加"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" 保存并重新启动VS代码。
Bash终端将反映在终端上。
在2022年7月,我通过在花括号内添加以下内容来解决这个问题。
"terminal.integrated.defaultProfile.windows": "Git Bash"
注意Git和Bash之间的空白。
我的设置。Json是这样的:
{
"python.defaultInterpreterPath": "C:\\Users\\Prakh\\AppData\\Local\\Programs\\Python\\Python39\\python.exe",
"python.diagnostics.sourceMapsEnabled": true,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"code-runner.runInTerminal": true,
"terminal.integrated.defaultProfile.windows": "Git Bash"
}
现在重新启动VS code并关闭所有现有终端并打开一个新终端。
推荐文章
- 打开同一目录两次
- 如何从终端/命令行调用VS代码编辑器
- 试图在Windows 10上运行Python时出现“权限被拒绝”
- 如何在Visual Studio代码中重置设置?
- 如何将制表符转换为空格,反之亦然,在现有的文件
- GitHub -致命:无法读取用户名https://github.com':没有这样的文件或目录
- 错误:'types'只能在.ts文件中使用- Visual Studio Code使用@ts-check
- Visual Studio Code: .git文件夹/文件隐藏
- Visual Studio Code:如何调试Python脚本的参数
- 如何在Visual Studio代码中触发参数提示?
- 在VS Code中禁用“Comments are not allowed In JSON”错误
- 使用正则表达式搜索和替换Visual Studio代码
- 如何缩进/格式选择的代码在Visual Studio代码?
- 如何禁用预览文件与点击在vs代码?
- Visual Studio代码更改文件资源管理器托盘的字体大小?