How to add multiple terminals in VS Code?

前端 未结 11 2467
轻奢々
轻奢々 2020-11-30 17:15

Can we add multiple different terminals in the VS Code? I am planning to add following three terminal and work with all of those :

  1. Windows Com
相关标签:
11条回答
  • 2020-11-30 17:55

    There is a way to make this happens with these steps by installing an extension:

    1. Find an extension called Shell launcher and install it or you can find it here. Reload VS Code if you want or after you finished all steps.

    2. Go to Files --> Preferences --> Settings and this will open settings.json file and you then insert this (you can edit this to your heart's content):

    Code:

    "shellLauncher.shells.windows": [
        {
            "shell": "C:\\Windows\\<sysnative>\\cmd.exe",
            "label": "cmd"
        },
        {
            "shell": "C:\\Windows\\<sysnative>\\WindowsPowerShell\\v1.0\\powershell.exe",
            "label": "PowerShell"
        },
        {
            "shell": "C:\\Program Files\\Git\\bin\\bash.exe",
            "label": "Git bash"
        },
        {
            "shell": "C:\\Windows\\<sysnative>\\bash.exe",
            "label": "WSL Bash"
        }
    ]
    

    PS: You can use shellLauncher.shells.linux for Linux or shellLauncher.shells.osx for macOS.

    1. Go to Files --> Preferences --> Keyboard Shortcuts and then find on {} icon on the top right corner to open keybindings.json file. Insert this:

    Code:

    [
        { "key": "ctrl+alt+`", "command": "shellLauncher.launch" }
    ]
    

    Update: Type shelllauncher into the search bar. You can then see Shell Launcher: Launch command. Highlight and use any keybinding you like. For example, I picked Ctrl + Alt + (backtick)` for myself.

    You can reload your VS Code and click the key combination you have assigned and that will give you the option to choose which integrated terminal you want to use.

    For more details, please check the official site: https://marketplace.visualstudio.com/items?itemName=Tyriar.shell-launcher

    Enjoy!

    0 讨论(0)
  • 2020-11-30 17:56

    To open the multiple terminal please check the screen shot for the same(on the right bottom of the visual studio code their will be a dropdown and just after it, their is +(plus) icon . On pressing it the new terminal will open.).

    0 讨论(0)
  • 2020-11-30 17:58

    I don't see this in the above, but read all the answers. I think this is the best approach for what is supported right now. I believe, like myself, the OP simply wants to open VSCode, and down yonder on the terminal window, we just want a list of options to open from.

    Yes, you can open the command, "Terminal: Select Default Shell" and loop through that to add various types of terminals...

    Followed by:

    I don't know when this option was added to the dropdown, but look! No need to start by looking up the command. I think this is a lot smoother than any other answer, but it still results in the annoying overwrite of your default term to whatever your last choice was before leaving session.

    Here, we can more easily open the Select Default Shell - it should support "Select New Shell". Simple, you'd think. Hopefully someone adds that soon or I have time to contribute.

    0 讨论(0)
  • 2020-11-30 17:58

    This can be done by adding a different key at the end. By just changing your example to:

    // // 64-bit cmd if available, otherwise 32-bit
     "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe",
    // // 64-bit PowerShell if available, otherwise 32-bit
     "terminal.integrated.shell.windows2": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
    // // Git Bash
     "terminal.integrated.shell.windows3": "C:\\Program Files\\Git\\bin\\bash.exe",
    

    Note that the key ...shell.windows is changed to ...shell.windows2 and ...shell.windows3.

    Follow-up finding: I've noticed that once restart of the IDE, only the first terminal gets displayed. I had to reopen the settings and save it once to get both the terminals again. Will post if any better solution available.

    0 讨论(0)
  • 2020-11-30 18:02

    For now VS Code support defining only one of available terminals as default at a time and you can not add multiple shell terminals.

    If you don't want to install "Shell Launcher" plugin as suggested by @ian0411 then here is a quick way to change/select default terminal.

    Press "Ctrl + Shift + P" to open the Command Palette.

    Type "Terminal: Select Default Shell" and hit enter. You will be prompted to select Git Bash, PowerShell or Cmd as shown below:

    Note: This will change the default shell terminal but there is no harm changing it whenever you need to use another.

    BTW, if you need to switch only between Cmd & Powershell then you can type cmd or powershell (in already opened terminal) to switch to desired terminal. But it would not work for Git Bash.

    0 讨论(0)
  • 2020-11-30 18:02

    As of https://code.visualstudio.com/updates/v1_35 you can now:

    1. select from the pulldown menu directly above the terminal "Select Default Shell"
    2. select the one you like
    3. click the +
    4. done

    (the same goes for opening split screen: before this do 1 + 2 and then click the split screen button)

    (although overriding the default but does no longer matter if this is your flow)

    0 讨论(0)
提交回复
热议问题