Add a terminal-side shortcut for clearing the screen and/or scrollback #2654

Closed
opened 2026-01-30 23:01:21 +00:00 by claunia · 31 comments
Owner

Originally created by @prumbles on GitHub (Jul 8, 2019).

It would be great to have the equivalent of Command+K on the Mac terminal. This clears the terminal completely, not the equivalent of typing "clear", which only scrolls the cursor to the top of the terminal. My use case is the following:

  • Open an Ubuntu terminal
  • ssh into a server
  • run a command which may produce large amounts of content and exceptions within the content
  • fix the exceptions by making a code change
  • CLEAR the terminal completely (not just a "clear" command)
  • re-run the command
  • now that the previous command output was cleared, we can search for new exceptions without getting the previous exceptions
  • NOTE: this also requires a "ctrl+F" type feature to exist in the terminal, which currently does not
Originally created by @prumbles on GitHub (Jul 8, 2019). It would be great to have the equivalent of Command+K on the Mac terminal. This clears the terminal completely, not the equivalent of typing "clear", which only scrolls the cursor to the top of the terminal. My use case is the following: - Open an Ubuntu terminal - ssh into a server - run a command which may produce large amounts of content and exceptions within the content - fix the exceptions by making a code change - CLEAR the terminal completely (not just a "clear" command) - re-run the command - now that the previous command output was cleared, we can search for new exceptions without getting the previous exceptions - NOTE: this also requires a "ctrl+F" type feature to exist in the terminal, which currently does not
Author
Owner

@mdtauk commented on GitHub (Jul 8, 2019):

Why just clear screen? Why not a toolbar where common commands can be added as quick shortcuts?

@mdtauk commented on GitHub (Jul 8, 2019): Why just clear screen? Why not a toolbar where common commands can be added as quick shortcuts?
Author
Owner

@prumbles commented on GitHub (Jul 9, 2019):

But, this isn't a bash command, as I think that's what you are asking. Command+K on a mac doesn't run any commands in the terminal such as "clear"... it clears the entire terminal buffer. Commands such as "clear" don't do the equivalent. I personally don't need a toolbar - I'm fine with adding them to the "Settings.json" file like all the other keyboard shortcuts. Its just that "Clear terminal" is not one of the available options to create a shortcut for. If you use VSCode, the exact equivalent command is "Terminal:Clear". I map that to Alt+K to get the same experience.

@prumbles commented on GitHub (Jul 9, 2019): But, this isn't a bash command, as I think that's what you are asking. Command+K on a mac doesn't run any commands in the terminal such as "clear"... it clears the entire terminal buffer. Commands such as "clear" don't do the equivalent. I personally don't need a toolbar - I'm fine with adding them to the "Settings.json" file like all the other keyboard shortcuts. Its just that "Clear terminal" is not one of the available options to create a shortcut for. If you use VSCode, the exact equivalent command is "Terminal:Clear". I map that to Alt+K to get the same experience.
Author
Owner

@fzed51 commented on GitHub (Jul 11, 2019):

Are we not talking about the same thing as issue # 1189 ?

@fzed51 commented on GitHub (Jul 11, 2019): Are we not talking about the same thing as issue # 1189 ?
Author
Owner

@zadjii-msft commented on GitHub (Jul 11, 2019):

@fzed51 Nope, this is unrelated to that one.

To clarify for future me - cmd+k is not something that's being handled by bash or the shell. This is the Terminal itself handling the keybinding, and clearing both the buffer and the scrollback.

You've described a user story that makes sense to me, so I'm gonna put this on the backlog.

  • We'd probably want #1142 to be able to support adding keybindings for Clear Screen, Clear Scrollback, or Clear Both all on the same "clear" action.
  • We'll need #1193 for clearing the conpty buffer. W/o this, we'll just get the screen repainted immediately.
@zadjii-msft commented on GitHub (Jul 11, 2019): @fzed51 Nope, this is unrelated to that one. To clarify for future me - <kbd>cmd</kbd>+<kbd>k</kbd> is not something that's being handled by `bash` or the shell. This is the Terminal itself handling the keybinding, and clearing both the buffer and the scrollback. You've described a user story that makes sense to me, so I'm gonna put this on the backlog. * We'd probably want #1142 to be able to support adding keybindings for Clear Screen, Clear Scrollback, or Clear Both all on the same "clear" action. * We'll need #1193 for clearing the conpty buffer. W/o this, we'll just get the screen repainted immediately.
Author
Owner

@eduardonunesp commented on GitHub (Jan 7, 2020):

I would like to help with that if possible, shouldn't be so difficult right? I mean can be just reset the buffer and initialize again the buffer

