【问题标题】:How to change default terminal in VS Code如何在 VS Code 中更改默认终端
【发布时间】:2021-11-01 12:44:58
【问题描述】:

每当我在 VS Code 中打开终端时,它总是打开它的默认终端,我总是必须手动更改它。

这真的很烦人,因为我每天都在使用终端。我检查了工具栏中的Terminal 设置,但找不到更改默认值的选项。我们该怎么做?

【问题讨论】:

    标签: visual-studio-code terminal vscode-settings


    【解决方案1】:

    当终端打开时,用户应该点击右上角的down-arrow按钮,然后会出现一个选项菜单。然后你应该选择Select Default Profile,你可以从那里选择你的默认终端。

    【讨论】:

    • 我的默认设置显示为命令提示符,但它拒绝遵守这一点,而是无论我做什么都打开 powershell。
    【解决方案2】:

    github 上有很多关于此的问题,请参阅,例如,Default console changed from what I wanted to Powershell during upgrade (我认为这是 v1.60 版本中最古老的跟踪问题)。

    我可以在 Stable v1.60 版本中复制该问题,但不能在 Insiders' 版本中使用完全相同的设置。

    所以这不是您的设置,我相信 vscode 团队知道这一点。您的选择是

    (1) 使用 Insiders' Build - 至少对我有用,
    (2) 将vscode降级到v1.59,
    (3) 当我点击 Add Terminal + 按钮时,我确实得到了我的默认 Git Bash 终端,或者
    (4) 重命名您的默认配置文件 - 见下文。

    仅供参考,我的设置:

      "terminal.integrated.profiles.windows": {
        "PowerShell": {
          "source": "PowerShell",
          "icon": "terminal-powershell"
        },
        "Command Prompt": {
          "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
          ],
          "args": [],
          "icon": "terminal-cmd"
        },
        // "Git Bash": {  // "Git Bash" does not work
        "GitBash": {      // "GitBash" does work
          "path": "C:\\Program Files\\Git\\bin\\bash.exe",
          "icon": "terminal-bash"
        }
      },
    
    
      //  "terminal.integrated.defaultProfile.windows": "Git Bash"  // does not work for me
      "terminal.integrated.defaultProfile.windows": "GitBash"  // does work
    
    
      // deprecated but may still work for you
      // "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
    

    以前trying to set Git Bash as default profile,对于Git Bash,建议改用GitBash(去掉空格)。直到今天在 v1.60 稳定版本中,这对我来说从来没有用过。

    因此,如果不起作用,可以尝试将您的个人资料名称更改为 Git BashWSL 等以外的名称。

    【讨论】:

    • 不幸的是,它仍然拒绝为我使用命令提示符而不是 powershell。
    • 将 vscode 降级到 v1.59 download link,对我有用。
    【解决方案3】:

    我已经尝试设置默认终端大约十几次,但它并没有坚持最新的更新。它一直打开 PowerShell 作为默认终端。这些设置对我来说一直很好,直到昨天的更新 (v1.60.0) 打破了这一点。

        "terminal.integrated.defaultProfile.windows": "WSL",
        "terminal.integrated.profiles.windows": {
          "WSL": {
            "path": "C:\\WINDOWS\\System32\\wsl.exe",
            "args": [
              "~"
            ],
            "icon": "terminal-ubuntu"
          },
          "Git Bash": {
            "source": "Git Bash",
            "icon": "terminal-bash"
          },
          "Command Prompt": {
            "path": [
              "${env:windir}\\System32\\cmd.exe"
            ],
            "args": ["/K cls && cd /D C:\\OD"],
            "icon": "terminal-cmd"
          },
          "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
          }
        }
    

    还有其他人遇到过这种情况吗?

    【讨论】:

      【解决方案4】:

      我让它正确加载,但是当我尝试使用运行按钮运行 Python 脚本时,它在 PowerShell 中运行。

      "terminal.integrated.automationShell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
      "terminal.external.windowsExec": "C:\\Program Files\\Git\\bin\\bash.exe",
      "terminal.integrated.profiles.windows": {
      
      
      "PowerShell": null,
      "Command Prompt": null,
        "Git Bash": {
          "path": "C:\\Program Files\\Git\\bin\\bash.exe",
          "icon": "terminal-bash"
        },
      },
      "terminal.integrated.defaultProfile.windows": "Git Bash"
      

      【讨论】:

        【解决方案5】:

        对我有用的解决方案是:

        方法一:

        打开Settings.json文件并添加以下代码行

        "terminal.integrated.defaultProfile.windows": "Command Prompt"

        进行此更改后,我的Settings.json 文件如下所示:

        {
            "files.autoSave": "afterDelay",
            "window.zoomLevel": 1,
            "liveServer.settings.donotVerifyTags": true,
            "liveServer.settings.donotShowInfoMsg": true,
            "terminal.integrated.automationShell.windows": "",
            "terminal.integrated.automationShell.linux": "",
            "terminal.integrated.defaultProfile.windows": "Command Prompt"
        }
        

        方法二:

        点击Settings并搜索defaultprofilewindows

        您将在此选项卡上获得默认终端。点击菜单列表,选择Command Prompt

        您可以选择任何可用的终端并检查哪一个可以根据需要工作。

        注意:使用任何一种方法都会得到相同的结果。上述两种方法对我来说都非常有效。

        【讨论】:

          猜你喜欢
          • 2022-01-06
          • 1970-01-01
          • 1970-01-01
          • 2021-08-17
          • 2020-08-20
          • 2022-10-16
          • 2016-01-30
          • 2023-03-09
          • 2021-09-03
          相关资源
          最近更新 更多