Visual Studio Code Terminal Usage and Setup Instructions
Visual Studio Code Terminal
In real-world project development, IDEs often use the command line (also known as a shell program) to compile and run code, or to perform other related tasks. Terminal enables developers to use the command line directly in Visual Studio Code, such as PowerShell and Command Prompt in Windows, and bash
in UNIX/Linux.
By default, the Terminal Panel will be displayed in the bottom area of Visual Studio Code, and the upper right corner of this panel will provide terminal-related functions and information. If Terminal launches more than one command-line application, the right area of the Terminal Panel will list them one by one and the interface will change a bit.
Open Visual Studio Code Terminal
To open Terminal in Visual Studio Code, you can either select the menu item View | Terminal, or use the keyboard shortcut Ctrl+` (⌃+` on macOS), or type and execute the command View: Toggle Terminal
in Command Panel. If Terminal is already open, then using the keyboard shortcut Ctrl+` or executing the command View: Toggle Terminal
will hide Terminal.
How to open a new external terminal?
In addition to being able to open the integrated Terminal, Visual Studio Code can also open an external terminal directly, simply by using the keyboard shortcut Ctrl+Shift+C, or by typing and executing the command Open New External Terminal
in the Command Panel, or by selecting the context menu item Open in External Terminal of the folder in Explorer.
The external terminal will be run as a separate program and the path to the specific command-line application to be launched can be specified through the Visual Studio Code user setting items (not available in the workspace settings file), where terminal.external.windowsExec
is used for Windows, terminal.external.linuxExec
for Linux, and terminal.external.osxExec
for macOS.
{
// The following three setting items are used to set an external command-line application that is being launched and are not available in the workspace settings
"terminal.external.windowsExec": "C:\\WINDOWS\\System32\\cmd.exe",
"terminal.external.linuxExec": "xterm",
"terminal.external.osxExec": "Terminal.app",
}
How to open an external terminal from a folder in Explorer?
By default, the folder in Explorer only has the context menu item Open in Integrated Terminal, you need to set the setting item terminal.explorerKind
to external
, this will enable the context menu item Open in External Terminal.
In addition, the setting item terminal.explorerKind
has the following valid values, integrated
(the default value, which enables the context menu item Open in Integrated Terminal), both
(which enables both the context menu items Open in Integrated Terminal and Open in External Terminal).
{
// Enable context menu items Open in Integrated Terminal and Open in External Terminal at the same time
"terminal.explorerKind": "both",
}
How to open an external terminal from a source control repository in the Source Control Panel?
If the Source Control Repositories in the Source Control Panel is already displayed, the integrated terminal can be opened by default through the context menu item Open in Integrated Terminal for the repositories listed in Source Control Repositories. Setting the setting item terminal.sourceControlRepositoriesKind
to external
enables the context menu item Open in External Terminal to open an external terminal.
In addition, the setting item terminal.sourceControlRepositoriesKind
has the following valid values, integrated
(the default value, which enables the context menu item Open in Integrated Terminal), both
(which enables both the context menu items Open in Integrated Terminal and Open in External Terminal).
{
// Enable context menu items Open in Integrated Terminal and Open in External Terminal at the same time
"terminal.sourceControlRepositoriesKind": "both",
}
New Visual Studio Code Terminal
As mentioned previously, Terminal can run multiple command-line applications (shell programs) at the same time, which are listed in the right area of the Terminal Panel. Select the menu item Terminal | New Terminal, or use the keyboard shortcut Ctrl+Shift+` (⌃+⇧+` on macOS), or type and execute the command Terminal: Create New Terminal
in Command Panel, or select the context menu item Open in Integrated Terminal for a folder in Explorer, or click the plus button in the upper right corner of the Terminal Panel to launch a new command-line application in Terminal. This usually works when you need to use a different command-line application to perform different tasks.
If the Visual Studio Code workspace contains more than one root directory, you need to choose the root directory in which you want to create a new terminal.
How to launch different command-line applications (shell programs) in Terminal?
In general, Visual Studio Code uses the default terminal profile and launches the command-line application specified by that profile, if you want to use another command-line application, then you should use its corresponding terminal profile. Clicking the arrow button next to the plus button in the upper right corner of Terminal Panel will list all the available terminal profiles, and selecting any one of them will launch the command-line application corresponding to that terminal profile. Alternatively, type and execute the command Terminal: Create New Terminal (With Profile)
in Command Panel and select the terminal profile you want to launch.
How to create a new terminal in the editor area?
Typing and executing the command Terminal: Create New Terminal in Editor Area
in Command Panel launches a new command-line application (shell program) in the editor area, while executing the command Terminal: Create New Terminal in Editor Area to the Side
launches a new command-line application on the right side of the editor area.
How to change the display location of a new terminal?
By default, after performing the operation of creating a new terminal, the launched command-line application (shell program) will be displayed in the Terminal Panel. You can change the display location of the new command line by using the Visual Studio Code setting item terminal.integrated.defaultLocation
, which has the following valid values.
view
is the default value of the setting item terminal.integrated.defaultLocation
, which indicates that new command lines will be displayed in the Terminal Panel. editor
means that new command lines will be displayed in the editor area.
{
// The new command-line application will be displayed in the editor area
"terminal.integrated.defaultLocation": "editor",
}
Current Working Directory of Visual Studio Code Terminal
By default, command-line applications (shell programs) launched by Terminal use the root directory of the workspace as their current working directory, and you can specify the current working directory of the command-line application via the setting item terminal.integrated.cwd
.
The current working directory of a new command-line application resulting from splitting Terminal may be determined by the original command-line application, as described in section Split and Unsplit Terminal.
{
// Use the src folder in the workspace as the current working directory for the command line
"terminal.integrated.cwd": "src",
}
How can I use a folder in Visual Studio Code as the current working directory of the terminal being opened?
In Explorer, selecting a folder’s context menu item Open in Integrated Terminal or Open in External Terminal opens the command-line application and makes the folder the current working directory for the command line.
Word Wrap in Visual Studio Code Terminal
Although some command-line applications (shell programs) have word wrap features of their own, some text may still not display in the Terminal Panel. You can set whether to enable or disable Terminal’s word wrap feature by selecting the command-line application’s context menu item Toggle Size to Content Width, or by using the keyboard shortcut Alt+Z, or by typing and executing the command Terminal: Toggle Size to Content Width
in Command Panel, enabling this feature will cause everything in the command line to be displayed in the visible area.
Buffers for Visual Studio Code Terminal
The commands and outputs displayed in a command-line application (shell program) are stored in a Terminal buffer, the size of which can be modified by the setting item terminal.integrated.scrollback
, with a default value of 1000
, i.e., up to 1000
lines of information can be retained. It should be noted that the maximum number of lines that can be retained in the Terminal’s buffer may differ from the setting item terminal.integrated.scrollback
.
Visual Studio Code will allocate memory based on the size of the terminal buffer
When you increase the size of the Terminal’s buffer by setting the item terminal.integrated.scrollback
, the amount of memory occupied by Visual Studio Code, which is pre-allocated to provide a smooth user experience, will also increase.
{
// The command line can hold up to 200 lines of information
"terminal.integrated.scrollback": 200,
}
Copy and Paste Operations in Visual Studio Code Terminal
The copy and paste operations in Terminal are the same as in the operating system on which it is based, and can be done using the keyboard shortcuts Ctrl+C and Ctrl+V in Windows, Ctrl+Shift+C and Ctrl+Shift+V in Linux, and C⌘+C and ⌘+C in macOS.
In addition to the keyboard shortcuts mentioned above, Terminal provides the following Command Panel commands to accomplish some copy and paste operations.
The command Terminal: Copy Last Command and Output
can be used to copy the last command executed on the command line and its output. The command Terminal: Copy Last Command
can be used to copy the last command executed on the command line. The command Terminal: Copy Last Command Output
can be used to copy the output of the last executed command on the command line.
The command Terminal: Paste into Active Terminal
can be used to paste content into the currently active command-line application.
Also, some mouse operations can also be used to copy and paste text, as described in section Mouse Operations.
How do I automatically copy the selected content in Terminal?
By default, selecting the contents of a command-line application (shell program) does not automatically copy them, you can set the Visual Studio Code setting item terminal.integrated.copyOnSelection
to true
to automatically copy the selected content.
{
// The selected content is automatically copied
"terminal.integrated.copyOnSelection": true,
}
How to disable or enable the paste warning in Terminal?
If the command-line application (shell program) launched by Terminal does not support bracketed paste mode and the paste is not handled by readline
, when you try to paste multiple lines of text for the command line, Visual Studio Code will display the paste warning “Are you sure you want to paste … lines of text into the terminal?”. At this point, there are three choices, where “Paste” means to paste multiple lines of text to the command line, “Paste as one line” means to convert the multiple lines of text to a single line of text and paste it to the command line, and “Cancel” means do not perform the paste operation.
To disable the above mentioned paste warning, you need to set the setting item terminal.integrated.enableMultiLinePasteWarning
to never
, which also has the following valid values. always
means that Visual Studio Code always displays a warning when pasting multiple lines of text (whether or not a warning is displayed depends on the specific command-line application). auto
is the default value of the terminal.integrated.enableMultiLinePasteWarning
setting item, which means that pasting multiple lines of text to the command line will cause Visual Studio Code to display a paste warning when the command line doesn’t support the bracketed paste mode and the paste is not handled by readline
.
{
// Disable paste warnings
"terminal.integrated.enableMultiLinePasteWarning": "never",
}
Find Operations in Visual Studio Code Terminal
When the command-line application (shell program) launched by Terminal is active, using the keyboard shortcut Ctrl+F, or typing and executing the command Terminal: Focus Find
in Command Panel will open the Find Widget.
In addition to performing find-related operations via the Find Widget, Terminal provides a number of keyboard shortcuts (which generally require the command line to be active) and CommandPanel commands to achieve the same effect.
The keyboard shortcut Alt+R and the command Terminal: Toggle Find Using Regex
can be used to set whether or not to use regular expressions for finding. The keyboard shortcut Alt+W and the command Terminal: Toggle Find Using Whole Word
can be used to set whether to use whole word matching. The keyboard shortcut Alt+C and the command Terminal: Toggle Find Using Case Sensitive
can be used to set whether to use case sensitive or not.
The keyboard shortcut Shift+Enter (requires the Find Widget to be active) and the command Terminal: Find Next
can be used to find the next matching text. The keyboard shortcut Enter (requires the Find Widget to be active) and the command Terminal: Find Previous
can be used to find the previous matching text.
The keyboard shortcut Escape and the command Terminal: Hide Find
can be used to hide the Find Widget.
Selection Operations in Visual Studio Code Terminal
For command-line applications (shell programs) launched by Terminal, macOS provides the keyboard shortcut ⌘+A to select everything in the command line, whereas Linux/Windows does not provide a keyboard shortcut for a select-all operation, so you may not be able to use Ctrl+A to select all in the command line. The alternative is to execute the command Terminal: Select All
in the Command Panel, which will select the entire contents of the command line.
In addition, Terminal provides the following keyboard shortcuts (which generally require the command line to be active) and the CommandPanel commands to accomplish some selection operations.
The command Terminal: Select To Next Line
can be used to select the next line of the command line, executing the command again will select more. The command Terminal: Select To Previous Line
can be used to select the previous line of the command line, executing this command again will select more.
The keyboard shortcut Ctrl+Shift+DownArrow and the command Terminal: Select To Next Command
can be used to select the next command on the command line and its output, executing the command again will select more. The keyboard shortcut Ctrl+Shift+UpArrow and the command Terminal: Select To Previous Command
can be used to select the previous command on the command line and its output, executing the command again will select more.
The keyboard shortcut Escape and the command Terminal: Clear Selection
can be used to deselect.
Mouse Operations in Visual Studio Code Terminal
In different operating systems, Visual Studio Code Terminal handles the right-click of the mouse in different ways. In Windows, a right-click will copy the selected content in the command line or paste the copied content, in Linux, a right-click will bring up the context menu, and in macOS, a right-click will select the text at the mouse and bring up the context menu.
How to change the behavior when clicking the right mouse button in Terminal?
If you want to change the behavior when clicking the right mouse button on the command line, then you can use the Visual Studio Code setting item terminal.integrated.rightClickBehavior
, which has the following valid values.
default
means that clicking the right mouse button will display the context menu in the command line. copyPaste
means that copying the selected content or pasting the copied content in the command line will be done when the right mouse button is clicked. paste
means to paste the copied content in the command line when clicking the right mouse button. selectWord
means to select the text at the mouse and bring up the context menu when clicking the right mouse button. nothing
means that when clicking the right mouse button, no action is performed and the mouse event is passed to the command-line application.
{
// When you click the right mouse button, the text at the mouse will be selected and the context menu will be displayed
"terminal.integrated.rightClickBehavior": "selectWord",
}
How to change the behavior when clicking the middle mouse button in Terminal?
If you want to change the behavior when clicking the middle mouse button on the command line, then you can use the setting item terminal.integrated.middleClickBehavior
, which has the following valid values.
default
means that clicking the middle mouse button will give the command line focus. paste
means that the copied content will be pasted into the command line when the middle mouse button is clicked.
{
// Paste when clicking the middle mouse button
"terminal.integrated.middleClickBehavior": "paste",
}
How to quickly move the cursor in Terminal with the mouse?
In a command-line application (shell program) launched by Terminal, holding down the Alt key (Option on macOS) and clicking the left mouse button allows you to quickly move the cursor on the command line. Since this feature is implemented by simulating keyboard operations, it may not work in some command-line applications. This feature can be disabled by setting the setting items terminal.integrated.altClickMovesCursor
to false
.
{
// Holding down the Alt key and clicking the left mouse button no longer moves the cursor
"terminal.integrated.altClickMovesCursor": false,
}
How to adjust the font size of Terminal by mouse?
If the setting item terminal.integrated.mouseWheelZoom
is set to true
(the default is false
), then holding down the Ctrl key in Terminal and scrolling the mouse wheel can adjust the font size of the command-line application, which is equivalent to modifying the setting item terminal.integrated.fontSize
.
It should be noted that the above effect may not be triggered immediately, as the mouse wheel will first scroll the buffer of the command-line application.
{
// Hold down the Ctrl key and scroll the mouse wheel to zoom in and out of the font
"terminal.integrated.mouseWheelZoom": true,
}
How to adjust the scrolling speed of the mouse in Terminal?
The setting item terminal.integrated.mouseWheelScrollSensitivity
can be used to adjust the scrolling speed of the mouse in the Terminal, e.g. setting it to 2
means that the scrolling speed is 2
times the default.
{
// Mouse scrolling speed is 2x the default
"terminal.integrated.mouseWheelScrollSensitivity": 2,
}
How to force the mouse behavior to be handled by Terminal?
On the command line launched by Terminal, some running programs may take over the handling of mouse behaviors, such as Vim
with mouse support, and you need to hold down the Alt key (Option on macOS) if you want the command line to still handle mouse behaviors. For macOS, you also need to set the setting item terminal.integrated.macOptionClickForcesSelection
to true
.
Input Operations in Visual Studio Code Terminal
If you want to quickly enter the paths to files or folders in the command-line application (shell program) launched by Terminal, then you can drag and drop those files or folders to the command line and the paths will be escaped as necessary and then entered into the command line.
Enter and execute the command Terminal:Run Selected Text In Active Terminal
in Command Panel and Visual Studio Code will run the text that has been selected in the current editor as a command in Terminal, if no text is selected, the entire line where the editor cursor is located will be used as the command.
Enter and execute the command Terminal: Run Active File In Active Terminal
in Command Panel and Visual Studio Code will run the current file as a command in Terminal.
Using the keyboard shortcut Ctrl+Alt+R (requires the command-line application to be active) or typing and executing the command Terminal: Run Recent Command…
in Command Panel, you can select and execute a recently executed command.
How do I give Terminal focus after I have selected text in the current editor as a command?
If the setting item terminal.integrated.focusAfterRun
is set to terminal
, then Terminal will gain focus after typing and executing the command Terminal: Run Selected Text In Active
in the Command Panel.
{
// After the command is executed, the command line gets focus
"terminal.integrated.focusAfterRun": "terminal",
}
Links in Visual Studio Code Terminal
The command-line application (shell program) launched by Terminal may contain links that can be clicked by the mouse while holding down Ctrl (⌘ on macOS) and displayed with an underline when the mouse is hovering. Different types of links have different priorities and are handled differently, so we list them below in order of priority, from highest to lowest.
- URI/URL links
For URI/URL links in the command line, holding down Ctrl and clicking on them will launch the handler for the associated protocol. For example, clicking on
https://www.google.com
might launch a browser.- File links
For file links in the command line, hold down Ctrl and click on them, and Visual Studio Code will try to open the related file, e.g. clicking on
readme.md
might open the filereadme.md
in the current working directory. If Visual Studio Code finds that a file link points to more than one file, it will list them and let the developer choose which one to open.File links are supported to be located using something like
file:l:c
, wherel
denotes the line being located andc
denotes the column being located, e.g. clicking onreadme.md:3:2
might open the filereadme.md
and locate to the2
nd column of the3
th line of that file.- Folder links
Folder links in the command line are similar to file links, except that by holding down Ctrl and clicking on them, Visual Studio Code will either try to select the folder pointed to by that folder link in its Explorer, or it will try to start another new window and open the folder pointed to by that folder link. For example, clicking on the folder link
C:\vscode
in Windows launches a new Visual Studio Code window and opens the folderC:\vscode
, if the folder does not already exist in the current Explorer.- Word links
If the text in the command line is not one of the above links, then the text may be treated as word links, and holding down Ctrl and clicking on them will cause Visual Studio Code to either try to open the related file (if the word link is a file path) or search for the related word in the workspace. If there is only one search result then Visual Studio Code will try to open that result, if there are multiple search results then Visual Studio Code will let the developer choose. Unlike other types of links, word links do not display an underline when the mouse is hovering unless Ctrl is held down.
Word links can be located like file links using a form similar to
file:l:c
, wherel
denotes the line being located andc
denotes the column being located, such assettings.json:3:2
.
Entering and executing the command Terminal: Open Detected Link…
in Command Panel or using the keyboard shortcut Ctrl+Shift+G (there may be a conflict) opens links in the command line, which is equivalent to holding down Ctrl and clicking on them. If there is more than one link in the command line, Visual Studio Code will let the developer choose which one to open.
Entering and executing the command Terminal: Open Last URL link
in Command Panel will cause Visual Studio Code to try to open the last URI/URL link in the current command line, and will have no effect if no URI/URL link exists.
Entering and executing the command Terminal: Open Last Local File Link
in Command Panel will cause Visual Studio Code to try to open the last local file link in the current command line, and will have no effect if no local file link exists.
How to disable file and folder links in Terminal?
Since Terminal requires the use of the file system to detect links in command-line applications (shell programs) and determine whether a file or folder is a valid file or folder link by confirming that it actually exists, enabling file and folder links may cause some performance issues, especially in high latency remote environments. You can disable file and folder links in remote environments by setting the setting item terminal.integrated.enableFileLinks
to notRemote
(the default for this setting item is on
, which means that file and folder links are enabled), or off
to disable file and folder links.
It should be noted that after disabling file and folder links, links in the command line may be treated as word links by Terminal, and holding down Ctrl and clicking on them may still cause Visual Studio Code to try to open a file. Also, if you change the setting item terminal.integrated.enableFileLinks
, the change will only work for newly generated command-line applications.
{
// Disable file links in remote environments
"terminal.integrated.enableFileLinks": "notRemote",
}
How to set a separator for word links in Terminal?
The setting item terminal.integrated.wordSeparators
can be used as a separator for word links, and the default value of this setting item is ()[]{}',"`-‘’ “"|
. The separator will be used as a word link boundary to distinguish between different word links in the command-line application, the separator itself will not be used as part of the word link, e.g. (hello)world,vscode
contains three word links hello
, world
and vscode
.
{
// Set the word separator
"terminal.integrated.wordSeparators": " (),",
}
Change the Name, Icon, Color of Visual Studio Code Terminal
When you launch several command-line applications (shell programs) in the Terminal Panel, these command-line applications may have the same name and icon, and it can be difficult to distinguish between them. In this case, you can change the name, the icon and the color of the icon of the command-line application, by selecting the context menu items Rename…, Change Icon…, Change Color….
Of course, in Command Panel, typing and executing the commands Terminal: Change Icon…
, Terminal: Change Color…
will achieve the same effect.
Profiles,Appearance and Styles
If you want to use the terminal profile to modify the name, icon, and icon color of the command-line application, you can check the section Set the Name, Icon, Color of Visual Studio Code Terminal. If you want to specify the default name, description, icon and icon color of the command-line application, you can check the section Customize the Default Name, Description, Icon, Color of Visual Studio Code Terminal Tabs.
Move Visual Studio Code Terminal
Command-line applications (shell programs) in the Terminal Panel have corresponding icons and names, and you can drag and drop the icon or name with the mouse to move the command-line application between the Terminal Panel and the editor area, or make the command-line application become a new window (drag and drop outside the Visual Studio Code window), or change the order between command-line applications (in the case of split command lines, all related command lines will be moved as a whole).
In addition, the same goal can be achieved by selecting the context menu items Move Terminal into Editor Area, Move Terminal into New Window, Move Terminal into Panel of the command-line application, or by typing and executing the commands Terminal: Move Terminal into Editor Area
, Terminal: Move Terminal into New Window
.
Split and Unsplit Visual Studio Code Terminal
If you want to make it easier to compare the outputs from the command line, then you can split Terminal, which is equivalent to launching a new command-line application (shell program), with the new command line displayed to the right of the original command line and forming a command-line group with it.
To split Terminal, you can click the split button next to the icon and name corresponding to a command line (if the Terminal Panel contains more than one command line, then you need to hover over the icon or name of the command line), or hold down the Alt key and click the Split button that appears, or select the context menu item Split Terminal corresponding to a particular command line, or click the arrow button next to the plus button in the upper right corner of Terminal Panel and select the menu item Split Terminal, or drag and drop the icon and name corresponding to the command line in the Terminal Panel, or use the keyboard shortcut Ctrl+Shift+5 in the active command-line application, or type and execute the command Terminal: Split Terminal
in the Command Panel.
To unsplit Terminal, you can either select the context menu item Unsplit Terminal that corresponds to the command line, or type and execute the command Terminal: Unsplit Terminal
in the Command Panel.
How to set the current working directory of a new terminal when splitting a terminal?
When splitting a terminal, a new command-line application (shell program) is created, and the current working directory of the new command line can be set through the setting item terminal.integrated.splitCwd
, which has the following valid values.
inherited
is the default value of the setting item terminal.integrated.splitCwd
, which indicates that the current working directory of the new command line is the same as the current working directory of the original command line. initial
indicates that the current working directory of the new command line is the same as the initial working directory of the original command line (the current working directory when the command line was started). workspaceRoot
indicates that the current working directory of the new command line is the root directory of the workspace, and you need to select the root directory if there are more than one.
For the current working directory of the command-line application, as described in section Current Working Directory of Terminal.
{
// The current working directory of the new command-line application is the root directory of the workspace
"terminal.integrated.splitCwd": "workspaceRoot",
}
How to navigate between split terminals?
When any split command line is active, the keyboard shortcut Alt+LeftArrow or Alt+RightArrow can be used to navigate between related command lines in a command line group.
Kill the Visual Studio Code Terminal
If Terminal launches too many command-line applications (shell programs), the command-line applications can be terminated by clicking on their corresponding trash button, or their corresponding context menu item Kill Terminal. The trash button is usually located in the upper right corner of the Terminal Panel. If the Terminal Panel contains more than one command line, the trash button will be located in the right area of the Terminal Panel, and will appear when the mouse is hovered over, at which point a selected and active command-line application can also be terminated by pressing the Delete key.
In addition, typing and executing the command Terminal: Kill the Active Terminal Instance
in the Command Panel will terminate the currently active command-line application in the Terminal Panel (which has no effect on command-line applications in the editor area), typing and executing the command Terminal: Kill the Active Terminal in Editor Area
will terminate the currently active command-line application in the editor area, typing and executing the command Terminal: Kill All Terminals
will terminate all command-line applications in Visual Studio Code.
The difference between killing Terminal and hiding Terminal
Using the keyboard shortcut Ctrl+` or executing the command View: Toggle Terminal
to hide Terminal does not terminate the command-line application (shell program), and the commands that are being executed on the command line will continue to be executed.