Issue
- I am using ohmyzsh with no changes. Here is my
.zshrc
file (comments removed for brevity):
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(git)
source $ZSH/oh-my-zsh.sh
When I use the UP arrow key with a blank terminal my
zsh_history
file will be searched for the latest commands I have typed, starting from the most recent command. If I start typing a command first, myzsh_history
will only match commands that start with whatever I have typed up until that point.For example, if this is my
zsh_history
file:
whoami
ls /home/user
ls /etc
ls /
cat /etc/ssh/ssh.pub
cat /etc/passwd
If I type
ls /
and then hit the up arrow one time, I will seels /etc
and if i hit the up arrow again I will seels /home/user
. If I try and hit the up arrow now thatls /home/user
is in my terminal buffer (typed in the prompt but not ran yet), then nothing will happen because there are no additional matches forls /home/user
.This is not what I want to happen.
Desired Outcome
Instead, when there is no history match in my terminal prompt I would like the history to be cycled from the very last command in
zsh_history
.So in my example, if I have
ls /home/user
in my terminal prompt and then I hit the up arrow, I want the commandcat /etc/passwd
to be displayed, then hitting once more would displaycat /etc/ssh/ssh.pub
and so forth until I reach the very top of the history atwhoami
.What changes do I have to make in my
.zshrc
file in order to accomplish this?I do not understand exactly why this happens but this is not the default behavior in normal
zsh
whenohmyzsh
is not in use. I know this because I tested withzsh -df
to load a bare zsh shell that has not sourced any config files. So for this reason, I think there may be a conflict in the~/.ohmyzsh/lib/completion.zsh
or one of those other default files.
Things I tried
- I have tried adding the lines
bindkey "^[[A" history-beginning-search-backward
andbindkey "^[[B" history-beginning-search-forward
that did not work, and yes I also made sure that those bindkeys matched my system by usingcat -v
and typing the arrow keys as well as usedshowkey -a
just to double check.
Additional Thoughts
- I think the solution might have to be some sort of zsh function that checks whether anything is returned to the user when up arrow key is pressed, and if nothing is returned then the HISTORY pointer (possibly
$HISTNO
environment variable) is reset to the latest command inzsh_history
.