Hacker News new | past | comments | ask | show | jobs | submit login

I’d just settle for macOS’ Terminal.app’s ⌘-K, that resets the terminal, and clears all the screen including scroll back window. Something so basic I have it in muscle memory but I haven’t found the equivalent in Linux terminals.



A lot of people swear by stuff like iTerm2, but I'm almost a little ashamed to admit that even though I have iTerm configured to my taste, I often still reach for macOS' native terminal. It's not gloriously beautiful or anything (basic Zsh with powerline for the shell), but it just seems to work great without the frills.

Little shortcuts that think of stuff like this without any configuration (iTerms is impressively extensive) are just a cherry on top. It kind of bums me out that's not linux native. Do you know of any other useful shortcuts specific to macOS? I've been using ctrl+L for the longest time. Thank you for sharing!


> A lot of people swear by stuff like iTerm2

Actually, I've been using Terminal for years. I usually try to use default apps as much as possible (Safari, Mail, Notes, Terminal) to reduce configuration overhead. I switched to iTerm2 a few days ago after reading an article on HN... not sure if it worth the change, but haven't tried anything fancy yet. What would be the killer feature of iTerm2?


Drop down with global shortcut (I use control + ‘)

https://www.marcjenkins.co.uk/drop-down-terminal-with-iterm2...


For me it is its integration with tmux, and therefore being able to use the command line in a remote computer as if you were using it locally.


I just use tramp for this.


I use profile triggers to change the color scheme of the shell when I SSH to a production server. The color I chose is different from my regular scheme so that it reminds me I am in production and things can break if I'm not careful.


I'm sort of in the opposite camp — I remember there being a non-trivial reason for moving over to iTerm several years ago, but now it's just become a habit and I can't for the life of me remember why I'm using it still.

As for shortcuts — ctrl-K (kill line), ctrl-A (go to start of line), ctrl-E (end of line) are my bread and butter, and work with most shells.


One thing I loved about Macs, even though I haven't used one in years, was that you could use Emacs keybindings with the control key and "standard" keybindings with the command key. Being able to type both C-c and ⌘-c was nice.


Definitely, having readline shortcuts available more or less across the whole OS is a godsend.


Since cmd+<number> now switches tab in Terminal.app, and the other few things I like, such as remembering the scrollbacks, number of tabs and cwd's, I find I have no use of iTerm2 any longer.

Plus, Terminal.app feels much faster. Using terminal Emacs feels very different in the two terminals.


Plus, Terminal.app feels much faster. Using terminal Emacs feels very different in the two terminals.

I recently switched back to Terminal from iTerm, and was amazed by the speed increase.

When entering commands, it is visibly a little "snappier." But where it really shines is in the output.

I have a few of batch processes that I have to run once a week, and they're all pretty heavy on the debug output, with lots of VT100 eye candy. One process that used to take close to six hours in iTerm got significantly shaved when I switched to Terminal.

Since I only run this once a week, I haven't had a chance to benchmark it, but my guess is that Terminal shaved 40 minutes off the job.

The only thing I miss from iTerm is having two sessions open in a single window. I suspect this is possible in Terminal, but I haven't figured it out yet. When I click the "Split Pane" button, I get two panes of the same session, instead of a new session in the new pane.


The fact that Ternimal.app and iTerm2 use different keyboard shortcuts for clearing scrollback buffer (⌥⌘K vs ⇧⌘K) is a constant frustration of my spotty use of Terminal.app. I would instinctively hit the iTerm2 shortcut, which brings up a connect to server panel or something.


You can use System Preferences (Keyboard -> Shortcuts, “App Shortcuts” in the list) to change any binding in any menu item in any app. In this case you could force both apps to use the same keys for those commands.


Good point. I used that feature in the past but somehow haven’t touched it in years.


> The fact that Ternimal.app

That typo has a nice program of its own: https://github.com/p-e-w/ternimal


