r/zsh•
rdbell

Fish-style autocomplete from the middle of a command

I'm trying to get zsh to have autocomplete behavior similar to fish.

In fish I can run these commands:

GOOS=darwin CONFIG=app make clean
GOOS=darwin CONFIG=app make generate
GOOS=darwin CONFIG=app make dist

and then on the next line I can type make and use the up/down arrows to scroll through relevant history.

Can anyone point me in the right direction?

Posted Aug 25, 2018, 7:25 PM UTC

55
giigu•

I think you're talking about this?

# Edit accordingly if your arrows aren't ^[0A and ^[0B
autoload -Uz {up,down}-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey '^[0A' up-line-or-beginning-search
bindkey '^[0B' down-line-or-beginning-search
7
rdbellOP•

This is perfect. Thank you!

2
rdbellOP•

To anyone else coming here looking for a solution, this is the best implementation I've found so far: https://github.com/zsh-users/zsh-history-substring-search

3
Cliff567•
1
rdbellOP•

Thanks for the link. I'm already using this, but it can't match suggestions from the middle of a command like I described.

Also it doesn't support scrolling through history based on suggestion. It only shows a single suggestion and up/down just scrolls through normal zsh history.

2