0

I have been coding for about a year as a hobby and I code mainly on Pycharm. I started to use Visual Studio Code because a course required using it. Every time I run my program it leaves everything from previous run into terminal and this slows me down since I have more trouble finding out what the actual print or error message was. Pycharm always cleared the previous run from terminal. If I remember correctly I am using some sort of education version of Visual Studio Code.

This answer is basically what I was looking for, but I can't find "Code-runner: Clear Previous Output" in my settings even with search terms.

Timothy G.
  • 6,335
  • 7
  • 30
  • 46
Heikki
  • 341
  • 2
  • 18
  • This was answered here: https://stackoverflow.com/questions/48713604/how-can-i-clear-the-terminal-in-visual-studio-code – Musaab Sep 18 '21 at 21:08
  • @Musaab That is similar, but not quite what I was looking for. In your suggested answer terminal is cleared with keyboard shortuct. I am looking for a feature that clears terminal everytime I click run button and only after clearing it shows the terminal output. – Heikki Sep 18 '21 at 22:46

2 Answers2

1

Turn to extension marketplace, make sure you have installed and enabled Code Runner.

Then add the following configurations in Settings.json: enter image description here

"code-runner.clearPreviousOutput": true,

Run Code, the result will be dispalyed in OUTPUT. If you don't want execution scripts, you can achieve it by adding

"code-runner.showExecutionMessage": false

Detailed information please view Configuration.

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
  • Where should I look for Settings.json? – Heikki Sep 20 '21 at 20:11
  • **Manage-->Settings**, then click the logo in the top right corner to `Open Settings(JSON)`. I upload the screenshot in my answer, please check.@Heikki – Molly Wang-MSFT Sep 21 '21 at 01:02
  • It seems to work at first, but after some testing it seems it will not always print errors. For example in python I typed `print(")`, witch gave me no error. Even `raise Error` gave me no error for some reason. Sometimes it would give me correct errors, but it was inconsistent when it gave them. – Heikki Sep 23 '21 at 17:59
  • @Heikki. It will happen sometimes when using code runner. it's recommended that you use java extension to run java code. – Molly Wang-MSFT Sep 27 '21 at 00:59
1

Go to settings and type Terminal. You are looking for: Debug > Terminal: Clear Before Reusing.

Tick the box and every time you will run your script, the terminal will clear itself from previous output. No need for extensions, just standard VS Code settings.

Jakub
  • 303
  • 2
  • 8
  • This seems to work only when I run in debug mode. This seems to have a drawback that it slows the proses down. Not much, but otherwise the code I run runs instantly, in debug mode it takes two secconds, even when running only one print statement. – Heikki Sep 23 '21 at 18:10
  • Don't know what it could be. Mine is working fine whether I will debug or not terminal will still get cleared. – Jakub Sep 23 '21 at 22:58