DEV Community

Ben Halpern
Ben Halpern Subscriber

Posted on • Edited on

Ctrl+R Autocomplete with Bash is a Life Saver

I only recently started integrating Ctrl+R into my command-line workflow, and I am happy I did! The command, called reverse-i-search, starts an autocomplete within one's history and eliminates most of my up, up, up, up, up behavior.

ctrl+r bash

From a UX perspective, Ctrl+R works perfectly for me. It's already part of my muscle memory on a few key commands I run a lot. It works by searching through your recent .bash_history. Once you see the command you are looking for, you can press return to execute it or use the left and right arrow buttons to modify it. If you are not seeing the command you want, or can't quite remember the params you need, you can keep hitting Ctrl+R to cycle through the results. It's a very natural flow.

If you're still addicted to up, up, up, up, up, I hope you try this command for yourself.

Latest comments (34)

Collapse
 
jonasbn profile image
Jonas BrĂžmsĂž

Do Try McFly

REF: github.com/cantino/mcfly

Collapse
 
drumor profile image
Ludovic Taffin

Waouw didn't know about that! Thx Ben!

Collapse
 
geoff profile image
Geoff Davis

This is what I use, really enjoy it. Still "autocompletes", but you don't have to move from the arrow keys

Collapse
 
benhemphill profile image
Ben Hemphill

Thats awesome! Going to use that. Ohmyzsh does some interesting things too, but definitely my pattern is still a few too many up arrow keys :)

Collapse
 
amrutprabhu profile image
Amrut Prabhu

This is surely a life saver for me. Just tried it. And it works!!!! :)

Collapse
 
dosamp profile image
DosAmp

Another upside is that this works with all applications that use libreadline. I just used this to bring up a complex SQL query from my ~/.mysql_history, and it also does the job for Python 3.x.

Collapse
 
oscherler profile image
Olivier “Ölbaum” Scherler

In zsh, I bound ctrl-R to history-incremental-pattern-search-backward, which allow wild cards in the search string. It's even more useful.

Collapse
 
flinux profile image
Francesco Marasco

try ohmyz.sh/ !!

Collapse
 
rafaelcg profile image
Rafael CorrĂȘa Gomes

I loved it _

Collapse
 
rlipscombe profile image
Roger Lipscombe

See also Hashtags for commands, wherein you add a #somethingmemorable after a complicated command, making it easier to Ctrl+R for it in future.