Cerlancism
Cerlancism

Reputation: 3174

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?

Upvotes: 13

Views: 28125

Answers (6)

Rafael Neto
Rafael Neto

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:

  1. Press the Windows key + R at the same time to launch the Run dialog.
  2. Copy and paste the following path: %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline
  3. Press Enter.
  4. The File Explorer will open the specified path.
  5. Edit the ConsoleHost_history.txt and Visual Studio Code Host_history.txt files manually to remove specific lines or all the content.

Upvotes: 6

HLTC
HLTC

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

Mark
Mark

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

Cerlancism
Cerlancism

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

matt9
matt9

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

Related Questions