I am not able to get the zsh history keybindings to work the way I'd like. I'd like to be able to type sudo and then use the up arrow to scroll through all history commands with the prefix sudo.

I believe this should be bindkey "^[[5~" up-line-or-history. I have that in lib/key-bindings.zsh and that file should be sourced. I am using a largely unmodified installation of oh-my-zsh.

I have what I think is the same .zshrc and lib files on a VM and history works as I want. The VM is running zsh 4.3.10 while my other machine (the one that is not working) is on 5.0.0. Is this a version issue?

5 Answers 5


See https://github.com/robbyrussell/oh-my-zsh/issues/1720

Adding this to .zshrc solved it for me:

# start typing + [Up-Arrow] - fuzzy find history forward
if [[ "${terminfo[kcuu1]}" != "" ]]; then
    autoload -U up-line-or-beginning-search
    zle -N up-line-or-beginning-search
    bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
# start typing + [Down-Arrow] - fuzzy find history backward
if [[ "${terminfo[kcud1]}" != "" ]]; then
    autoload -U down-line-or-beginning-search
    zle -N down-line-or-beginning-search
    bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
  • Thankyou! This has been bugging me for ages, it always worked on MacOS, but now it's working nicely on my Linux box too Commented Nov 21, 2022 at 8:15

I'm not sure, if that changed from 4.3.10 to 5.0.0, but the widget you are searching for is called history-search-backward in the last few releases.

Also a nice key binding is history-incremental-pattern-search-backward where you can input (at a special prompt after invoking that widget) for example sudo*destdir to cycle through all commands starting with sudo and ending with destdir.

  • Thanks for this answer, my problem ended up being the key mapping itself. I followed this answer (especially noting the last paragraph) and got it working.
    – Matt
    Commented Mar 25, 2013 at 23:10

To make it work on Ubuntu do echo DEBIAN_PREVENT_KEYBOARD_CHANGES=yes>>~/.zshenv.


In my case, what was wrong was that I was copying the following environment vars from bash to zsh:

# History modifications
export HISTTIMEFORMAT="%y-%m-%d %T  "
export HISTSIZE=-1

Removing those in zsh made it work


Changing export HISTSIZE= to export HISTSIZE=999999999 in ~/.zshrc solved the issue for me.

You must log in to answer this question.

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