When using the up and down arrow in my terminal (iTerm 2
on Mac OS Catalina
), I can browse through my last commands using the up and down arrows.
I use ZSH
(Oh-my-zsh
to be precise) and if I type e.g. vim
then press up, it will browse my history for any commands issued starting with vim
.
I think it's annoying to have to move my hand to the arrow keys, so i wanted to bind ctrl-j
and ctrl-k
for browsing up and down.
I looked at bindkey
and bound ^j
to down-history
and ^k
to up-history
. This allows me to browse my history, but not with the "smart" functionality (i'm not sure of the right terminology here) - It simply goes up and down in my history, without regards to my input.
I've looked through the standard widgets on the Zsh Line Editor
manual, but I cannot find the right command for this.
Which command should I bind ^j
and ^k
to to get my desired result?
bindkey | grep -F '^[[A'
; that should show you the widget that up-arrow is currently bound to.up-line-or-history
, so naturally I bound^p
to that. Unfortunatly i still only get what seems to beup-history
without the "smart" search.