简体   繁体   中英

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?

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.

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM