zsh: better history search

zsh: better history search

14 Mar 2025

I absolutely love how zsh implemented the prefix search with an "arrow-up" key.

this feature is extremely useful for a long commands with lots of arguments, such as starting docker containers.

but! the arrow keys are not so convenient to reach, especially when you touch-type-wannabe.

let's remap the ctrl+p, which is usually stands for "scroll history back", to do the same as "arrow-up" in zsh:

bindkey "^P" up-line-or-beginning-search
bindkey "^N" down-line-or-beginning-search

update: without oh-my-zsh you (probably) have to load the plugin by hand. add the following to your .zshrc:

autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search

also, it's helpful to run bindkey to list the current keybinging configuration, zsh appears to have A LOT of interesting features by default! go take a look!


related stackoverflow post

history control from zsh docs