@eduardonunesp commented on GitHub (Jan 7, 2020): I would like to help with that if possible, shouldn't be so difficult right? I mean can be just reset the buffer and initialize again the buffer
Author
Owner

@DHowett-MSFT commented on GitHub (Jan 7, 2020):

You should definitely read the comments here. Because of the windows console infrastructure we’re built on it’s not quite that easy.

@DHowett-MSFT commented on GitHub (Jan 7, 2020): You should definitely read the comments here. Because of the windows console infrastructure we’re built on it’s not quite that easy.
Author
Owner

@eduardonunesp commented on GitHub (Jan 7, 2020):

Ok, I don't have any idea about the internals of the terminal, however, if in order to clear a buffer after press a key combination is so complex probably it will be impossible to scale the product when adding more complex stuff than this

@eduardonunesp commented on GitHub (Jan 7, 2020): Ok, I don't have any idea about the internals of the terminal, however, if in order to clear a buffer after press a key combination is so complex probably it will be impossible to scale the product when adding more complex stuff than this
Author
Owner

@DHowett-MSFT commented on GitHub (Jan 7, 2020):

It's just this issue in particular that's thornier than most. For compatibility with Windows console applications that do not expect a terminal to be connected, we need to maintain a text buffer for them to read. That's all. Because we don't have a way to clear that text buffer (from the terminal side), and we just haven't written one yet, it's only more complex than clearing the local screen. It's not a complexity class issue with all of Terminal.

@DHowett-MSFT commented on GitHub (Jan 7, 2020): It's just this issue in particular that's thornier than most. For compatibility with Windows console applications that do _not_ expect a terminal to be connected, we need to maintain a text buffer for them to read. That's all. Because we don't have a way to clear that text buffer (from the terminal side), and we just haven't written one yet, it's only more complex than clearing the local screen. It's not a complexity class issue with all of Terminal.
Author
Owner

@eduardonunesp commented on GitHub (Jan 7, 2020):

Gotcha, thanks for the clarification, definitely isn't a beginners task

@eduardonunesp commented on GitHub (Jan 7, 2020): Gotcha, thanks for the clarification, definitely isn't a beginners task
Author
Owner

@xoofx commented on GitHub (Jan 21, 2020):

I'm discovering this while switching to this terminal and this is really annoying.
I was previously using cls to clear not only the screen but also the history, when you are using the same terminal for hours, and you are running commands that can generate errors, scrolling back is making things very difficult to spot which command is failing (when the errors can span on several pages), the sensitivity of the scroll is making too easy to scroll back to a previous command without noticing.

So big 👍 for a keystroke as I understand that cls is not meant for the history.

Thinking about it, also, as a nice improvement, maybe it is something that has a feature request on its own, but a "bird-view" side pane on the right side where we could spot easily where commands are and where are the outputs would be also super useful...

@xoofx commented on GitHub (Jan 21, 2020): I'm discovering this while switching to this terminal and this is really annoying. I was previously using `cls` to clear not only the screen but also the history, when you are using the same terminal for hours, and you are running commands that can generate errors, scrolling back is making things very difficult to spot which command is failing (when the errors can span on several pages), the sensitivity of the scroll is making too easy to scroll back to a previous command without noticing. So big 👍 for a keystroke as I understand that `cls` is not meant for the history. Thinking about it, also, as a nice improvement, maybe it is something that has a feature request on its own, but a "bird-view" side pane on the right side where we could spot easily where commands are and where are the outputs would be also super useful...
Author
Owner

@DHowett commented on GitHub (May 27, 2020):

Don’t do that. It emails every subscriber to this issue or to this repository. We know that you want this fixed, somebody just needs to do the work.

@DHowett commented on GitHub (May 27, 2020): Don’t do that. It emails every subscriber to this issue or to this repository. We know that you want this fixed, somebody just needs to do the work.
Author
Owner

@vamsi360 commented on GitHub (May 31, 2020):

@prumbles
If you are running WSL2, you can run:
tput clear
This does reset the terminal buffer fully without scrollback.

@vamsi360 commented on GitHub (May 31, 2020): @prumbles If you are running WSL2, you can run: `tput clear` This does reset the terminal buffer fully without scrollback.
Author
Owner

@tommyZZM commented on GitHub (Aug 8, 2020):

@prumbles
If you are running WSL2, you can run:
tput clear
This does reset the terminal buffer fully without scrollback.

both tput clear and celar can't clear while the process is outputing texts to the screen

I want a hotkey to clear the buffer. like ctrl+K in the macOS terminal

