Skip to content

Conversation

@ruifm
Copy link

@ruifm ruifm commented Jun 16, 2019

From this discussion.
Tested it on both neovim 0.3.7 and vim 8.1.1-1467.

@gpanders
Copy link
Contributor

gpanders commented Oct 6, 2019

For Vim 8.1 and higher (with terminal support), this is more concise and doesn't offer two separate implementations for vim/nvim:

function! s:completed(winid, filename, action, ...) abort
    bdelete!
    call win_gotoid(a:winid)
    if filereadable(a:filename)
      let lines = readfile(a:filename)
      if !empty(lines)
        exe a:action . ' ' . lines[0]
      endif
      call delete(a:filename)
    endif
endfunction

function! FzyCommand(choice_command, vim_command)
    let file = tempname()
    let winid = win_getid()
    let cmd = split(&shell) + split(&shellcmdflag) + [a:choice_command . ' | fzy > ' . file]
    let F = function('s:completed', [winid, file, a:vim_command])
    botright 10 new
    if has('*termopen')
        call termopen(cmd, {'on_exit': F})
    else
        call term_start(cmd, {'exit_cb': F, 'curwin': 1})
    endif
    startinsert
endfunction

@keith
Copy link
Contributor

keith commented Mar 1, 2020

@jhawthorn probably worth merging this, it works great for neovim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants