How to Clear the VS Code Terminal: 4 Effective Methods

How To Clear The Terminal Of VS Code

Visual Studio Code (commonly known as VS Code), is an integrated development environment(IDE) used by many developers and programmers worldwide. It first came into existence in 2015, introduced by Microsoft.

In the recent survey conducted by Stack Overflow, VS Code stands at the top of the most popular development tools used in 2023. It comes as no surprise owing to its vast and useful functionalities, multi-language support, and of course, simplicity. It can be downloaded for any operating system like Windows, Linux, and MacOS from the web and the git.

What we are concerned about, is understanding how we can clear the terminal of VS Code. First of all, let us understand what a terminal in coding is.

Recommended Read: Determining the install path of Python from the Command Line

What Is a Terminal?

A terminal is a text-based window through which we can interact with the computer, and pass commands and it is used by the computer to display the results or outputs of the commands or code snippets.

Different Operating Systems have different types of terminals and are called by different names. Not only the operating systems but the IDEs also have terminals to interact with the user.

This is what a VS Code terminal looks like.

VS Code Terminal
VS Code Terminal

Now coming to the main question, Why do we have to clear the terminal?

One primary reason is aesthetics; no one wants to work in a cluttered environment, do they? When you are working with multiple program files at the same time, the terminal becomes cluttered and it might be confusing to understand the outputs. Hence it is important to clear the terminal before execution of any file. Doing so will also prevent any distractions, preserving the appearance of the terminal, privacy, and security if you are dealing with secret and important information like APIs. Debugging is easier when the terminal is clean.

Let us take a look at the code used for this tutorial.

def add(a,b):
    return a+b 
def sub (a,b):
    return a-b 
def mul(a,b):
    return a*b 
def divi(a,b):
    return a/b
a = add(10,20)
s = sub(20,10)
m = mul(10,20)
d = divi(20,10)
print("Sum of two numbers:",a)
print("Difference between two numbers:",s)
print("Product of two numbers:",m)
print("Remainder of the division:",d)

The code is pretty simple to understand. We have created four different functions that take two arguments as input to carry out basic arithmetic operations – addition, subtraction, multiplication, and division. These functions are called separately and print statements are used to print the result on the terminal.

Let us take a look at four methods to clear the terminal.

For example, I have executed two Python files to make the terminal a little messy, which we are going to clean up using the below methods.

Terminal before clean up
Terminal Before Cleanup

Clearing with ‘Cls’ Command in VS Code

The first and direct way to clear the terminal window is to use the cls command. Cls stands for clear screen and is used in command line interfaces to clear them while interacting with the terminal itself.

All you need to do is type cls on the terminal after the cursor and hit enter.

The cls command
The cls command

Just like that, the terminal is cleared up and as good as new!

Quick Terminal Clearing: Keyboard Shortcut

There is one standard keyboard shortcut widely used by developers which wipes off the terminal quickly. This shortcut is ctrl+l. We just have to press ctrl with the l key.

Since this is a shortcut, we don’t see any output but the terminal does get cleared.

Personalize Your Shortcut for Terminal Clearance

This method is for all the people who want to experiment with the standard shortcut and customize it according to their choice.

VS Code has preference settings, through which we can update the keyboard settings.

Find the File option, navigate to Preferences>Keyboard Shortcuts. In the search bar type workbench. action.terminal. There you can type in any shortcut of your choice and hit enter. Follow the video below to complete the process.

Customising Keyboard Shortcut

Using the Command Palette for Terminal Cleaning

The command palette is a window in which we can find pretty much every useful command related to the terminal. It includes a search box through which we can search commands and execute them. It is accessible using ctrl+shift+P in Windows and Shift+Command+P in MacOS. The command to type in to clear the terminal is Terminal:Clear.

Here is a demo for clearing the terminal using the command palette.

Command Palette


In this short tutorial, we have discussed the history of VS Code and its functionalities in the introduction, followed by the definition of a terminal and the need to clear the terminal.

We have briefly discussed four different methods to do the same. Using a short command, a keyboard shortcut, a way to customize the keyboard shortcut, and finally, using the command palette.

I hope you find this tutorial useful for your next big work! Happy Coding!


VS Code Wikipedia

Stack Overflow Query