How to split the terminal when running tasks in VSCode? - visual-studio-code

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.

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

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.

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.

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.
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)"
Once Homebrew is installed, you can use brew to install tmux:
brew install tmux
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.
Update apt-get to make sure we are on the latest and greatest:
sudo apt-get update
Install tmux:
sudo apt-get install tmux
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

You can simply split the
terminal via shortcut:
Ctrl + Shift + 5
Note: Tested on version 1.36.1 or greater

Related

How to add anaconda powershell to vscode?

I'm trying to add anaconda prompt to start up instead of powershell to avoid having to add python to env variables.
"terminal.integrated.shellArgs.windows": [
<args>
]
I tried putting them into single line, splitting them "-Foo Goo" as well as "-Foo","Goo". Each version leads to either error or simply ignoring the "-Command" parameter (the lines simply get pasted, but not executed).
First of all, I I'd like to give a hint for everyone that uses PowerShell to use the new one.
So, with the Anaconda ready to go (and it been equal or greater than 4.6 - use conda --version) run in sequence (from base environment in cwd terminal):
conda update conda
conda init
This will update your conda root environment and the init will setup all you need to run it on both cwd and powershell.
After this, you can start any powershell (inside vscode or not) and it will be conda ready.
Look at this article for further information.
Hope it helps!
I ended up using this (although it has tendency to break).
"terminal.integrated.shellArgs.windows": [
"-ExecutionPolicy"
, "ByPass"
, "-NoExit"
, "-Command"
, "& 'C:\\ProgramData\\Anaconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\ProgramData\\Anaconda3'"
],
Thanks Zerg! Your answer worked for me but I also got a warning message to say that this approach has been depreciated. After some googling I got this working by adding a new terminal profile to settings.json.
"terminal.integrated.profiles.windows": {
"PowerShell (Anaconda)": {
"source": "PowerShell",
"args": [
"-ExecutionPolicy"
, "ByPass"
, "-NoExit"
, "-Command"
, "& 'C:\\Users\\<username>\\AppData\\Local\\Continuum\\anaconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\Users\\<username>\\AppData\\Local\\Continuum\\anaconda3'"
]
}
},
Then changing the default profile:
"terminal.integrated.defaultProfile.windows": "PowerShell (Anaconda)",
I just installed PowerShell 7, and since I had anaconda installed before, this seems to add the starting command to the profile.ps1 automatically.
The profile.ps1 in C:\Users\USER\Documents\PowerShell (this is version 7, directory WindowsPowerShell would be the old version 5) contains:
#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "C:\Users\USER\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion
With these automatic settings at the start of PowerShell 7, adding PowerShell 7 as a new terminal type to vsccode solved it.
This is how to add PowerShell 7 to the dropdown menu:
Enter Ctrl+Shift+P, open settings.json for the User, and add
{
"terminal.integrated.profiles.windows": {
"PowerShell7": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"args": ["-NoProfile",
"-noexit",
"-file",
"C:\\Users\\USER\\Documents\\PowerShell\\profile.ps1"]
}
},
"terminal.integrated.defaultProfile.windows": "PowerShell7"
}
Then in the settings.json, press Ctrl+s and restart (!) vscode. You will see PowerShell7 as the new default terminal in the dropdown of terminal types:
From the VSCode Command Palette (Ctrl+Shift+P), select
Terminal: Select default shell
and then pick PowerShell.
Then from the Command Palette (Ctrl+Shift+P), select
Python: Select Interpreter
and pick one of the conda environments. When you now open a new terminal VSCode starts PowerShell and activates the selected environment. This is exactly what the Anaconda-Prompt does. However, you should not set a PYTHONPATH in the environment in combination with an Anaconda install. Conda activation is all you need. It not only adds the selected interpreter to the PATH, but the required libraries too.

How to configure the lanuch.json file of vscode to automatically update the module when running debug

