Live data from Hacker News

Keyboard shortcuts for GNU Readline

masteringemacs.org

91–100 of 174 posts

Re: Keyboard shortcuts for GNU Readline

#91
post #89

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 Linu…

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…

Very cool!

What keys do ~ and ^ represent?

    {
      "^w" = "deleteWordBackward:";
      "~f" = "moveWordForward:";
      "~b" = "moveWordBackward:";
      "~d" = "deleteWordForward:";
      "~" = "moveToEndOfDocument:";
      "~w" = "copy:";
      "^y" = "yank:";
      "^t" = "transpose:";
      "^p" = "moveUp:";
      "^n" = "moveDown:";
      "^u" = "deleteToBeginningOfLine:";
    }

Re: Keyboard shortcuts for GNU Readline

#92
post #68

Ctrl-R! Ctrl-R! Ctrl-R! How many people have been on a screen sharing call and watched the other person tediously up-arrow through 5-10 commands to try to rerun what they just did? The single greatest productivity boost you can gift a CLI newbie is searching their command history. Everyone jumps on the Emacs nav keys (C-f, C-b, etc) or other editing trivia. No one has trouble editing a command in place but it certain…

ctrl+r is great

so is modifying your inputrc so you can still use up arrows but filter the options by first typing a bit of text

i.e. $ find

tada:

    $if mode=emacs
    "\e[A": history-search-backward
    "\e[B": history-search-forward
    $endif

I do a bit more in that if block, but trimmed it down to make a point

Re: Keyboard shortcuts for GNU Readline

#93
post #3

Just enable vim mode (`set -o vi`) and call it a day.

This is actually encouraged by POSIX.

set -o vi: "Allow shell command line editing using the built-in vi editor. Enabling vi mode shall disable any other command line editing mode provided as an implementation extension."

No other mode, specifically emacs mode, is included in the POSIX standard.

Take from this what you will.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...

Re: Keyboard shortcuts for GNU Readline

#94
post #3

Just enable vim mode (`set -o vi`) and call it a day.

And add search support, if you're using zsh: https://github.com/soheilpro/zsh-vi-search

Every vi mode that I have ever used in any shell allows search with ESC-/ as the vi editor itself allows.

Re: Keyboard shortcuts for GNU Readline

#95
post #89

Earlier quoted context omitted.

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…

Very cool! What keys do ~ and ^ represent? { "^w" = "deleteWordBackward:"; "~f" = "moveWordForward:"; "~b" = "moveWordBackward:"; "~d" = "deleteWordForward:"; "~ " = "moveToEndOfDocument:"; "~w" = "copy:"; "^y" = "yank:"; "^t" = "transpose:"; "^p" = "moveUp:"; "^n" = "moveDown:"; "^u" = "deleteToBeginningOfLine:"; }

If it's anything like readline/Emacs, then:

^ = Control

~ = Escape

Re: Keyboard shortcuts for GNU Readline

#97
post #23
post #11

Knowledge like this used to spread naturally—physically sitting with a junior engineer, muscle memory would make any shortcut-fu gaps painfully clear. That’s not as visceral in remote pairing, and doesn’t show up at all in async processes like CR. Still, I try to at least share the “greatest hits”: ctrl-r: search backwards through command history ctrl-a: go to beginning of line ctrl-e: go to end of line If nothing el…

In ~20 years of professional programming, I have never explored much beyond these shortcuts, except for also using: * ctrl-left/ctrl-right to go back/forward word by word instead of char by char * ^C to cancel the current line

It's mentioned in the linked page, but not really explored: instead of `^C` (aka `C-c`, `Control-c`, &c) use `M-#` (aka `Alt-#` or `option-shift-3`) which adds a `#` before whatever you've typed on the current line and hits `return`, putting the line you're cancelling in the history as a comment so you can go back and `C-a C-d return` to submit it.

Re: Keyboard shortcuts for GNU Readline

#98

How to remember "Kill word backward/forward". Is there any mnemonic for C-w, M-d?

C-w is "wipe", and M-d is "delete".

C-d is also "delete" but one character. There are several Emacs combos where C- is for single characters and M- is for whole word, like C-f/M-f, C-b/M-b etc.

M-w also exists in Emacs proper but it's "wipe without delete" or in common parlance, "copy".

Post reply on HN