24

When I first switched to ZSH when I would use the up arrow key to move through history it would filter the history based on what I had already typed so if I type mysql and then up I would be stepping through recent commands that started with mysql.

This is no longer the case, now if I use up it just steps thought the most recent commands regardless of what I've already typed. How can I turn this back on?

My .zshrc is very small and I've already tried turning all my options off.

Here is what is in my .zshrc

plugins=(git command-not-found svn debian screen vi-mode)
source $ZSH/oh-my-zsh.sh

bindkey -v
bindkey "^R" history-incremental-search-backward
export EDITOR="vim"

# history stuff
HISTFILE=~/.zsh-histfile
HISTSIZE=2000
1
  • 5
    "My .zshrc is very small" except that whole oh-my-zsh bit... Jun 7, 2014 at 22:44

2 Answers 2

31

You had up-line-or-search bound to your up-arrow. This should do what you want:

bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search

[Edit]:

The command above only uses the first word to search. The following will use the whole line. See man zshcontrib...

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
bindkey "^[[A" up-line-or-beginning-search # Up
bindkey "^[[B" down-line-or-beginning-search # Down
13

I'd highly recommend using "$terminfo[kcuu1]" or "$key[Up]" rather than hard-coded stuff like "^[[A" which may or may not work on any particular system.

Check out /etc/zsh/zshrc for more keys. Here's what it looks like on my system. I think the terminfo keys are more likely to be defined.

key=( BackSpace "${terminfo[kbs]}" Home "${terminfo[khome]}" End "${terminfo[kend]}" Insert "${terminfo[kich1]}" Delete "${terminfo[kdch1]}" Up "${terminfo[kcuu1]}" Down "${terminfo[kcud1]}" Left "${terminfo[kcub1]}" Right "${terminfo[kcuf1]}" PageUp "${terminfo[kpp]}" PageDown "${terminfo[knp]}" )

https://unix.stackexchange.com/a/405358/276872

2
  • +1 -- This is important, and was why the accepted answer above wasn't working for me. If other solutions aren't working, try this first!
    – Linuxios
    Sep 7, 2018 at 15:54
  • I tried the "$key[Up]" first because it looked friendlier, but only the terminfo did the trick. Thanks!
    – Jonathan
    Jun 16, 2019 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy