Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Created May 31, 2017 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethagnawl/7ed9852d896841f262c16ec4540e4920 to your computer and use it in GitHub Desktop.
Save ethagnawl/7ed9852d896841f262c16ec4540e4920 to your computer and use it in GitHub Desktop.
vim background job demo
" http://andrewvos.com/writing-async-jobs-in-vim-8
function! BackgroundCommandClose(channel)
execute "cfile! " . g:backgroundCommandOutput
copen
unlet g:backgroundCommandOutput
endfunction
function! RunBackgroundCommand(command)
if !exists('g:backgroundCommandOutput')
let g:backgroundCommandOutput = tempname()
call job_start(a:command, {'close_cb': 'BackgroundCommandClose', 'out_io': 'file', 'out_name': g:backgroundCommandOutput})
endif
endfunction
command! -nargs=+ -complete=shellcmd RunBackgroundCommand call RunBackgroundCommand(<q-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment