BlueCaret
BlueCaret

Reputation: 5030

How to split the terminal when running tasks in VSCode?

In Visual Studio Code you can now split the integrated terminal in half. I am using VSCode's tasks feature as well to run two tasks always at the same time. How can I make it so when I run a task it will automatically split the current terminal, using the new one for the task?

Basically I'm wanting to open VSCode, it should auto open the integrated terminal like normal, and then I can run my two tasks which should end me with a terminal split into three like so:

------------------------------------------------------
| default terminal   | Task 1       | Task 2         |
------------------------------------------------------

EDIT (SOLVED): VSCode has been updated to allow this now :D https://code.visualstudio.com/updates/v1_31#_task-output-support-split-terminals

You can now configure tasks to show output in a split terminal panel instead of creating a new one. A task configuration can use the group attribute in the presentation section to define where the task's output should be shown.

Upvotes: 22

Views: 10494

Answers (5)

mark.monteiro
mark.monteiro

Reputation: 2941

Direct support for this was added in the January 2019 update.

Setting the same name for the presentation.group property of each task will cause the tasks to appear in split terminals. From the VS Code documentation:

group: Controls whether the task is executed in a specific terminal group using split panes. Tasks in the same group (specified by a string value) will use split terminals to present instead of a new terminal panel.

Upvotes: 9

iutlu
iutlu

Reputation: 435

The following should work:

{
    "type": "process",
    "label": "terminal",
    "command": "/bin/bash",  // <-- your shell here
    "args": [
        "-l"  // login shell for bash
    ],
    "problemMatcher": [],
    "presentation": {
        "echo": false,  // silence "Executing task ..."
        "focus": true,
        "group": "sxs",  // some arbitrary name for the group
        "panel": "dedicated"
    },
    "runOptions": {
        "runOn": "folderOpen"
    }
}

Here, I'm auto-launching (and setting the focus on) the terminal when the folder is opened in vscode -- and further tasks that share the same presentation.group gets placed in split terminals when they're run (with new vs. reused splits depending on their presentation.panel)

Note: For this example, you may or may not need the -l option depending on your settings for terminal.integrated.shell*, terminal.integrated.automationShell* and terminal.integrated.inheritEnv -- this issue has some discussion on what is involved in setting up the shell environment.

Upvotes: 7

Mwiza
Mwiza

Reputation: 9011

You can simply split the terminal via shortcut:

Ctrl + Shift + 5

Note: Tested on version 1.36.1 or greater

Upvotes: -1

GudarJS
GudarJS

Reputation: 178

You can use tmux to split your terminal not just inside vscode, but in all your terminals.

MacOS Installation

The easiest way to get started with tmux on a Mac is to use the Homebrew package manager.

  1. If you don’t have Homebrew installed yet, open either Terminal or iTerm and paste the below command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. Once Homebrew is installed, you can use brew to install tmux:

brew install tmux

  1. Confirm that it installed by checking the version (note the uppercase V):

tmux -V

Ubuntu / Debian Linux Installation

Installation for Ubuntu is similar to Mac, except that we will be using the apt-get package manager that comes pre-installed. Note that we will have to run apt-get as sudo. This is because a user account won’t have enough privileges to install tmux, so sudo will allow us to install it as superuser.

  1. Update apt-get to make sure we are on the latest and greatest:

sudo apt-get update

  1. Install tmux:

sudo apt-get install tmux

  1. Confirm that it installed by checking the version:

tmux -V

After installing

Use the tmux command to start a new session, then press ctrl/cmd + b and % for vertical split or " for horizontal split.

References

How to install tmux

Tmux cheatsheet

Upvotes: 0

Luan Moraes
Luan Moraes

Reputation: 315

When creating your task make sure to have the presentation.reveal option set to always and presentation.panel option set to new. That way the output is always revealed and a new terminal is created on every task run

Example:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run tests",
            "type": "shell",
            "command": "./scripts/test.sh",
            "windows": {
                "command": ".\\scripts\\test.cmd"
            },
            "group": "test",
            "presentation": {
                "reveal": "always",
                "panel": "new"
            }
        }
    ]
}

More info at: Tasks in Visual Studio Code

EDIT: Since you want new tasks into split terminals, maybe this info helps. I don't think it is possible to do it: Launch task directly into split terminal

Upvotes: 8

Related Questions