3

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

3
  • Have a look at this Stack Overflow question. Commented Jun 8, 2019 at 7:41
  • 1
    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). Commented Jun 8, 2019 at 15:48
  • 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
    – Moshe Katz
    Commented Oct 13, 2019 at 16:42

2 Answers 2

1

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.

1
0

Use two commands together in keybindings.json: ctrl+k, then ctrl+l

 {
    "key": "ctrl+k",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "cls \u000D" },
    "when": "terminalFocus" 
},

{
    "key": "ctrl+l",
    "command": "workbench.action.terminal.clear",
    "when": "terminalFocus" 
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .