Live data from Hacker News

Keyboard shortcuts for GNU Readline

masteringemacs.org

41–50 of 174 posts

Re: Keyboard shortcuts for GNU Readline

#41
post #20

After getting very used to C-w (delete back work) and C-h (delete character backward) on readline, it really bugged me that these aren't default on emacs, even though readline is often advertised as giving emacs muscle memory. I ended up globally remapping C-w and moving the help prefix, C-h to C-x h and making C-h backspace, because i was pressing it incorrectly that often.

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, all Control does is convert a normal (capital) character into a control character, which is the term for the ASCII characters below 32 (aka, the space character) by essentially subtracting 64 (which is almost but not quite equivalent to masking out a bit). Notably, @ is 64, so C-@ generates ASCII 0, which is why you see ^@ printed for NUL bytes in many editors (including vim). After @, you get A-Z and then [, \, ], ^, and _.

This is why, if you want to get Escape, you can type C-[, as ESC is 27 and [ is 91. And this is also how C-G becomes that annoying bell, because G is the 7th letter of the alphabet and BEL is 7, And so, C-M is equivalent to pressing Enter, C-J is equivalent to pressing Tab... and C-H is equivalent to pressing Backspace!! Now, there is also a DEL, for the Delete key, which is which is 127. As ASCII is designed for 7-bit, that is the same as -1, so you can type it using C-?, as ? is 63 ;P.

OK, so, one might should then wonder how the hell Emacs even works, if they remapped the character code for Backspace to do something silly like Help... right?! And the answer is kind of "it doesn't", which I find amazing! There is actually a FAQ entry for Emacs "Why does the Backspace key invoke help?" and a related section from its manual on "If DEL fails to delete". (It might even be the solution you came up with isn't the ideal one, so you might want to read these.)

https://www.gnu.org/software/emacs/manual/html_node/efaq/Bac...

https://www.gnu.org/software/emacs/manual/html_node/emacs/DE...

Re: Keyboard shortcuts for GNU Readline

#42
Friends if you dont know: you can add readline support to LOTS of things, especially custom scripts and tools with a prompt by just calling the program with rlwrap.

> rlwrap is a 'readline wrapper', a small utility that uses the GNU Readline library to allow the editing of keyboard input for any command.

https://github.com/hanslub42/rlwrap

Re: Keyboard shortcuts for GNU Readline

#43

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…

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...

Re: Keyboard shortcuts for GNU Readline

#44

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 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.

Re: Keyboard shortcuts for GNU Readline

#45

Earlier quoted context omitted.

Command-A isn’t available on Linux in slack? How do people even function without basic function keys?

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

Doesn't ctrl+/ select all in either GTK key theme?

Re: Keyboard shortcuts for GNU Readline

#46
post #6

I'm using bash (and thus GNU readline) all day every day at work, and by far the most useful shortcut for me is Ctrl-r (reverse history search). I also sometimes use Ctrl-a (start of line, if the keyboard doesn't have a convenient Home key) and Ctrl-e (end of line, in lieu of End key). Btw the post disses Ctrl-s / Ctrl-q for pausing/resuming terminal output, but it can be useful when you're outputting a lot of text (…

If you don't already know about it: combining fzf with Ctrl-r is _amazingly good_ https://github.com/junegunn/fzf it's a fuzzy finder combined with reverse history search..

Re: Keyboard shortcuts for GNU Readline

#47
post #41
post #20

After getting very used to C-w (delete back work) and C-h (delete character backward) on readline, it really bugged me that these aren't default on emacs, even though readline is often advertised as giving emacs muscle memory. I ended up globally remapping C-w and moving the help prefix, C-h to C-x h and making C-h backspace, because i was pressing it incorrectly that often.

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…

Don't mean to be pedantic, but this comment left me very confused, surely you mean carriage return to be ASCII 13? Also, g is the 7th character and BEL is 7.

Re: Keyboard shortcuts for GNU Readline

#48

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

Seems quite cool - I don't suppose you have a copy of the .dict file linked in that blog post? the link is 503 :\

Re: Keyboard shortcuts for GNU Readline

#49
post #48

Earlier quoted context omitted.

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…

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 */
Post reply on HN