Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active March 9, 2019 16:53
Show Gist options
  • Save caseywatts/6c989ed8e942a75f97f5e05dcda003f1 to your computer and use it in GitHub Desktop.
Save caseywatts/6c989ed8e942a75f97f5e05dcda003f1 to your computer and use it in GitHub Desktop.
BEST THING EVER
# for bash
### Search History (autocomplete style~)
# Press up-arrow for previous matching command
"\e[A":history-search-backward
# Press down-arrow for next matching command
"\e[B":history-search-forward
# for zsh
### Search History (autocomplete style~)
# Press up-arrow for previous matching command
bindkey "^[[A" history-search-backward
# Press down-arrow for next matching command
bindkey "^[[B" history-search-forward

Short link to this: caseywatts.com/bashautocomplete

Other gists & tricks: http://caseywatts.com/gists-and-tricks

Bash/zsh Autocomplete

So you typed something into the terminal before and you wanna bring it up now? Once that code above is in your .inputrc (for bash) or your .zshrc, then try it out:

  • type the first few characters of the thing (fortunately you remember how it started)
  • press the up arrow key. ✨ the most recent command that starts with those letters shows up ✨
  • up again to cycle back further
  • press down to go back one :)

(there's a related thing called reverse-i-search that you can do with ctrl+r (see here) but I definitely don't like it as much b/c you can't cycle up and down, just in one direction~)

@sameetn
Copy link

sameetn commented Jun 14, 2017

I think reverse search works as ctrl+r in one direction and ctrl+shift+r in the other direction

@caseywatts
Copy link
Author

@sameetn I wish something like that would work too!
I believe you that it works somewhere - but that didn't work on my mac just now :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment