With the release of vim 8, I was wondering if there is a way to execute :s or :g asynchronously.


2 Answers 2


Short Answer: No

Long Answer:

The Async supported add in vim 8 was for I/O. From :h version8

Vim can now exchange messages with other processes in the background.  This
makes it possible to have servers do work and send back the results to Vim.

Theoretically the issue is that :s and :g operate on your current buffer. Doing work async would mean that the results would be overridden if you happened to modify the buffer before the "async find-n-swap" completed. You'd have to reload the buffer with :e! and at that point you've lost the time gained by doing it async.

There is a function call timer_start() which you could use to execute a viml function. Using a 0ms timeout would make the task execute immediately and in the background. While the theoretical issue still applies, you could write a function that takes a sequence of file names (from your args list or buffer list) and performs a :s or :g on them and then reload the files after it has completed. Rereading the documentation, it looks like if vim is "busy" the timeout might be longer, which makes it sound like the operation wouldn't be async and would stop you from inputting during the callback.

A better option for that function would be to use job_start() and call a system command to do the background file manipulation. Then use something like sed or even better use ex to perform the operations. Still have the issue with updating your current buffer since it will change in the background and now your buffer will be out of sync, but its an option.


Vim 8 only permits to execute external jobs asynchronously. Unfortunately, no vim ex command can be executed this way.

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.