fzf icon indicating copy to clipboard operation
fzf copied to clipboard

Strange delay | A function and `zle -N` for "Switch between Ripgrep launcher mode (CTRL-R) and fzf filtering mode (CTRL-F)"

Open sisrfeng opened this issue 2 years ago • 0 comments

  • [x] I have read through the manual page (man fzf)
  • [x] I have the latest version of fzf
  • [x] I have searched through the existing issues

Info

  • OS
    • [x] Linux
    • [ ] Mac OS X
    • [ ] Windows
    • [ ] Etc.
  • Shell
    • [ ] bash
    • [x] zsh
    • [ ] fish

My config

I've modified this line to INITIAL_QUERY="${BUFFER:-}" : https://github.com/junegunn/fzf/blob/e619b7c4f4e0da09b87a239b8f52ad909bb5f1e0/ADVANCED.md?plain=1#L423

My function and zle config:

# Switch between Ripgrep launcher mode (CTRL-R) and fzf filtering mode (CTRL-F)
rg-fzf-switch(){
    \rm -I --preserve-root -f /tmp/rg-fzf-{r,f}
    RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
    INITIAL_QUERY="${BUFFER:-}"
    FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
    fzf --query "$INITIAL_QUERY" \
        --ansi \
        --disabled \
        --color "hl:-1:underline,hl+:-1:underline:reverse" \
        --prompt          'ripgrep正则> '                                  \
        --delimiter       :                                                \
        --header          '模式: CTRL-R (ripgrep) | CTRL-F (fzf)'  \
        --preview         'bat --color=always {1} --highlight-line {2}'    \
        --preview-window  'up,60%,border-bottom,+{2}+3/3,~3'               \
    --bind  "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
    --bind  "ctrl-f:unbind(change,ctrl-f)+change-prompt(fzf模糊> )+enable-search+rebind(ctrl-r)+transform-query(echo {q} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f)" \
    --bind  "ctrl-r:unbind(ctrl-r)+change-prompt(1. ripgrep> )+disable-search+reload($RG_PREFIX {q} || true)+rebind(change,ctrl-f)+transform-query(echo {q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r)" \
    --bind  "start:unbind(ctrl-r)" \
    --bind  "enter:become(nvr {1} +{2})"
}

    zle -N rg-fzf-switch
    bind '\C-F' rg-fzf-switch

Problem / Steps to reproduce

The rg command seems to have a delay at the first time. In the second picture, there is no result. And think it's a bug or it needs some hack.

image

After typing ctrl-f:

image

After typing Backspace:

image

sisrfeng avatar May 01 '23 14:05 sisrfeng