Hacker News new | ask | show | jobs
by CodeIsTheEnd 1292 days ago
For anyone using a Mac, the basic cursor movement commands available in readline and emacs—C-f, C-b, C-a, C-e, C-n, C-p—are also available in virtually any text input in any program, namely web browser inputs, url bars, and textareas, as well as all system UIs.

Once you get used to using these shortcuts that means you can compose and edit text anywhere without ever moving your hands.

I recently switched to using Linux full time for my job and it KILLS me that these shortcuts aren’t available outside of the terminal. I try to navigate to a search suggestion in Chrome using C-n and accidentally open three new windows. I try to add a sentence at the start of Slack message using C-a and accidentally highlight everything and delete it. I try to move my cursor up to edit a previous line using C-p and end up brining up a print dialogue. It’s breaking the muscle memory of my most basic interactions with the computer, and it sucks.

15 comments

Ugh this destroyed my productivity too for a while. I even wrote an entire blog post about my woes and different experiments to get back to getting consistent shortcuts across terminal and GUI apps here: https://alexdav.id/2020/07/12/text-manipulation-and-modifier.... GTK key themes didn't end up working out for me, and I ended up with a custom QMK solution, but it's not great.

Note for people still using macos, you can enable many more readline shortcuts by creating a special file at ~/Library/KeyBindings/DefaultKeyBinding.dict. I made a repo that simplifies the process to just a single git clone when setting up a new machine: https://github.com/alexdavid/keybindings

Very cool!

What keys do ~ and ^ represent?

    {
      "^w" = "deleteWordBackward:";
      "~f" = "moveWordForward:";
      "~b" = "moveWordBackward:";
      "~d" = "deleteWordForward:";
      "~<" = "moveToBeginningOfDocument:";
      "~>" = "moveToEndOfDocument:";
      "~w" = "copy:";
      "^y" = "yank:";
      "^t" = "transpose:";
      "^p" = "moveUp:";
      "^n" = "moveDown:";
      "^u" = "deleteToBeginningOfLine:";
    }
If it's anything like readline/Emacs, then:

^ = Control

~ = Escape

In this file `~` is meta (option key on macs). Not sure why it's not escape like it is in emacs.
Because on a particular three/four-decade-old physical terminal[0], Alt-$KEY was transmitted as "1B [sequence for $KEY]". Eg, Alt-X was "1B 58"[1]. The escape key happened to also transmit "1B" on its own. Consequently, "Alt-$KEY" and "Esc, $KEY" were indistinguishable unless you went out of your way to engineer a race condition. This has never really been fixed, despite intermittent attempts.

0: I think VT100, but don't quote me on that

1: or possibly "1B 78", depending on how it handled shift; I don't remember exactly.

On Linux, Meta is activated on modern keyboards by both ESC and ALT.
Also on macOS and (at least within emacs) Windows.
I’m not sure about other OSs, but having cmd for standard mac shortcuts and ctrl for all things Linuxy is really useful in general. As you point out, loads of apps support the standard readline controls. I additionally wire ctrl-p / ctrl-n to be more generally useful in Linux and vim, but I find that they just work all over the place in Mac apps too (up / down in Alfred search results for example).
You can enable "Emacs bindings" in a bunch of applications. Enabling that in GTK would let you use the cursor movement keys in Chrome and Firefox.

https://askubuntu.com/a/1280532

Unfortunately, GTK 4 has removed key themes. Eventually, Firefox, Chrom(e|ium) and all actual GTK applications will migrate to GTK 4, so this is not very future-proof.

I use a variant of the emacs key theme, so I'd be happy if there were a workaround...

It's unfortunate that the GTK devs feel they have to remove features which their users find useful to keep GTK maintainable. Keeping software complexity under control is a difficult task, and I can't begrudge them their choice.
You are a hero and have just cured me of a hundred daily paper cuts. My employer should give you a bonus.

It works in Chrome, but unfortunately not in the standalone Slack client. (Maybe an argument for switching to the web version?)

(Uh, does anyone know how I select all (previously C-a) or search (previously C-f) in Chrome now??)

EDIT: Looks like C-/ functions as select all, still looking for a find replacement.

