我需要在Visual Studio代码中清除终端的内容。

每次我使用Maven时,终端的输出都会附加到以前的构建中,这让我感到困惑。

我如何清除终端窗口与一些命令或键盘快捷方式?

CLS不起作用;它只隐藏文本。


当前回答

使用Ctrl + K。这将在Visual Studio代码中清理控制台。

每个注释,在VSCode(1.29及以上)的后期版本中,这个快捷方式是缺失的/需要手动创建。

Navigate: File > Preferences > Keyboard Shortcuts search for workbench.action.terminal.clear If it has no mapping or you wish to change the mapping, continue; otherwise note & use the existing mapping Double click on this entry & you'll be prompted for a key binding. Hold CTRL and tap K. Ctrl + K should now be listed. Press enter to save this mapping Right click the entry and select Change when expression. Type terminalFocus then press enter. That's it. Now, when the terminal is in focus and you press Ctrl+K you'll get the behaviour you'd have expected to get from running clear/cls.

其他回答

在v1.32以上的版本见下面

这个命令的绑定仍然需要手动设置,即使是在v1.33.1,我也在v1.33.1。命令在Terminal:清除但绑定为空。下面介绍如何在v1.32及更高版本中设置绑定。

用Ctrl+K, Ctrl+S打开键盘快捷键。然后单击键盘快捷键选项卡旁边的{}打开键绑定。json文件。

这样做之后,在文件的任何地方找到一些开放的空间,并键入下面的键bind。

{
    "key": "ctrl+k",
    "command": "workbench.action.terminal.clear",
    "when": "terminalFocus"
}

为版本到v1.32见下面

我相信这是针对Visual Studio Code v1.18到v1.32的;我的版本是v1.29.1。显然,关于默认绑定有很多假设,下面介绍如何设置绑定,然后使用它。请记住,这个绑定也会完全删除终端中的所有历史记录。

用Ctrl+K, Ctrl+S打开键盘快捷键。进入键盘快捷键后,单击键盘绑定。Json在文本中表示....打开并编辑keybindings.json。然后在右边,在按键绑定中。Json,添加这个(如果已经有一个或多个绑定,请确保在第一个前面加上逗号):

{
    "key": "ctrl+k",
    "command": "workbench.action.terminal.clear",
    "when": "terminalFocus"
}

适用于所有版本

记住,“键”:可以是你想要的任何绑定。不一定是Ctrl + K。

要使用键绑定,必须在终端中有焦点,然后进行绑定。

粘贴此命令-

Remove-Item (Get-PSReadlineOption)。HistorySavePath

在你的powershell和启动新的powershell和它发现清除

欲了解更多详情,请查看此链接@ https://www.shellhacks.com/clear-history-powershell/

按Ctrl + Shift + P选择“Terminal:clear”

若要永久删除前面的命令,请使用此命令

Set-PSReadlineOption -HistoryNoDuplicates Remove-Item (Get-PSReadlineOption)。HistorySavePath Alt-f7

F1键打开快捷方式为我使用windows 10。然后输入Terminal,你会看到清晰的选项。