Reputation: 3174
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?
Upvotes: 13
Views: 28125
Reputation: 1290
If you are using the VS Code PowerShell terminal you can clear the entire history of the terminal or even specific lines with these steps:
Upvotes: 6
Reputation: 71
In Windows platform press and hold ctrl+shift+P, in the pop up window write terminal:clear
, you'll get it shown, assign shortcut key (crtl+K) for example and hit enter. Now every time you want to clear the terminal you can use the hotkey you just created.
Do the same in Mac but using cmd+shift+P instead.
Upvotes: 7
Reputation: 182941
In v1.65 there will be this command:
workbench.action.terminal.clearCommandHistory
"Clear Command History"
In v1.65 there will also be a new setting:
terminal.integrated.shellIntegration.history
"Controls the number of recently used commands to keep in the terminal command history. Set to 0 to disable terminal command history."
I suppose to clear the terminal history you could set this to 0 (100 is the default), reload (I'll test this tomorrow to see if a reload is necessary, it may not be) and then reset the limit to 100 or whatever you want.
Upvotes: 1
Reputation: 3174
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
Upvotes: 4
Reputation: 703
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.
Upvotes: 2
Reputation: 1999
the Cmdlet Clear-History
should do what you want https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Clear-History?view=powershell-6
Upvotes: 0