VS code terminal disable previous commands output

Is it Possible to disable/remove Previous commands output in VS code terminal default terminal is Powershell now if i type commands pwd and dir and then clear the screen by using cls command now if i type dir command again i am receving all previous commands output in terminal how can i fix this problem

1st command output

PS C:\Users\sadam\Desktop> pwd
Path
----
C:\Users\sadam\Desktop

2nd command output

PS C:\Users\sadam\Desktop> whoami
root\sadam

3rd command output

PS C:\Users\sadam\Desktop> dir Directory: C:\Users\sadam\Desktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 1/24/2022 8:53 PM 7.txt
d---- 10/22/2021 9:46 PM 8
d---- 11/16/2021 7:16 PM del
d---- 11/16/2021 8:52 PM pcl
d---- 1/9/2022 12:40 PM ssssss
-a--- 1/20/2022 6:41 PM 68 11.txt

cleaning the screen by using cls command

typing again dir command & receving output of previous commands

PS C:\Users\sadam\Desktop>cls
PS C:\Users\sadam\Desktop>
PS C:\Users\sadam\Desktop> pwd
Path
----
C:\Users\sadam\Desktop
PS C:\Users\sadam\Desktop> whoami
root\sadam
PS C:\Users\sadam\Desktop> dir Directory: C:\Users\sadam\Desktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 1/24/2022 8:53 PM 7.txt
d---- 10/22/2021 9:46 PM 8
d---- 11/16/2021 7:16 PM del
...
...
PS C:\Users\sadam\Desktop> dir Directory: C:\Users\sadam\Desktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 1/24/2022 8:53 PM 7.txt
d---- 10/22/2021 9:46 PM 8
d---- 11/16/2021 7:16 PM del

1 Answer

This issue is described in the bug-report
Reopen: vscode terminal disrespects cls command in windows #45137.

This bug-report is titled "Reopen", because Microsoft keeps on closing it whenever it is reported. Evidently, there is no intention of fixing it.

The bug seems to be that the cls command clears the screen, but does not clear the scrollback buffer of the terminal, where the past events still exist and are recalled when any scrolling is done.

The solution is to useCtrl+K. This cleans out the Visual Studio Code console, rather than the screen.

As in some versions of VSCode (1.29 and above) this shortcut is missing, it needs to be created as follows:

  • Navigate to menu File > Preferences > Keyboard Shortcuts
  • Find workbench.action.terminal.clear
  • To change its mapping, double-click and when prompted holdCtrl and press K. Press Enter to save.
  • Right-click the entry and select "Change when expression". Type terminalFocus then press Enter.
  • Now Ctrl+K is defined.

Another solution is to pressCtrl+Shift+Pand select Terminal:clear.

Still anothersolutionis:

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"
}

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like