Skip to content

Instantly share code, notes, and snippets.

@johansenja
Created May 24, 2021 13:39
Show Gist options
  • Save johansenja/2df14daf4c611685c20a81dd3f22d68c to your computer and use it in GitHub Desktop.
Save johansenja/2df14daf4c611685c20a81dd3f22d68c to your computer and use it in GitHub Desktop.
Run command in the background in vim
" I ended up using this for starting the long-running qdocs server in qdocs-vim (https://github.com/johansenja/qdocs-vim).
" Obviously this requires ruby to spawn the process, but that is ok here given that qdocs is written in ruby anyway
" spawn the process and grab the pid to be able to refer to later
" --disable=all just speeds up the ruby start time
let l:long_running_pid = system("ruby --disable=all -e 'print(spawn(%{long_running_shell_command}))'")
" stop the server using the pid from earlier
exe "! kill -9 " . l:long_running_pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment