Update on 2015-06-07: I’ve discovered from this stackexchange answer that zsh now provides this function out-of-box, so what you really need, instead of the config below, is:
1 2 3 4
Update on 2015-03-07: see an update about keys at the bottom.
There is an extremely convenient feature in command-line shells (i.e.,
bash) when you start typing a command, say
git s, and then press Up and Down keys to search back/forward commands starting with that text. Here the commands may be
git status or
git show, whatever there is in your history.
bash, the following
~/.inputrc lines work:
1 2 3 4 5
zsh, however, that doesn’t work anymore, as it doesn’t use the
readline library. I noticed that the feature was on by default in
zsh (at least, having oh-my-zsh installed), but it worked rather strangely. It seemed to do the search matching the first word of the command only (which is exactly how it’s supposed to act, according to
man zshall). To have the same behavior as in
bash, add these lines to your
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Update: to find out the actual characters sequences that Up and Down keys are sending, you can run this command:
cat - and press those keys. I needed that, because on another Mac they produced
^[OB characters instead. Keep that in mind if the above snippet doesn’t work for you out of the box!