fzf: [regression] sink function calling fzf#run() puts vim in normal mode instead of terminal

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

Info

  • OS

    • Linux
  • Shell

    • bash

Env

NVIM v0.5.0-dev+1085-g52397aaa0
> nvim --version
NVIM v0.5.0-dev+1085-g52397aaa0
> vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jan 20 2021 22:47:34)
Included patches: 1-2380

Problem / Steps to reproduce

When the sink function calls fzf#run(), vim and neovim switch to normal mode instead of terminal mode.

This regression comes from this commit: https://github.com/junegunn/fzf/commit/1a76bdf8914195ab26ebac7e49a3ed8752dd69bd

minimal_vimrc:

call plug#begin('~/.vim/plugins')
Plug 'junegunn/fzf', {'dir': '~/.fzf','do': './install --all'}
call plug#end()

testcase.vim:

function! s:list_handler(...) abort
  call s:run_testcase()
endfunction

function! s:run_testcase() abort
  let opts = {'sink*': function('s:list_handler')}
  call fzf#run(fzf#wrap(opts))
endfunction

call s:run_testcase()

Steps to reproduce the issue:

  1. nvim -u minimal_vimrc
  2. source testcase.vim
  3. press Enter

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I was able to reproduce the problem on Neovim HEAD (but not on Neovim 0.4.4 release). 29851c18aa47ad4b4cbf92358cfbe11935f0c033 will fix it.

@junegunn note that this commit created a weird condition where some commands executed after wait for a key to be pressed to be executed.

The minimal testcase I found is using CocList. CocList extensions won’t execute before we press a key:

function! s:list_handler(...) abort
  let cmd = "CocList extensions"
  execute cmd
endfunction

function! s:run_testcase() abort
  let opts = {'sink*': function('s:list_handler')}
  call fzf#run(fzf#wrap(opts))
endfunction

call s:run_testcase()

I had to call feedkeys('', 'x') before invoking CocList extension to fix it.

Can you test if this patch fixes the problem?

diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 763747c..1069af8 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -764,6 +764,10 @@ function! s:split(dict)
   endtry
 endfunction
 
+noremap  <silent> <Plug>(fzf-normal) <Nop>
+noremap! <silent> <Plug>(fzf-normal) <Nop>
+tnoremap <silent> <expr> <Plug>(fzf-normal) &filetype == 'fzf' ? "\<C-L>" : "\<C-\>\<C-n>"
+
 function! s:execute_term(dict, command, temps) abort
   let winrest = winrestcmd()
   let pbuf = bufnr('')
@@ -793,7 +797,7 @@ function! s:execute_term(dict, command, temps) abort
     else
       if bufnr('') == self.buf
         " Exit terminal mode first (see neovim#13769)
-        call feedkeys("\<C-\>\<C-n>", 'n')
+        call feedkeys("\<Plug>(fzf-normal)")
         " We use close instead of bd! since Vim does not close the split when
         " there's no other listed buffer (nvim +'set nobuflisted')
         close