13

As far as I know, Neovim enables running a command async, without blocking the user. I was told this is also enabled in Vim 8.

But I couldn't find examples of how to run a command asynchronously. Suppose that I want to run the command :make.

How would I run this command in Neovim without blocking?

Is there an example I can find, or easy to follow documentation?

2
  • 5
    For Vim 8, see :help job_start(). NeoVim has a similar API but the function is jobstart() instead.
    – filbranden
    Commented Oct 7, 2019 at 23:17
  • 2
    If you're comfortable reading plugin code, dispatch is a great place to start
    – D. Ben Knoble
    Commented Oct 8, 2019 at 2:05

2 Answers 2

5

vim-dispatch :Make instead of :make

You cannot run the built-in command :make asynchronously in Vim8 or NeoVim.

You have to take the value of 'makeprg' and insert it into vim8 job_start() or neovim jobstart().

I personally like the convenience of plugins which take care of vim8/neovim differences, parsing the result and inserting it into the quickfix/location list, ...

As often the case for vim, there are many plugins you can choose from:

I would recommend to try first vim-dispatch by tpope. It provides

  • familiar command names :Make, :Copen, ...
  • a convenience command :Dispatch to activate compiler/linter and run it in one step.
  • IMHO nice default maps `m for :Make and `<Space> for :Dispatch<Space> and more
  • limited feature set

Some people like to use different plugins for following reason

  • limitations of 'errorformat' for parsing of compiler/linter results
  • vim-dispatch does not open the quickfix list automatically in case of warnings and errors (issue #226) (see e.g. neomake)
  • handling of several linter/static code analyzer/...

BTW good companion plugins are

  • vim-projectionist: e.g. helpful for out-of-source builds when using CMake (similar for meson). You can define heuristics to detect out-of-source builds. I often put the out-of source build next to <project>/CMakeLists.txt into <project>/_builds/debug which means I set in my vimrc:

      let g:projectionist_heuristics = {
            \ "CMakeLists.txt&builds/debug/Makefile": {
            \   "*": {
            \            "make": "make -C {project}/builds/debug -j8",
            \            "compiler": "gcc",
            \     }
            \   }
            \ }
    

    vim-projectionist can detect your build directory automatically and allows you to press `m to compile in this directory. You have to modify this to your personal preference. You can also define several heuristics.

  • vim-unimpaired: nice additional non-clashing maps ]q, [q, ]Q, [Q to navigate the quickfix list.

Furthermore, vim-fugitive uses :Make if available for git push/pull which means it runs them async as well. You can also use other plugins for this. For example, define :Make using neomake:

command! -bang -nargs=* -complete=file Make NeomakeProject <args>

If you have added the above line, vim-fugitive runs git push/pull without blocking the editor but uses neomake and not vim-dispatch.

1

There are currently two great plugins I found that can run commands asynchronously: vim-dispatch and asyncrun.vim. The two plugins have async support for both Neovim and Vim, but you have to make sure you have relatively new versions of Neovim or Vim (see their home for exact version requirements.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.