Zsh completion with up and down arrows

I used oh-my-zsh for a while and found one of its nice features, where I could complete my command using up and down arrow keys.

I want to recreate the feature, and even browsed it source code and this is what I have so far: https://termbin.com/vlaj in my ~/.zshrc.
Say my history is like this:

1 nvim hello-word.sh

2 nvim fibonacci.c

3 nvim cmatrix.py

Now if i had $ nvim he
and i press up arrow key, it becomes nvim cmatrix.py , and not nvim hello-word.sh as it would in oh-my-zsh.
I found this to be helpful, but it doesn’t fix it: https://github.com/ohmyzsh/ohmyzsh/issues/1720

Asked By: astroanax

||

Does this plugin fulfill your need?

https://github.com/zsh-users/zsh-history-substring-search

Answered By: Bi Ao

If you are looking for completion based on the prefix of your command, zsh includes what you need natively (taken from this blog post). Simply include the following in your .zshrc (adjusting the bindkey keycodes if necessary for your OS):

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
bindkey "^[[B" down-line-or-beginning-search
Answered By: Daniel Harding

All the solutions didn’t work, but I finally found this one:

# Make zsh autocomplete with up arrow
autoload -Uz history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "$terminfo[kcuu1]" history-beginning-search-backward-end
bindkey "$terminfo[kcud1]" history-beginning-search-forward-end
Answered By: Olivier Pons
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.