You can use the widgets history-beginning-search-backward
and history-beginning-search-forward
for that. By default they are not bound to any keys so you'll have to do that with bindkey
.
bindkey "^[[5~" history-beginning-search-backward
bindkey "^[[6~" history-beginning-search-forward
Where ^[[5~
is the code for page up and [[6~
for page down. These codes may be different for your terminal.
You can either use cat -v
to show the codes for the non-printing characters. Or you can use the associative array terminfo
from the zsh/terminfo
module (which may already be loaded; see zshmodules(1)
and zshbuiltins(1)
for more infos on zsh modules) which should contain the correct codes in the keys knp
(next-page key) and kpp
(previous-page key):
if (( ${+terminfo[knp]} )) && (( ${+terminfo[kpp]} )); then
bindkey "${terminfo[kpp]}" history-beginning-search-backward
bindkey "${terminfo[knp]}" history-beginning-search-forward
fi
To be honest these widgets will not loop when they reach the beginning or end of history, but as you can go both directions (and considering that ipython
does not loop either) that should not be a real problem.