Live data from Hacker News

Keyboard shortcuts for GNU Readline

masteringemacs.org

101–110 of 174 posts

Re: Keyboard shortcuts for GNU Readline

#101
post #23

Earlier quoted context omitted.

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

If we're counting ^C, then I'd also add: * ^D - Send EOF, which exits most shell-like programs (if you're on an empty line, so try ^C^D) And the job control bindings: * ^Z - Suspend current foreground process and return to shell, use `fg` to resume it in foreground and `bg` to resume it in background (see also `disown`) * ^S - "Stop" current process, useful if it's printing a lot of stuff and you want to pause it for…

I hated ^S until I disabled it with `stty -ixon`. The thing is, this key is actually bound to a really useful command: the reverse of ^R, ie. search forward in history. It's very useful when you assemble a new command from a few separate ones. You just ^R to the first one you want, mark and copy the part you want with ^Space and Alt+w, then search forward to the next one with ^S. I do use fzf, and it's great, but not for this specific use case.

Also, it's worth noting that you can give a prefix argument to many commands by pressing Alt+1-9 (possibly multiple times). For example, the sequence Alt+2 Alt+. pasted not the last, but second to last word from the previous command.

Oh, and Alt+x also works! With completion under TAB!

The terminal looks simple, and most people prefer GUIs for good reasons. Not to mention the actual complexity of interpreting escape sequence and emulating the teletype (TTY). By the same token, though, terminal is something that was developed and polished by hordes of programmers since the teletypes. It's amazing, and the result is quirky as hell, but also incredibly powerful.

Re: Keyboard shortcuts for GNU Readline

#102
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…

I'm really bad about picking up new keyboard shortcuts (I end up using them little enough that unless I take out time for focused practice, I'll forget them—I'm pretty sure I'm just never gonna get decent at vim or emacs, for this reason, aside from basic navigation keys) but took to this one instantly because it's so damn useful that I used it several times the very first day I learned it, kept using it the rest of the week, and have used it almost daily ever since. Doesn't hurt that it's reasonably mnemonic ("R" for "reverse-search")

Reverse-history-search is amazing and I don't know how I went as long as I did without knowing about it.

Re: Keyboard shortcuts for GNU Readline

#104
post #58
post #27

> C-e, C-f, M-b, M-f Why these strange shortcuts when any keyboard has arrow keys and they can be used with a control modifier to move by words? I can understand why to use C-a, C-e, because laptop keyboards tend to have "Home" and "End" keys in strange places, but those... And Emacs documentation for some reason insists on using C-e, C-f instead of arrow keys.

C-f(orwards) C-b(ackwards) The reason you use them is that they allow you to not leave the home row. So say you're writing something and need to move back and delete a mistype, it's much faster to do that with C-b C-b C-b backspace M-f than moving your right hand to the arrow keys and moving it back to type the letter and then moving it to the arrow keys again. Now, lot's of people can't be bothered to take the time…

>The reason you use them is that they allow you to not leave the home row

How do you press the control key or the alt key while touch typing without loosing home row position? For alt, I try using my thumb, extremely folded down, but for control...?

Re: Keyboard shortcuts for GNU Readline

#105
post #60
post #41

Earlier quoted context omitted.

So, to be fair , C-h isn't some crazy invention of readline (and thereby a failure of what it was "advertising") that you got used to: it is the standard key code for backspace. Just like a horizontal tab is ASCII 9 and a carriage return is ASCII 13, ASCII 8--and I realize this might make less sense as this in some sense "undoes" a thing and maybe you would never expect it to be in a file--is backspace. Meanwhile, al…

> by essentially subtracting 64 (which is almost but not quite equivalent to masking out a bit) Subtracting 64 is exactly the same as "masking out a bit". The difference between the control characters and their upper case equivalents is that bit 6 (counting from zero) of the byte is zero for the control characters and is one for the upper case equivalents. On old terminals, the 'control' key more often than not worke…

It isn't the same as "masking out a bit" when you are subtracting 64 from 63 to get 127 (the behavior of C-?). I think it is equivalent to Xor-ing it, but I didn't want to go into that for various reasons, including it just being overly complicated (and, in fact, edited that statement three times in an attempt to find something that was all of true, expository, and easy to understand; but, I apparently didn't optimize for "something everyone would appreciate why it was said the way it was said if they liked adding information but hadn't paid as much as attention to all of the examples as I had been forced to while drafting the comment").

Re: Keyboard shortcuts for GNU Readline

#106
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:"; }

In this file `~` is meta (option key on macs). Not sure why it's not escape like it is in emacs.

Re: Keyboard shortcuts for GNU Readline

#107
post #4

Earlier quoted context omitted.

Can I still use macros with 'q '?

You can edit the current prompt in a full vim by pressing ‘v’. On :wq the content of the file will be run as the command. In that case you can use the macros with q (and any fancy vim plugin you might like)

Or e.g. Neovim if `FCEDIT=nvim`

Re: Keyboard shortcuts for GNU Readline

#108

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…

On a linux desktop you can have this in GTK applications with the "gtk-key-theme 'Emacs'" settings.

Re: Keyboard shortcuts for GNU Readline

#109

The time has come for gnu console and linux filesystems to support emoji characters for command names and filenames. In Windows 10 you can name your files and folders with emojis.

This has been supported on Linux systems for many, many years, decades in the case of filenames, afaik.

Re: Keyboard shortcuts for GNU Readline

#110

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…

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

Post reply on HN