@tommyZZM commented on GitHub (Aug 8, 2020): > @prumbles > If you are running WSL2, you can run: > `tput clear` > This does reset the terminal buffer fully without scrollback. both `tput clear` and `celar` can't clear while the process is outputing texts to the screen I want a hotkey to clear the buffer. like `ctrl+K` in the macOS terminal
Author
Owner

@kimlym commented on GitHub (Aug 20, 2020):

So find seems be there with ctrl+shift+F, hopefully we will get the ctrl+shift+K soon

@kimlym commented on GitHub (Aug 20, 2020): So find seems be there with `ctrl+shift+F`, hopefully we will get the `ctrl+shift+K` soon
Author
Owner

@swinder0161 commented on GitHub (Sep 9, 2020):

I upvote the need
This is really a needed a feature while I am running logcat on an android device and want to start seeing the log when I start my app

@microsoftopensource please prioritize this.

@swinder0161 commented on GitHub (Sep 9, 2020): I upvote the need This is really a needed a feature while I am running logcat on an android device and want to start seeing the log when I start my app @microsoftopensource please prioritize this.
Author
Owner

@mt33 commented on GitHub (Sep 30, 2020):

Adding my support for this feature!

@mt33 commented on GitHub (Sep 30, 2020): Adding my support for this feature!
Author
Owner

@swinder0161 commented on GitHub (Oct 8, 2020):

All related issues are being closed by admins by mentioning this one, but there is no activity on this issue,

@microsoftopensource @zadjii-msft How to prioritize this development?

@swinder0161 commented on GitHub (Oct 8, 2020): All related issues are being closed by admins by mentioning this one, but there is no activity on this issue, @microsoftopensource @zadjii-msft How to prioritize this development?
Author
Owner

@zadjii-msft commented on GitHub (Oct 9, 2020):

If you want to help prioritize this feature, you can hit that 👍 button on the OP, which will avoid sending an unnecessary ping to everyone that's subscribed to this thread 😉
image

@zadjii-msft commented on GitHub (Oct 9, 2020): If you want to help prioritize this feature, you can hit that 👍 button on the OP, which will avoid sending an unnecessary ping to everyone that's subscribed to this thread 😉 ![image](https://user-images.githubusercontent.com/18356694/95562996-79767f80-09e2-11eb-9bcc-5f3bdbac0fee.png)
Author
Owner

@jijiechen commented on GitHub (Nov 8, 2020):

On my terminal, it worked by input tput reset
But tput clear did not work.

@jijiechen commented on GitHub (Nov 8, 2020): On my terminal, it worked by input `tput reset` But `tput clear` did not work.
Author
Owner

@csabka commented on GitHub (Mar 14, 2021):

I have created a workaround which worked on WSL/bash, SSH/bash (Linux tested) and PowerShell 7 for me with CTRL+ALT+K:

{ "command": { "action": "sendInput", "input": "\u001B[H#\rtput reset || printf '\e[1J\e[3J\e[r'|| Clear-Host\r\u001B[A\u001B[A\u001B[H\u001B[3~\u001B[F" }, "name":"Clear screen and Scrollback", "keys": "ctrl+alt+k" },

These steps will done with sendInput action:

  1. send home key (if you already type something into shell)
  2. send # (comment out what you have already typed)
  3. send return (save commented out strings to history note: \n : only work on linux so I used \r)
  4. send tput reset or printf with CSI codes (if tput command fails) or Clear-Host (if both commands failed: eg in PowerShell)
  5. send two times up key for history (needs to have history in shells)
  6. send home key
  7. send delete key to remove first character "#" from the beginning (written by step 2.)
  8. send end key to put cursor back to the end (you can continue typing of the command)

For me the history and scrollback are cleared

@csabka commented on GitHub (Mar 14, 2021): I have created a workaround which worked on WSL/bash, SSH/bash (Linux tested) and PowerShell 7 for me with CTRL+ALT+K: { "command": { "action": "sendInput", "input": "\u001B[H#\rtput reset || printf '\\e[1J\\e[3J\\e[r'|| Clear-Host\r\u001B[A\u001B[A\u001B[H\u001B[3~\u001B[F" }, "name":"Clear screen and Scrollback", "keys": "ctrl+alt+k" }, These steps will done with sendInput action: 1. send home key (if you already type something into shell) 2. send # (comment out what you have already typed) 3. send return (save commented out strings to history note: \n : only work on linux so I used \r) 4. send tput reset or printf with CSI codes (if tput command fails) or Clear-Host (if both commands failed: eg in PowerShell) 5. send two times up key for history (needs to have history in shells) 6. send home key 7. send delete key to remove first character "#" from the beginning (written by step 2.) 8. send end key to put cursor back to the end (you can continue typing of the command) For me the history and scrollback are cleared
Author
Owner

