Add the Following Lines to Your ~/.bashrc and You Will Be Very Happy

I added the following to my ~/.bashrc and I am loving it!

## Up Arrow: search and complete from previous history
bind '"\eOA": history-search-backward'
## alternate, if the above does not work for you:
#bind '"\e[A":history-search-backward'

## Down Arrow: search and complete from next history
bind '"\eOB": history-search-forward'
## alternate, if the above does not work for you:
#bind '"\e[B":history-search-forward'

(see the comments below for explanation of the alternate codes) The first command rebinds the up arrow from “previous-history”, which unconditionally selects the immediately preceding command from your command history, with “history-search-backward”, which selects the previous command in your history that begins with the characters you have already typed in. The second command does the same, but with the down arrow key, in the opposite direction. For example, given the following sequence of commands: So, for example, if you have nothing typed at the prompt, then the up arrow and down arrow keys will work just as before, moving through your history one step up or down respectively. However, if you type “fi” and then press the up arrow key, the previous command entered that begins with “fi” (e.g., “find …“) will be filled out at the prompt. Press the up arrow key again to select the command beginning with “fi” preceding that, and so on. Down arrow iterates downward over commands beginning with “fi”

Share