Compared to Fish, currently I like Zsh a little bit more. But one of the unforgettable feature of Fish is its auto-suggestion based on history.
It made command line input so fluent.
Zsh has a feature similar to that called predict. You could configure by placing the following codes in your ~/zshrc.
You could press <Ctrl-Z> to toggle predict on and off.
autoload predict-on
predict-toggle() {
((predict_on=1-predict_on)) && predict-on || predict-off
}
zle -N predict-toggle
bindkey '^P' predict-toggle
zstyle ':predict' toggle true
zstyle ':predict' verbose true
But compared to Fish’s auto-suggestion, I feel that the predict feature is less useful.
The difference show up when you simply type ls<Enter>.
- In Fish, only
lswill be executed. - In Zsh, if
predictwas turned on,ls -lawill be executed, which is sometimes not what we want.
So for a more convenient way of accessing command line history, I prefer Zsh’s vi mode and history-search-backward.
You could press <Ctrl-J> and <Ctrl-K> to search history forward and backward.
# vi mode
setopt vi
# bind k and j for history search in vi mode
bindkey -M viins '^k' history-search-backward
bindkey -M viins '^j' history-search-forward
bindkey -M vicmd '^k' history-search-backward
bindkey -M vicmd '^j' history-search-forward