VS Code "Terminal : Clear" command not working as desired

10,416

I'm not even sure if you need the answer anymore but... while I couldn't find a VS CODE behavior that can do what you want (I also tried looking for it). What you can do is add these two lines at the very beginning of your code:

import os
os.system('cls')

It will clear all the terminal garbage before each execution.

Share:
10,416

Related videos on Youtube

vivekmalhotra
Author by

vivekmalhotra

Updated on September 18, 2022

Comments

  • vivekmalhotra
    vivekmalhotra over 1 year

    I am trying to compile a Python file in VS Code.

    I have setup Ctrl+Shift+F10 as the keys for the "Python: Run file in terminal" command.

    Once the file runs in the terminal, I press the Ctrl+K keybinding for "Terminal : Clear". This clears the terminal window.

    However, when I run the Python file again (Ctrl+Shift+F10), the previous output entries (that were cleared before) show up back in the terminal window.

    Any insight on what I am doing incorrectly would be appreciated. Thanks.

    ex. Recreation Of This Issue:

    Recreation of this Issue

    • Anaksunaman
      Anaksunaman almost 5 years
      Have a look at this Stack Overflow question.
    • vivekmalhotra
      vivekmalhotra almost 5 years
      Thanks for the suggestion and I had already gone through the thread you suggested. It is unrelated in this case. I don't have any issue with clearing the terminal. Just that, once terminal is cleared, the previous output data shows up back when teh file is run again (pls refer to the gif file I attached along).
    • Moshe Katz
      Moshe Katz over 4 years
      For new visitors to this question - this appears to be a VSCode bug. It has nothing to do with the keyboard shortcut, because the same thing happens if you select Terminal: Clear from the Command Palette. See github.com/microsoft/vscode/issues/75141, which links to this question
  • vivekmalhotra
    vivekmalhotra almost 3 years
    Thanks. This is being tracked as a bug on github - github.com/microsoft/vscode/issues/75141