Replace zsh-history-substring-search with fzf

Replace the zsh-history-substring-search plugin with fzf by adding a
function that starts the fzf-history-widget when pressing <Up> with a
nonempty BUFFER. The widget then uses the buffer automatically as query
for fzf.
This commit is contained in:
2020-08-19 21:51:47 +02:00
parent 8bcc737030
commit d5dda4d353
3 changed files with 28 additions and 12 deletions

View File

@@ -26,14 +26,6 @@ zle -N zle-line-finish
bindkey '^[h' run-help
## History
## Alternatives to check out: {up,down}-line-or-search
bindkey '^[[A' history-substring-search-up
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey '^[[B' history-substring-search-down
bindkey "$terminfo[kcud1]" history-substring-search-down
bindkey '^R' history-incremental-search-backward
## Navigation
bindkey '^[[Z' reverse-menu-complete # shift-tab
bindkey '^K' kill-whole-line # ctrl-K
@@ -83,11 +75,39 @@ function ls-on-enter {
else
zle accept-line
fi
# See fzf-hist below
FZF_HIST_WENT_UP=
}
zle -N ls-on-enter
bindkey "^M" ls-on-enter
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(ls-on-enter)
# "Scroll" through history if buffer was empty but use it as query for fzf over
# command line history if not (similar to substring-search but with fzf)
function fzf-hist-up {
if [ -z "$BUFFER" ] || [ "$FZF_HIST_WENT_UP" -eq 1 ]; then
zle up-line-or-history
FZF_HIST_WENT_UP=1
else
# Will take BUFFER as query
fzf-history-widget
fi
}
function fzf-hist-down {
zle down-line-or-history
[ -n "$BUFFER" ] || FZF_HIST_WENT_UP=
}
zle -N fzf-hist-up
zle -N fzf-hist-down
## History
# Up
bindkey '^[[A' fzf-hist-up
bindkey "$terminfo[kcuu1]" fzf-hist-up
# Down
bindkey '^[[B' fzf-hist-down
bindkey "$terminfo[kcud1]" fzf-hist-down
# Fuzzy finder bindings:
# ^T fzf-file-widget
# \ec (Alt-C) fzf-cd-widget

3
.gitmodules vendored
View File

@@ -40,9 +40,6 @@
[submodule ".config/zsh/plugins/zsh-autosuggestions"]
path = .config/zsh/plugins/zsh-autosuggestions
url = https://github.com/zsh-users/zsh-autosuggestions
[submodule ".config/zsh/plugins/zsh-history-substring-search"]
path = .config/zsh/plugins/zsh-history-substring-search
url = https://github.com/zsh-users/zsh-history-substring-search
[submodule ".config/zsh/plugins/zsh-syntax-highlighting"]
path = .config/zsh/plugins/zsh-syntax-highlighting
url = https://github.com/zsh-users/zsh-syntax-highlighting.git