Live data from Hacker News

Keyboard shortcuts for GNU Readline

masteringemacs.org

11–20 of 174 posts

Re: Keyboard shortcuts for GNU Readline

#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 else, it’s a topic to keep us occupied while they hit the left arrow 47 times instead of ctrl-a.

Re: Keyboard shortcuts for GNU Readline

#12
post #10
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 (…

>by far the most useful shortcut for me is Ctrl-r I rarely ever use Ctrl-r since I usually know the starting part of the command I want. So, I type those starting characters and use up/down arrow keys, courtesy these lines in `~/.inputrc` "\e[A": history-search-backward "\e[B": history-search-forward

That's useful, but C-r has its merits too, as you can search for any string in the history. So, even if you run, say, python programs all day, here's a way to find that one time you used a different command line parameter... etc.

Re: Keyboard shortcuts for GNU Readline

#15
"Shame, then, that even serious command line hackers never bother learning about its capabilities, as they can supercharge your command line productivity."

Because it is really confusing if you are not an emacs user.

Re: Keyboard shortcuts for GNU Readline

#16
post #4
post #3

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

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)

Re: Keyboard shortcuts for GNU Readline

#18
post #9

One thing I wish I knew how to do -- presuming it's possible -- is constraining the reverse/forward history search. Say I know I'm looking for a grep command, I'll do `C-r grep`, but then I want to look through that subset of results for another string (e.g., the pattern, or maybe another part of a pipeline that I half-remember). AFAIK, reverse/forward history search is just an exact string match...and remembering ex…

I'd use "history | grep ..." at that point, if I can't remember an old command. Possibly "history | grep ... | less" and finish searching inside less.

I was doing history grep too until someone on HN told me about hstr:

https://github.com/dvorka/hstr

Re: Keyboard shortcuts for GNU Readline

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

Post reply on HN