Hacker News new | ask | show | jobs
by capn_cabbage 2300 days ago
I am currently using Fedora 31 Cinnamon which uses GNOME Terminal and the shortcut to reset and clear screen/scrollback is CTRL+L. I am not sure if this shortcut is standard on GNOME Terminal or not, but it's present in this flavor.

EDIT: On my windows machine I think it is ALT+F8 in Git Bash. May be similar in other terminal emulators.

2 comments

CTRL-l is a standard "clear the screen" keystroke, and should work in all terminals, but it does not necessarily clear the scrollback buffer. Since "scrollback" is something implemented by the emulator itself, you'll have to look up how to do it there.

I use konsole, and it's CTRL-SHIFT-k there by default, I believe. I just ran gnome-terminal, and I see in Edit -> Preferences -> Terminal -> Reset and Clear that you can give it a shortcut key but it does not appear to ship with one configured by default.

The reset command should clear the scrollback buffer. On older terminals where you'd get a garbled screen if you accidentally cat a binary file, it will give you your ASCII back.
Trying it just now on konsole, it does not. Whether that's because your terminal is following standards or because your terminal is interpreting a terminal command that doesn't actually say anything about scrollback to also clear scrollback, I don't know, and await anyone who does to answer that question.

My gut is that the terminal protocol would know nothing about scrollback and thus not have a "clear scrollback" command in it directly. There are plenty of other indications that scrollback is basically a hack.

[Konsole] Settings -> Configure Keyboard Shortcuts ... "Clear Scrollback and Reset". On my Arch boxes it is mapped to Ctrl + Shift + k. That's probably a default from upstream.
Tried it on konsole 19.12.2 (on Arch), it works for me.
Your "gut" is wrong. It's ED 3.
It's a common feature, but not formally standardized.

ED 3 isn't actually in the [ECMA-048] spec.

It was an xterm feature introduced in June 1999. Several terminal developers later adopted the feature. In April 2011, a Red Hat developer submitted a patch to the Linux kernel, modifying its console driver to do the same thing.

So it's not a formal standard, but it's universal on Linux since 3.0 and many terminal emulators have adopted it.

This history is covered in [clear(1)] from the ncurses project.

[ECMA-48]: http://www.ecma-international.org/publications/files/ECMA-ST...

[clear(1)]: http://man7.org/linux/man-pages/man1/clear.1.html#HISTORY

EDIT: Fix wording and formatting.

... none of which contradicts the point that the protocol does know about scrollback. The aforementioned developer, Petr Písař, got the implementation wrong, note.

* https://unix.stackexchange.com/a/375784/5132

* http://jdebp.uk./Softwares/nosh/guide/commands/setterm.xml

Reset takes at least a couple seconds though, I’m not sure I’d swap it with clear in something like:

    clear && make test
I may have changed the key binding after installation. It has been a while so it feels like it has always been that way.
It's actually an Emacs keybinding, that was added to GNU readline, which is used by Bash; most shells followed suit (either by using readline, or implementing it themselves).

Ctrl + l is in Bash, in your case.

While many of the readline keybindings come from Emacs, I would have said the common shell handling of Ctrl-L comes from that ^L is ASCII form-feed, which is "clear the page; start a new page" (in the same way that ^H is ASCII backspace).

I hadn't considered Bash C-L to be the same as Emacs C-L, since in Emacs I can hit C-L again to "undo" it (kinda).

C-l doesn't clear anything in it's default behavior right? It changes the line-at-poit to be at the center of the screen, bottom, or top, depending on how often yoi press it.

I would never have associated that with screen clear.

E: excuse me, of course C-l does the same scrolling in the terminal, it doesn't clear the history of course.