I am writing odoo module with vscode, I want to run the module with VScode debug mode, but I don't want to manually update the module, I want to write the configuration in lanuch.json, but I have found a lot of ways to find the write.
I tried a lot to write -u (module name) -d (database) into the args configuration, but it is invalid
"version": "0.2.0",
"configurations": [
{
"name": "Odoo10",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/odoo-bin",
"args": [
"--config=${workspaceFolder}/odoo.conf",
// "${workspaceFolder}/odoo.conf -u aatudo -d Odoo",
// "${workspaceFolder}\C:\Odoo_env\odoo\odoo.conf -u aatudo -d
Odoo",
],
"debugOptions": [
"RedirectOutput"]
Odoo itself has a development mode which can come in handy when you are developing modules, development mode in odoo ensures two things:
Along with watchdog module of python, odoo server is reloaded whenever change in python code detected in the directories listed in addons_path
Instead of reading view files from database, view definitions are read directly from xml file, so change in xml view definitions and a page reload will reflect those changes in odoo. No need to update any module from commandline or odoo apps.
To use development mode, just append --dev=all to your odoo running command and don't forget to run pip install watchdog in your environment to install watchdog package for auto server reloading in case of change in Python code.

Skip VS Code terminal shell arguments for launch.json

In my workspace settings I have
{
"terminal.integrated.shellArgs.linux": [
"-c",
"yarn custom_shell"
],
}
which launches a custom shell that prompts for user input on startup.
When I create a launch.json config that launches using the integrated terminal my yarn custom_shell command will run and wait for input, causing the launch command supplied by VS Code to fail to run. This same issue occurs for extensions that launch a program in my integrated terminal.
Is there a way to launch the integrated terminal with terminal.integrated.shellArgs only when it is an interactive user shell, not a shell started by an extension or launch.json config?
I think a good solution is to keep the integrated shell to behave as expected and to use shell-launcher extension for hacking different shells in vscode (it might also save you the need to wait for user input in your custom shell):
"shellLauncher.shells.linux": [
{
"shell": "bash",
"args": ["-c yarn custom_shell"],
"label": "my_custom_yarn_shell"
}
]

How to change the integrated terminal in Visual Studio code

I want to change integrated terminal to CMDER i use VS Code on Windows 8.1.
I checked the docs and also preference file, but I am confused
which line to change.
External Terminal
// Customizes which terminal to run on Windows.
"terminal.external.windowsExec": "%COMSPEC%",
// Customizes which terminal application to run on OS X.
"terminal.external.osxExec": "Terminal.app",
// Customizes which terminal to run on Linux.
"terminal.external.linuxExec": "xterm",
Integrated Terminal
// The path of the shell that the terminal uses on Linux.
"terminal.integrated.shell.linux": "sh",
// The command line arguments to use when on the Linux terminal.
"terminal.integrated.shellArgs.linux": [],
// The path of the shell that the terminal uses on OS X.
"terminal.integrated.shell.osx": "sh",
// The command line arguments to use when on the OS X terminal.
"terminal.integrated.shellArgs.osx": [],
// The path of the shell that the terminal uses on Windows. When using shells shipped with Windows (cmd, PowerShell or Bash on Ubuntu), prefer C:\Windows\sysnative over C:\Windows\System32 to use the 64-bit versions.
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
// The command line arguments to use when on the Windows terminal.
"terminal.integrated.shellArgs.windows": [],
// Controls the font family of the terminal, this defaults to editor.fontFamily's value.
"terminal.integrated.fontFamily": "",
// Controls whether font ligatures are enabled in the terminal.
"terminal.integrated.fontLigatures": false,
// Controls the font size in pixels of the terminal, this defaults to editor.fontSize's value.
"terminal.integrated.fontSize": 0,
// Controls the line height of the terminal, this number is multipled by the terminal font size to get the actual line-height in pixels.
"terminal.integrated.lineHeight": 1.2,
// Controls whether the terminal cursor blinks.
"terminal.integrated.cursorBlinking": false,
// Controls whether locale variables are set at startup of the terminal, this defaults to true on OS X, false on other platforms.
"terminal.integrated.setLocaleVariables": false,
// A set of command IDs whose keybindings will not be sent to the shell and instead always be handled by Code. This allows the use of keybindings that would normally be consumed by the shell to act the same as when the terminal is not focused, for example ctrl+p to launch Quick Open.
"terminal.integrated.commandsToSkipShell": [
"editor.action.toggleTabFocusMode",
"workbench.action.debug.continue",
"workbench.action.debug.restart",
"workbench.action.debug.run",
"workbench.action.debug.start",
"workbench.action.debug.stop",
"workbench.action.quickOpen",
"workbench.action.showCommands",
"workbench.action.terminal.clear",
"workbench.action.terminal.copySelection",
"workbench.action.terminal.focus",
"workbench.action.terminal.focusNext",
"workbench.action.terminal.focusPrevious",
"workbench.action.terminal.kill",
"workbench.action.terminal.new",
"workbench.action.terminal.paste",
"workbench.action.terminal.runSelectedText",
"workbench.action.terminal.scrollDown",
"workbench.action.terminal.scrollDownPage",
"workbench.action.terminal.scrollToBottom",
"workbench.action.terminal.scrollToTop",
"workbench.action.terminal.scrollUp",
"workbench.action.terminal.scrollUpPage",
"workbench.action.terminal.toggleTerminal"
],
To change the integrated terminal on Windows, you just need to change the terminal.integrated.shell.windows line:
Open VS User Settings (Preferences > User Settings). This will open two side-by-side documents.
Add a new "terminal.integrated.shell.windows": "C:\\Bin\\Cmder\\Cmder.exe" setting to the User Settings document on the right if it's not already there. This is so you aren't editing the Default Setting directly, but instead adding to it.
Save the User Settings file.
You can then access it with keys Ctrl+backtick by default.
It is possible to get this working in VS Code and have the Cmder terminal be integrated (not pop up).
To do so:
Create an environment variable "CMDER_ROOT" pointing to your Cmder
directory.
In (Preferences > User Settings) in VS Code add the following settings:
"terminal.integrated.shell.windows": "cmd.exe"
"terminal.integrated.shellArgs.windows": ["/k", "%CMDER_ROOT%\\vendor\\init.bat"]
I know is late but you can quickly accomplish that by just typing Ctrl+Shift+P and then type "default" - it will show an option that says:
Terminal: Select Default Shell
It will then display all the terminals available to you.
From Official Docs
Correctly configuring your shell on Windows is a matter of locating
the right executable and updating the setting. Below is a list of
common shell executables and their default locations.
There is also the convenience command Select Default Shell that can be
accessed through the command palette which can detect and set this for
you.
So you can open a command palette using ctrl+shift+p, use the command Select Default Shell, then it displays all the available command line interfaces, select whatever you want, VS code sets that as default integrated terminal for you automatically.
If you want to set it manually find the location of executable of your cli and open user settings of vscode(ctrl+,) then set
"terminal.integrated.shell.windows":"path/to/executable.exe"
Example for gitbash on windows7:
"terminal.integrated.shell.windows":"C:\\Users\\stldev03\\AppData\\Local\\Programs\\Git\\bin\\bash.exe",
For OP's terminal Cmder there is an integration guide, also hinted in the VS Code docs.
If you want to use VS Code tasks and encounter problems after switch to Cmder, there is an update to #khernand's answer. Copy this into your settings.json file:
"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.env.windows": {
"CMDER_ROOT": "[cmder_root]" // replace [cmder_root] with your cmder path
},
"terminal.integrated.shellArgs.windows": [
"/k",
"%CMDER_ROOT%\\vendor\\bin\\vscode_init.cmd" // <-- this is the relevant change
// OLD: "%CMDER_ROOT%\\vendor\\init.bat"
],
The invoked file will open Cmder as integrated terminal and switch to cmd for tasks - have a look at the source here. So you can omit configuring a separate terminal in tasks.json to make tasks work.
Starting with VS Code 1.38, there is also "terminal.integrated.automationShell.windows" setting, which lets you set your terminal for tasks globally and avoids issues with Cmder.
"terminal.integrated.automationShell.windows": "cmd.exe"
I was successful via settings > Terminal > Integrated > Shell: Linux
from there I edited the path of the shell to be /bin/zsh from the default /bin/bash
there are also options for OSX and Windows as well
#charlieParker - here's what i'm seeing for available commands in the command pallette
If you want to change the external terminal to the new windows terminal, here's how.
The method explained in the accepted answer has been deprecated, now the new recommended way to configure your default shell is by creating a terminal profile in #terminal.integrated.profiles.windows# and setting its profile name as the default in #terminal.integrated.defaultProfile.windows#.
The old method will currently take priority over the new profiles settings but that will change in the future.
See an example for powershell taken from the docs
{
"terminal.integrated.profiles.windows": {
"My PowerShell": {
"path": "pwsh.exe",
"args": ["-noexit", "-file", "${env:APPDATA}PowerShellmy-init-script.ps1"]
}
},
"terminal.integrated.defaultProfile.windows": "My PowerShell"
}
change external terminal
windows terminal , which has been mentioned by others, is an alternative of alacrity, which is a terminal (emulator)
As stated in vscode, Cmder is a shell, just like powershell or bash.
"terminal.integrated.profiles.windows": {
"cmder": {
// "path": "F:\\cmder\\Cmder.exe", // 这样会开external terminal
"path": "C:\\WINDOWS\\System32\\cmd.exe",
"args": ["/K", "F:\\cmder\\vendor\\bin\\vscode_init.cmd"]
}
},
"terminal.integrated.profiles.linux": { "zsh": { "path": "zsh" }, },
"terminal.integrated.defaultProfile.windows": "PowerShell",
The statment in cmder' repo is misleading
Different shells under a terminal:
If you want to change the external terminal to the new windows terminal, here's how.
Probably it is too late but the below thing worked for me:
Open Settings --> this will open settings.json
type terminal.integrated.windows.shell
Click on {} at the top right corner -- this will open an editor where this setting can be over ridden.
Set the value as terminal.integrated.windows.shell: C:\\Users\\<user_name>\\Softwares\\Git\\bin\\bash.exe
Click Ctrl + S
Try to open new terminal. It should open in bash editor in integrated mode.
Working as of 02-Dec-2021.
In settings.json
{
"go.toolsManagement.autoUpdate":true,
"terminal.integrated.profiles.windows":{
"My Bash":{
"path":"D:\\1. Installed_Software\\Git\\bin\\bash.exe"
}
},
"terminal.integrated.defaultProfile.windows":"My Bash"
}
Reference: https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles

Sublime Text 3 build system: keep console running

I set up a build system in Sublime Text 3 to run Matlab files. This works really fine:
{
"cmd": ["/usr/local/MATLAB/R2013b/bin/matlab", "-nosplash", "-nodesktop", "-nojvm", "-r \"run('$file');\""]
}
The problem is I want to keep Matlab running in the Sublime console after $file is executed. Is this possible?
Thank you in advance.
Ok, I've finally found a solution that runs the build system in an external xterm terminal. If you use this Sublime will open a xterm window and execute the build system there. This window remains open, so e.g. Matlab plot windows will not be closed after execution of the code. I've combined the build system with and without the external terminal into one build system:
{
"cmd": ["/usr/local/MATLAB/R2013b/bin/matlab", "-nosplash", "-nodesktop", "-r \"run('$file');quit;\""],
"selector": "source.m",
"variants": [
{
"name": "xterm",
"cmd": ["xterm", "-e", "/usr/local/MATLAB/R2013b/bin/matlab", "-nosplash", "-nodesktop", "-r \"run('$file');\""]
}
]
}
and then assigned a user key binding to access the xterm variant easily:
[
{ "keys": ["ctrl+shift+b"], "command": "build", "args": {"variant": "xterm"} }
]
This xterm solution should also work with any other interpreter that you want to prevent from being closed after code execution finishes.
An alternative method is to have both Sublime and Matlab open and then set up a script with AutoHotKey (Windows) or Autokey (Linux) that copies the filename or the code to evaluate and then pastes this in Matlab's command window.
The benefits of this method are:
You maintain all of the useful features of MatLab as an IDE
You can evaluate code snippets (the F9 feature) as well as the whole file
See detailed instructions for Linux or Windows