@mia-riezebos commented on GitHub (Mar 24, 2021):

open a second tab?

@mia-riezebos commented on GitHub (Mar 24, 2021): open a second tab?
Author
Owner

@carlosmunozrodriguez commented on GitHub (Mar 24, 2021):

open a second tab?

I have a running process that is logging to the console, but since it is logging too much things and I just want to concentrate in newer lines I just want to clear the screen so new lines don't get confused with older ones.

A new tab doesn't work for this case

@carlosmunozrodriguez commented on GitHub (Mar 24, 2021): > open a second tab? I have a running process that is logging to the console, but since it is logging too much things and I just want to concentrate in newer lines I just want to clear the screen so new lines don't get confused with older ones. A new tab doesn't work for this case
Author
Owner

@tommiv commented on GitHub (Mar 24, 2021):

Second tab doesn't work for many cases. SSH sessions, tail -f, long CWD you don't want to type again and again – to start with.

@tommiv commented on GitHub (Mar 24, 2021): Second tab doesn't work for many cases. SSH sessions, tail -f, long CWD you don't want to type again and again – to start with.
Author
Owner

@chilipepper987 commented on GitHub (Jun 13, 2021):

Any updates on this? Still annoying that there is no clear scrollback option. That's the only thing stopping me from uninstalling MobaXTerm

@chilipepper987 commented on GitHub (Jun 13, 2021): Any updates on this? Still annoying that there is no clear scrollback option. That's the only thing stopping me from uninstalling MobaXTerm
Author
Owner

@astraw commented on GitHub (Jun 13, 2021):

Others have noted that the command cls is not a perfect solution but for me it has reduced the issue to background noise and I am happy to have rediscovered cls (after approximately 30+ years -- I think I used to use it in DOS if I remember correctly).

@astraw commented on GitHub (Jun 13, 2021): Others have noted that the command `cls` is not a perfect solution but for me it has reduced the issue to background noise and I am happy to have rediscovered `cls` (after approximately 30+ years -- I think I used to use it in DOS if I remember correctly).
Author
Owner

@zadjii-msft commented on GitHub (Jul 29, 2021):

There are other details in #1193 for those interested in the technical bits.

For everyone else who's just here for results:
clear-buffer-000

@zadjii-msft commented on GitHub (Jul 29, 2021): There are other details in #1193 for those interested in the technical bits. For everyone else who's just here for results: ![clear-buffer-000](https://user-images.githubusercontent.com/18356694/127570078-90c6089e-0430-4dfc-bcd4-a0cde20c9167.gif)
Author
Owner

@VanilsonFernandes commented on GitHub (Jul 30, 2021):

There are other details in #1193 for those interested in the technical bits.

For everyone else who's just here for results:
clear-buffer-000

Nice work! This works while running a "ping google.com -t"?

Thanks

@VanilsonFernandes commented on GitHub (Jul 30, 2021): > There are other details in #1193 for those interested in the technical bits. > > For everyone else who's just here for results: > ![clear-buffer-000](https://user-images.githubusercontent.com/18356694/127570078-90c6089e-0430-4dfc-bcd4-a0cde20c9167.gif) Nice work! This works while running a "ping google.com -t"? Thanks
Author
Owner

@KaoruDev commented on GitHub (Sep 21, 2021):

I'm sort of confused, I'm hitting ctrl+shift+p to pull up the command menu, but I can't seem to find Clear buffer? I'm on version: 1.10.2383.0

@KaoruDev commented on GitHub (Sep 21, 2021): I'm sort of confused, I'm hitting `ctrl+shift+p` to pull up the command menu, but I can't seem to find Clear buffer? I'm on version: `1.10.2383.0`
Author
Owner

@DHowett commented on GitHub (Sep 21, 2021):

1.12 should be the first version that has this feature.

@DHowett commented on GitHub (Sep 21, 2021): 1.12 should be the first version that has this feature.
Author
Owner

@KaoruDev commented on GitHub (Sep 21, 2021):

1.12 should be the first version that has this feature.

ah got it, thank you! can't wait!

@KaoruDev commented on GitHub (Sep 21, 2021): > 1.12 should be the first version that has this feature. ah got it, thank you! can't wait!
Author
Owner

@ghost commented on GitHub (Oct 20, 2021):

:tada:This issue was addressed in #10906, which has now been successfully released as Windows Terminal Preview v1.12.2922.0.🎉

Handy links:

@ghost commented on GitHub (Oct 20, 2021): :tada:This issue was addressed in #10906, which has now been successfully released as `Windows Terminal Preview v1.12.2922.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.12.2922.0) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2654