Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear terminal command history in VS code?

In VS Code Powershell Terminal, you can simply press up and down arrow keys to navigate through the history of commands entered, even after a restart. However, when there are same commands entered, it will also cycle through these duplicated histories instead of just making them distinct, making it hard to find cycle back to some old history. Is there a way to clear this history entirely?

like image 942
Cerlancism Avatar asked Oct 17 '22 10:10

Cerlancism


2 Answers

Try the following command:

Set-PSReadlineOption -HistoryNoDuplicates

It sets the HistoryNoDuplicates option to True and hides duplicate histories.

You can see the value of HistoryNoDuplicates with the following command:

(Get-PSReadLineOption).HistoryNoDuplicates

If you want to set it back to False:

Set-PSReadlineOption -HistoryNoDuplicates:$false

For more information, see Set-PSReadlineOption in Microsoft Docs.

like image 95
matt9 Avatar answered Oct 20 '22 06:10

matt9


As a conclusion to the answers: my actual process to prevent duplicates, delete history and clear:

Set-PSReadlineOption -HistoryNoDuplicates

Remove-Item (Get-PSReadlineOption).HistorySavePath

Alt-F7

like image 40
Cerlancism Avatar answered Oct 20 '22 04:10

Cerlancism