EDIT #2: Oh, silly me, as long as I'm not focused on an input, C-f still works.

> “I try to move my cursor up to edit a previous line using C-p and end up brining up a print dialogue.

I used to be a big enthusiast of keyboard shortcuts, now I’m getting fed up of how many there are, every program has a zillion shortcuts all stacked on top of each other. Someone needs to come up with a better way (cough Jeff Raskin THE?).

This one is notably egregious, hands up anyone who prints often enough to need a keyboard shortcut; someone who prints as often as they new-tab, as often as they Ctrl-s a text file, as often as they copy/paste? Anyone? If only there was a universal way to unbind them.

In KDE one can unbind Ctrl-P from print for all KDE apps, from the web browser to the PDF reader to the mail client.
On Mac Os you can also add some other ones that are not enabled by default, there's various write ups on how to do this.

https://irreal.org/blog/?p=259

I really missed C-w for delete word personally.

There's also a vim plugin by tim pope that adds a few readline keys that don't clash.

https://github.com/tpope/vim-rsi

And if you use the fish shell you can have both vi and Emacs shortcuts activated at the same time for the best of both worlds.

Until you get used to C-w in any text box, and then randomly close browser tabs (ff on Linux) because muscle memory.
Opening the Firefox console with Shift+Ctrl+C is my particular habit. Of course the shortcuts aren't configurable, it's 2022.
Seems quite cool - I don't suppose you have a copy of the .dict file linked in that blog post? the link is 503 :\
There's a link in the comments to it.

https://github.com/jrus/cocoa-text-system/blob/master/KeyBin...

Though I just have:

    "^w"   = "deleteWordBackward:";                            /* C-W        Delete word backward */
Missed that - thanks :)
I switched to Mac full time when I got frustrated with my Linux desktop having (far) worse support for Emacs keybindings than my work Mac. There was a certain amount of irony in it.
If we are doing a survey.

Firefox on openbsd uses the emacs keybindings.

And just checked, it looks like chrome on openbsd uses the emacs keybindings as well. it just reinforces my feeling that openbsd makes the best desktop system.

Anyone using a Mac is probably not using readline but its replacement 'editline'.

So the configuration file is ~/.editrc.

man editrc

Note also that to have a full mapping of keys available to you, you have to be aware of the tty settings (see stty), the terminal emulator and the GUI environment in which it is running. I would appreciate a tool that would dump all this in a comprehensive list.

Don't confuse Mac's Ctrl with Ctrl on Win/Linux. Mac's equivalent to non-Mac's Ctrl is Cmd.
You find these all over the place[0]; I often try them and am unsurprised when they work. Have to train myself not to use ^w though. Try to erase word and it closes the window.

[0] for example in the quakelive console

C-a, C-k are probably my most used shortcuts on the mac
My favorite is that those can combined with the shift key, to get native highlighting. So Ctrl-Shift-a works like Shift-Home on windows (and Ctrl-Shift-e for Shift-End).

So you can do C-s-a and C-s-e, followed by cmd-C, to copy stuff to the native clipboard.

(Kill and yank (C-k and C-y) work too, but not across applications.)

keyd is a really nice key remapping daemon that supports application-specific remappings. You could use it to emulate readline bindings in Chrome. Or if you can't figure out how to emulate something, at least bind it to noop so it doesn't mess you up any more.

https://github.com/rvaiya/keyd

On a linux desktop you can have this in GTK applications with the "gtk-key-theme 'Emacs'" settings.
X11 supports all of this with user configurability but the cool kids threw all of it away.
Command-A isn’t available on Linux in slack?

How do people even function without basic function keys?

Let me introduce you to the Home key: https://en.wikipedia.org/wiki/Home_key
I've always pried this key and other useless keys off my keyboards. TIL.
Command-A does select all. On Linux if you use defaults, ctrl+A will do that. If you change your gtk keyboard shortcut theme to ‘emacs’ it will do the equivalent of ‘home’ instead (which is what ctrl-A does on a Mac). To delete a message under these conditions, you can usually do e.g. C-A C-K. But that’s not so suitable for eg a high-risk text box on a buggy site where you want to regularly select all then copy in case the site crashes or loses your data.
Doesn't ctrl+/ select all in either GTK key theme?