How can I clear the terminal in Visual Studio Code?
I need to clean the contents of the terminal in Visual Studio Code.
Every time I use Maven, the output of the terminal is attached to the previous build, which is confusing me.
How do I clear the terminal window with some command or keyboard shortcut?
cls
doesn't work; it only hides the text.
Solution 1:
Use Ctrl+K. This goes clean your console in Visual Studio Code.
Per comments, in later versions of VSCode (1.29 and above) this shortcut is missing / needs to be created manually.
- Navigate:
File
>Preferences
>Keyboard Shortcuts
- search for
workbench.action.terminal.clear
- If it has no mapping or you wish to change the mapping, continue; otherwise note & use the existing mapping
- Double click on this entry & you'll be prompted for a key binding. Hold
CTRL
and tapK
.Ctrl + K
should now be listed. Press enter to save this mapping - Right click the entry and select
Change when expression
. TypeterminalFocus
then press enter. - That's it. Now, when the terminal is in focus and you press Ctrl+K you'll get the behaviour you'd have expected to get from running
clear
/cls
.
Solution 2:
Ctrl + Shift + P and select Terminal:clear
Solution 3:
FOR VERSIONS AT AND ABOVE
v1.32
SEE BELOW
Bindings for this command still need to be setup manually, even at v1.33.1
, which I am at. The command is there under Terminal: Clear
but the binding is blank. Here is how you can setup bindings in v1.32
and up.
Open up the Keyboard Shortcuts
with Ctrl+K, Ctrl+S. Then click on the {}
next to the Keyboard Shortcuts
tab to open up the keybindings.json
file.
After doing so, find some open space anywhere in the file, and type in the key bind below.
{
"key": "ctrl+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus"
}
FOR VERSIONS UP TO
v1.32
SEE BELOW
This is for Visual Studio Code v1.18
up to v1.32
, I believe; I am on v1.29.1
. Since apparently there are a whole lot of assumptions about the default bindings, here is how you set up a binding, then use it. Keep in mind this binding will completely delete all of the history in your terminal too.
Open up the Keyboard Shortcuts
with Ctrl+K, Ctrl+S. Once you are in Keyboard Shortcuts
, click on keybindings.json
in the text that says ....open and edit keybindings.json
. Then on the RIGHT side, in the keybindings.json
, add this (make sure you put a comma before the first {
if there are one or more bindings already):
{
"key": "ctrl+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus"
}
FOR ALL VERSIONS
Remember, the "key":
can be whatever binding you want. It doesn't HAVE to be Ctrl + K.
To use the keybinding, you must have focus in your terminal, and then do the binding.