Skip to content

Added nvim function to README docs (Issue #64)#116

Open
ruifm wants to merge 1 commit into
jhawthorn:masterfrom
ruifm:nvim-integration
Open

Added nvim function to README docs (Issue #64)#116
ruifm wants to merge 1 commit into
jhawthorn:masterfrom
ruifm:nvim-integration

Conversation

@ruifm

@ruifm ruifm commented Jun 16, 2019

Copy link
Copy Markdown

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

@gpanders

gpanders commented Oct 6, 2019

Copy link
Copy Markdown
Contributor

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

keith commented Mar 1, 2020

Copy link
Copy Markdown
Contributor

@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