Windows上的Visual Studio Code默认使用PowerShell作为集成终端。如果你想从Visual Studio Code中使用Bash,应该遵循哪些步骤?
当前回答
我的VS Code版本:1.56.1 (Code——version)
一体化终端配置的用户设置:
Ctrl + Shift + P 用户类型: 首选项:打开用户设置 点击:打开设置(JSON)按钮(靠近右上角)
settings.json:
{
"terminal.integrated.tabs.enabled": true,
"terminal.integrated.shell.windows": "<your installation path>\\Git\\bin\\bash.exe",
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.windows": {
"Git Bash": {
"path": "<your installation path>\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
},
"Command Prompt": {
"path": "${env:windir}\\System32\\cmd.exe",
"icon": "terminal-cmd"
},
"Windows PowerShell": {
"path": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"icon": "terminal-powershell"
}
}
}
terminal.integrated.defaultProfile.windows
这个属性只会在你点击“添加新终端”(“+”)按钮时将GitBash设置为默认值。在启动时将其设置为默认值是不够的。
terminal.integrated.shell.windows
将显示废弃的警告。但是,要使所选shell(这里是github)在启动时成为默认shell,则需要此配置。
过滤问题
在PROBLEMS选项卡上,在输入字段旁边,单击过滤器图标,我选中了“Show Active File Only”选项,以便在处理其他任何事情时消除这个已弃用的错误。
其他回答
这个答案与投票最多的答案相似,但有一个重要的区别:之前关于这个问题的很多答案都集中在运行Git Bash上,而我的答案则集中在运行WSL Bash上。
在Windows 10机器上启用Windows子系统for Linux。 打开Visual Studio Code,按住Ctrl + '打开终端。 使用Ctrl + Shift + P打开命令面板。 类型—选择“Default Shell”。 从选项中选择WSL Bash(不是Git Bash)。
单击终端窗口中的+图标。新终端现在将是一个WSL Bash终端!
VSCODE 1.63.2
即使把这里的答案结合起来,我也不能让它工作。也许,我有一个奇异的设置。我会得到这个错误,设置"terminal.integrated.defaultProfile.windows": "Git Bash",它仍然只会打开Powershell, Git Bash无处可见:
我的解决方法是修改命令提示符的入口,通过改变它指向bash的路径,然后将其设置为默认值,如下所示:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"C:\\Path\\To\\Git\\bin\\bash.exe",
// "${env:windir}\\Sysnative\\cmd.exe",
// "${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"terminal.integrated.defaultProfile.windows": "Command Prompt",
如果你已经有“bash”,“powershell”和“cmd”命令行,并且有正确的路径设置,那么可以通过以下方式从一个命令行切换到另一个命令行。
Ctrl + ':使用默认命令行打开终端窗口。 bash + enter:从默认/当前命令行切换到bash命令行。 powershell + enter:从默认/当前命令行切换到powershell命令行。 cmd + enter:从默认/当前的命令行切换到cmd命令行。
我使用的VS Code版本是1.45.0
最新的VS代码:
如果你看不到设置。进入菜单文件->首选项->设置(或按Ctrl+,) 设置出现,见两个选项卡用户(默认选择)和工作空间。进入“用户->功能->终端” 终端部分出现,请参见settings.json中的链接编辑。点击并添加"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" 保存并重新启动VS代码。
Bash终端将反映在终端上。
要在Visual Studio Code中打开终端,你不需要在任何地方都使用推荐的Ctrl + ',因为这是非常不方便的手指操作。更好的解决方案是:
Ctrl + j
推荐文章
- 如何设置每个文件类型的标签大小?
- 我如何添加环境变量启动。VSCode中的json
- 如何格式化Visual Studio Code项目中的所有文件?
- Pylint在Visual Studio代码中“未解决的导入”错误
- 如何在VS Code中默认打开文本换行
- Git bash错误:无法fork子进程:没有可用的终端(-1)
- 在Visual Studio代码中更改突出显示文本的颜色
- Visual studio代码-键盘快捷键-全部展开/折叠
- Visual Studio Code无法检测已安装的Git
- 禁用Visual Studio代码中的工具提示提示
- Visual Studio Code -将空格转换为制表符
- 在VSCode中的列自动硬换行
- Visual Studio Code:格式没有使用缩进设置
- 如何排除文件扩展名和语言从“格式保存”在VSCode?
- Visual Studio代码- URI的目标不存在" package:flutter/material.dart "