34

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
Mikel
  • 9,026

2 Answers2

56

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
Francisco
  • 2,298
  • 21
  • 21
21

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

marmastr
  • 311
  • +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 07 '18 at 15:54
  • I tried the "$key[Up]" first because it looked friendlier, but only the terminfo did the trick. Thanks! – Jonathan Jun 16 '19 at 15:19
  • 7
    The $terminfo and $key variants of up/down don't work for me (iterm 3.4.15, zsh 5.8.1, MacOS Monterey), whereas "^[[A" does work fine. terminfo does work for pageup/pagedown though – craigds Jun 12 '22 at 21:43