I don’t even install any other terminal. I just update bash to latest and stick to stock terminal. I have come to believe that often tool overload adds to the clutter and complexity and problems that didn’t need solving in the first place.


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.


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.


It's also super helpful when you want to run one command which spews out a bunch of errors, and then read the first error. Cmd-K, enter, and fling up the the trackpad. I think I'd have to pipe to less if I don't have cmd-K.


Cmd up and down navigates between prompts, so you don’t even have to scroll


I tried this and it even worked within the sqlite3 session I have open, very nice.


This changes everything!


printf "\033c"? I don't know if it resets, but it does clear the scroll buffer. I use it before compiling (printf "\033c"; make) so that I don't have to search for the first error or warning, I can just scroll all the way up.


Can substitute a forward slash for the 0 and remove the quotes

   printf \\33c
Another way is to use a program that converts hex to binary. A short script to use when there is no clear, tput, etc, e.g., xxd or nc-data

   exec echo 1b63 |exec xxd -p -r

   echo -e '27\n99\n' |exec nc-data -g

   exec echo |exec sed '1i\
   27 \
   99 

   ' |exec nc-data -g


\ is a backslash

/ is a forward slash, a.k.a. simply “slash”


Not sure why I always get this wrong. Maybe it is because when I draw these characters on a surface, I start from the top not the bottom. Hence the line goes forward for a "backslash" and backward for a "forward slash". What is the etymology of these terms?

Probably better to just use "escape" for backslash and "slash" for forward slash.


As I said elsewhere in this discussion, use DECSTR instead of RIS unless you really need all of the things that RIS does to actual terminals, like performing selftests and resetting the serial connection. Habitual use of RIS is a bad habit to get into.


On iTerm, that clears everything visible on the screen, but not the scroll history.

Sounds like your terminal clears everything? vt100 variants are a, uh, delightful mix of nearly-compatible dialects...


KDE's Konsole has it at CTRL+ALT+K by default.

The command "tput clear" should work everywhere though. And frankly, while obviously more work than a keyboard shortcut, it's not that much of an effort.


Use clear and the flush_scrollback escape:

  $ clear; printf '\e[3J'
(edit: whoops wrong URL, sorry https://apple.stackexchange.com/a/113168 )

https://unix.stackexchange.com/a/530146


I use this too but on linux, I am constantly hitting cmd-k and control-l in a sort of futile attempt to reset the screen correctly.

I think this needs a solution -- a keymapping and a function that resets the terminal need to be consciously united.

actually, I think I need a full set of keystrokes for linux. Somehow on ubuntu pressing the command key leads to all the windows rearranging like expose on mac.

sigh.


You can make your life easier on macOS by aliasing the `⌘-K` shortcut, as in: https://github.com/kdeldycke/dotfiles/blob/23ac0cd2a6c944242...


When I switched from macOS to Linux, not having ⌘-K really bugged me.

However I found out that most terminal emus on Linux also have this feature as Ctrl-L.

In gnome-terminal you have to press Ctrl-K to clear the screen, and then Ctrl-L to redraw the prompt.

The bash manual documents Ctrl-L as "Clear the screen leaving the current line at the top of the screen."


Is it possible to bring it back? I’ve pressed it accidentally on server window and lost the whole svr output ( I know I could look at logs but it would still be nice to quickly bring back stdout)


Whoa, someone downstream says `reset` clears scrollback.


Konsole has that since forever.


You don't know ctrl+L?


It looks like you're getting downvoted without explanation: Ctrl+L doesn't clear the scrollback, it just scrolls the terminal down.


Alacritty clears with Ctrl-L, out-of-the-box.

Also, from `man bash`...

> clear-screen (C-l) Clear the screen leaving the current line at the top of the screen. With an argument, refresh the current line without clearing the screen.


Also, Terminal.app seems to implement almost as many extensions as XTerm, and does them pretty well.

It's too bad it's so slow though (in terms of throughput, that is; latency is pretty okay).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: