Windows上的Visual Studio Code默认使用PowerShell作为集成终端。如果你想从Visual Studio Code中使用Bash,应该遵循哪些步骤?
当前回答
Ctrl+Shift+P >打开用户设置>
"terminal.integrated.profiles.windows": {
"Git Bash": {
"path": "D:\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "Git Bash",
"git.enabled": true,
"git.path": "D:\\Git\\bin\\bash.exe",
"terminal.integrated.shell.windows": "D:\\Git\\bin\\bash.exe"
如果您在工作区!
Ctrl+Shift+P >打开工作区设置>在“设置”中粘贴以下内容:{}:
"terminal.integrated.profiles.windows": {
"Git Bash": {
"path": "D:\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "Git Bash",
"git.enabled": true,
"git.path": "D:\\Git\\bin\\bash.exe",
"terminal.integrated.shell.windows": "D:\\Git\\bin\\bash.exe"
最后关闭你所有的Vscode窗口/实例,重新打开,你就可以开始了。
关于莱昂布洛伊和灵魂闪耀 解决方案!
其他回答
我的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”选项,以便在处理其他任何事情时消除这个已弃用的错误。
Vs代码1.60.0
因为我正面临着前面的问题,Git Bash根本没有被识别,尽管之前已经安装了。要让上述任何解决方案发挥作用,您需要遵循本主题中讨论的说明和下面列出的说明。
转到settings.json 通过添加“git. sh”来启用git bash。启用”:真正的 并通过添加“git”来定义它的路径。path": "<你的路径到GIT>\\ GIT \\bin\\bash.exe"
之后,指令(例如由@rustyhu定义的指令)将起作用。
PS:希望我能在调试最初陈述的问题时为您节省几个小时的时间
您不再需要手动输入bash.exe路径。这个答案不赞成。现在,如果在默认路径中安装了git,可以直接切换到bash。如果将git安装到不同的路径,则需要使用下面的解决方案。
从https://git-scm.com/download/win安装Git。
然后打开Visual Studio Code,使用Ctrl + Shift + p打开命令面板,然后输入“open user setting”,然后从下拉菜单中选择“open user Settings”。
然后这个选项卡会打开,左边是默认设置,右边是你的设置:
现在将这行代码复制到您自己的设置页面(右侧的窗格)并保存 "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
注意:“C:\\Program Files\Git\bin\bash.exe”是Git安装时bash.exe文件所在的路径。如果您使用的是Windows子系统for Linux (WSL) Bash shell,路径将是“C:\Windows\System32\ Bash .exe”
现在按Ctrl + '从Visual Studio Code打开终端。你会有巴斯
我尝试了上面的答案,因为vscode 1.42.1和他们的工作,让我一个git bash终端。因此,这个设置只适用于从终端打开bash shell:
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
然而,它也有一个不想要的副作用,即它也是用于构建东西的shell,这打破了MS c++链,因为用于路径分隔符的\字符被bash理解为转义字符。对我来说,完整的修复需要我添加这个额外的变量,将其设置为powershell:
"terminal.integrated.automationShell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
现在,我可以有我的bash终端和Ctrl-Shift-B或F5工作没有问题。
哦,正如其他海报提到的,这些信息的来源是VSCode的文档。
要在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 "