Fix your terminal experience with this 4 lines of input config

Fix your terminal experience with this 4 lines of input config
Photo by Gabriel Heinzer / Unsplash

I cringe every time I see someone painfully pressing ArrowUp to find something in their terminal history, only to then hit Cmd+R and end up with something they did not want to find at all.

If you are an avid terminal user, which probably you are, judging by your reading preferences, this will be a life-changing tip!

So what's the big deal? You type something, like cd /etc/ and press ArrowUp to search in your history for only entries that start with "cd /etc/".

For Bash users

Add this to ~/.inputrc:

"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

For ZSH users

Add this to your ~/.zshrc :

bindkey "^R" history-incremental-search-backward
bindkey "\e[A" history-beginning-search-backward
bindkey "\e[B" history-beginning-search-forward
HISTFILE=~/.zsh_history
HISTSIZE=100000000
SAVEHIST=100000000
setopt INC_APPEND_HISTORY
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_DUPS
setopt PROMPT_SUBST

And, of course, restart your teminal after that.

There you go! You can thank me later!

Subscribe to darlanalv.es

Sign up now to get access to the library of members-only issues.
Jamie Larson
Subscribe