junegunn / fzf.vim

fzf :heart: vim
MIT License
9.51k stars 581 forks source link

[Feature Request] functional, blocking version of `fzf#run` for neovim #1504

Closed Jasha10 closed 9 months ago

Jasha10 commented 10 months ago

Hello,

I would like to request a blocking version of fzf#run(...) that returns the line or list of lines selected.

EDIT: This issue only applies to neovim, not to vim. See comment below.

Motivation

Sometimes using a callback via fzf#run({..., 'sink': MyCallback}) is a pain. It forces me to use an asynchronous programming model.

I want a blocking version of fzf#run such that I can do :let foo = fzf#run_blocking(...). This will enable me to use a functional programming style in my vimscript. Even echoing the line selected by fzf (:echo fzf#run_blocking(...)) seems very difficult to achieve with fzf#run.

Please let me know if I'm missing something. Related issue: https://github.com/junegunn/fzf/issues/2056

Jasha10 commented 10 months ago

After using the minimal setup using vim -Nu <(curl https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw) I realized that fzf#run already returns the selected line(s). I must have a problem somewhere in my .vimrc that's making fzf#run not return the selected lines.

Jasha10 commented 10 months ago

Ok I'm reopening because :echo fzf#run() works with the minimal vim setup but it doesn't work with a minimal Neovim setup! Steps to reproduce:

  1. Open a minimal neovim setup:
    $ nvim --version
    NVIM v0.9.1
    ...
    nvim -Nu <(curl https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)
  2. Run :echo fzf#run(). Nothing is echo'd.
junegunn commented 10 months ago

See https://github.com/junegunn/fzf/issues/2916#issuecomment-1210098626

fzf#run returning values on regular Vim is a happy coincidence, and you shouldn't rely on this behavior because it's not guaranteed if you open fzf in different layouts. And there's no way to implement blocking fzf#run on Neovim unless you set up fzf to open using fzf-tmux. It's a shame we don't have better options.

Jasha10 commented 10 months ago

Thanks for your reply, @junegunn. If my understanding is correct, the fundamental issue is that vim/neovim have a single-threaded event loop. This makes it difficult to escape from the callback paradigm without using green threads.

Thanks also for the tip about fzf-tmux. I'll give that a try.