Version 8 of the Vim text editor introduced a great new feature for executing processes asynchronously. In this article I'm going to show you a plugin that makes use of these async jobs and how I utilize them to build a C++ project in the background.
AsyncRun is a plugin that is built around the new job_start vimscript function to execute processes and let them run in background. As it doesn't rely on any external environment (tmux, screen, etc.) to accomplish that, it works in GUI Vim just as well as in the terminal.
The following screencast shows a traditional synchronous make call followed by an execution of AsyncRun:
To get the neat success marker in vim airline, you can put the following code snippet into your ~/.vimrc:
Note: I got this snippet from a github issue page related to the vim-airline project.
To use the async job feature you will probably need to update your currently installed Vim. The github.com/vim/vim offers some ways how to do that. You can find further information via the Vim help:
For me there's still the question why we need an external plugin for that functionality. At the moment Vim 8 was announced, my first thought was: "finally we can use some extension to the ! command and throw away that plugin (vim-dispatch)!". Of course, after a quick peek over the AsyncRun code with my limited understanding of vimscript, I see there are plenty of other things to do besides executing a background process. So, probably we do need an external plugin. That said, I do like Tim Pope's vim-dispatch plugin very much and would really appreciate Vim 8 support.
There are some performance considerations as well. Echoing a 500 line text file using AsyncRun takes about 3 seconds. This makes it nearly impractical to run unit tests in a TDD environment. This has to be further evaluated though.
What do you think? Leave me a comment via twitter: @ronalterde.