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:
2 Answers
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.
1Use 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"
}