在 VS Code 中使用 Git Bash 终端 - 如何强制它在内部打开

Using Git Bash terminal in VS Code - how to force it to open internally

重复:I asked this on SuperUser without answer

使用:

VS Code 提供了快捷键 Ctrl+Shift+C 在外部打开它,快捷键 Ctrl+`(在我的例子中是 Ctrl+F1)在内部打开它。

在我的例子中,它使用快捷方式和菜单视图->终端从外部打开它。

据我所知,我颠倒了 Google 找到了这个解决方案。

我已经从 git-scm.com 重新安装了 Git。

我检查了我的 VS Code 设置 (Code\User\settings.json) 以找到线索,如果我不小心设置为强制外部打开。

我知道我不应该粘贴整个文件,但也许您会发现 settings.json 中的问题所在:

{
  // Chosen Terminal
  "terminal.integrated.shell.windows": "C:\Program Files\Git\bin\bash.exe",
  // Prevent losing aliases, colorization etc. for the Git bash terminal
  // "terminal.integrated.shellArgs.windows": [
  //     "--login",
  //     "--init-file",
  //     "C:\Program Files\Git\etc\profile"
  // ],
  // Windows Terminal
  "terminal.external.windowsExec": "C:\Program Files\Git\bin\bash.exe",
  // Chosen Theme Color and Color Customization
  "workbench.colorTheme": "Monokai",
  "workbench.colorCustomizations": {
    "[Monokai]": {
      // "statusBar.background": "#666666",
      // "panel.background": "#555555",
      // "sideBar.background": "#444444",
      "tab.activeBackground": "#999999",
      "tab.activeForeground": "#333333"
    }
  },
  // Emmet Customization
  "emmet.triggerExpansionOnTab": true,
  // Editor Customization
  "editor.fontSize": 14,
  "editor.wordWrap": "on",
  "editor.codeActionsOnSave": {},
  "editor.tabSize": 2,
  // PHP Tooltip Suggestions
  "php.suggest.basic": false,
  "php.validate.executablePath": "C:\xampp\php\php.exe", //for linting
  "php.validate.run": "onSave", //change to onType if need be
  "explorer.confirmDelete": false,
  "beautify.language": {
    "js": {
      "type": [
        "javascript",
        "json",
        "jsonc"/*,
        "html"*/
      ],
      "filename": [
        ".jshintrc",
        ".jsbeautifyrc"
      ]
    },
    "css": [
      "css",
      "scss"
    ],
    "html": [
      "htm",
      "html"
    ]
  },
  "beautify.config": {
    "indent_size": 2,
    "indent_char": " ",
    "css": {
      "indent_size": 2
    }
  },
  // Git costumization
  "window.zoomLevel": 0,
  "workbench.colorCustomizations": {
    "gitDecoration.addedResourceForeground": "#f45342",
    "gitDecoration.modifiedResourceForeground": "#3888d8"
  },
  "workbench.settings.useSplitJSON": true,
  "files.trimTrailingWhitespace": true,
  "minify.minifyExistingOnSave": true
}

如果我使用 Ctrl+Shift+C 快捷方式,比方说在两个不同的项目上,它会打开两个外部终端,正如人们所期望的那样。

如果我使用 Ctrl+F1(默认 Ctrl+`)快捷方式,它想在内部打开它们,所以 VS Code windows 的底部看起来像这样:

而且它仍然在外部打开它们:

任何人都可以提供一些见解吗?

似乎将 "terminal.external.windowsExec": "C:\Program Files\Git\bin\bash.exe" 添加到“设置”是旧方法,无法按预期工作。

从设置 JSON 中删除与 bash 相关的所有行(检查用户、工作区和文件夹设置以确保确定)并保存文件。

然后打开命令面板(Ctrl + Shift + P)并输入

Select Default Shell

然后从那里选择 bash。

现在您所要做的就是重新启动 VS Code,终端将按预期 运行。

对于不在您的 %PATH% 中的 shell,请参阅其他答案。

参见 the complete Visual Studio Code shell reference

应该已经配置了预先存在的终端配置文件,所以它应该像添加一样简单:

"terminal.integrated.defaultProfile.windows": "Git Bash",

给你的settings.json