Not sure I'm wording the question very well, but an example is worth a thousand words of mine. eg., using oh-my-zsh :

git <up arrow>

Will cycle up all the git commands I have used...

git rebase brancha
git commit foo
git rebase branchb

Is there a way to limit that history to the second/third word given. eg.

git rebase <up arrow>

To only cycle through git rebase commands :

git rebase brancha
git rebase branchb

1 Answer 1


You're looking for the zle widget history-beginning-search-backward, which is not bound to a key by default.

You can bind this command to a key, for example Ctrl+Up (and the symmetric command on Ctrl+Down). Keychords like Ctrl+Up send different escape sequences on different terminals, so check what yours sends by typing Ctrl+V Ctrl+Up; \e represents an escape character (displayed as ^[ by most terminals) which is the first character of all escape sequences.

bindkey '\e[1;5A' history-beginning-search-backward
bindkey '\e[1;5B' history-beginning-search-forward

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .