Personally I bind them to up/down which on OS X at least involves:
# Put this in some file like ~/.readline-bindings
"\e[A": history-search-backward
"\e[B": history-search-forward
# And this in your ~/.bashrc or ~/.zshrc
bind -f ~/.readline-bindings
That way if you haven't typed any input it behaves like normal up (previous command), but if you've typed some characters it only retrieves matching commands.http://codeinthehole.com/writing/the-most-important-command-...
I also use zsh and I don't even use ctrl+r anymore. I just type a portion of the command I remember and hit the up arrow key. Almost always the command I want is only one to three arrow keys away. zsh matches partial commands really well.
I can start typing and then type more once I see some results to hone in more precisely to what I want, or even backspace over some of what I've typed and type some more without having to start all over again.
Also, using control-r instead of the arrow keys doesn't force me to move my wrists and lets me keep my fingers mostly on the home row. I try to use the arrow keys as little as possible.
Now I gotta retrain my muscle memory :)
bindkey '^r' history-incremental-pattern-search-backward
When you remember parts of the commands, you can do "C-r" then "echo*something".
I'm a little wary of precompiled binaries.
> While the [ctrl-r] method is more powerful, when doing some redundant task, it’s much easier to remember !22 than it is to muck with ctrl-r type searches or even the arrow keys.
how?!
There's `Meta-_` to insert the previous last word, but you cannot cycle with the previous words--it inserts the last word of the previous commands. You can give it a count, though (with Meta+nums).
That's a much more interactive way of getting to the command I want, and if the first match isn't what I want I can either keep typing more of the command or type control-r for the next match. I can also type control-s to go to the previous match. For that last trick to work, you need to do something like this first: stty stop ""
Granted, I use zsh, but I think it works pretty much the same in bash.
Another trick I really like, which I've only used in zsh, but which might exist in bash too (since bash and zsh have so much feature parity these days) is to bind a keystroke to "insert-last-word". When this keystroke is hit, it appends the last argument of the previous command to the end of the current line, further typing of this same keystroke will remove the appended argument and instead append the last argument of the previous command, and so on. I use this all the time and therefore never have to type !$
And my favorite shell trick of all time: set -o vi