From d5dda4d3537624c62466d054f6a24e8ce3f05ecf Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Wed, 19 Aug 2020 21:51:47 +0200 Subject: [PATCH] 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 with a nonempty BUFFER. The widget then uses the buffer automatically as query for fzf. --- .config/zsh/plugins/keys.zsh | 36 ++++++++++++++----- .../zsh/plugins/zsh-history-substring-search | 1 - .gitmodules | 3 -- 3 files changed, 28 insertions(+), 12 deletions(-) delete mode 160000 .config/zsh/plugins/zsh-history-substring-search diff --git a/.config/zsh/plugins/keys.zsh b/.config/zsh/plugins/keys.zsh index c0512bb..273de5d 100644 --- a/.config/zsh/plugins/keys.zsh +++ b/.config/zsh/plugins/keys.zsh @@ -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 diff --git a/.config/zsh/plugins/zsh-history-substring-search b/.config/zsh/plugins/zsh-history-substring-search deleted file mode 160000 index 0f80b8e..0000000 --- a/.config/zsh/plugins/zsh-history-substring-search +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0f80b8eb3368b46e5e573c1d91ae69eb095db3fb diff --git a/.gitmodules b/.gitmodules index e8287af..c3e5013 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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