capture output of a vim command into a quickfix windows without freezing vim

961 views
Skip to first unread message

FlashBurn

unread,
Oct 17, 2013, 2:29:50 PM10/17/13
to vim...@googlegroups.com
My colleague at work is using Emacs and it I recently saw a really nice feature that he is using. Whenever he compiles his code the output is dumped into a scratch buffer in what I would call "live" mode. Meaning he can edit files while the code is being compiled. I was wondering if it is possible to do something like this in Vim.

I have mapped my make and setup my quickfix window to work with it. However whenever I execute make, I have to wait till it finishes. Is there a way in Vim to execute make, see make target execution as if it is being executed in a shell, capture the output, and then navigate this output?

Any help is appreciated.

Gary Johnson

unread,
Oct 17, 2013, 4:59:30 PM10/17/13
to vim...@googlegroups.com
Vim is not multi-threaded, and it has only one command line, so you
can't run a command in the foreground of one window while editing in
another window.

I looked at ":help remote.txt" but didn't see anything there that
would do what you want, but I don't use the client-server
functionality so I could easily be wrong about that.

The easiest "solution" is to run your make command in a different
Vim instance.

Another approach is to run make in the background and send its
output to file. Then, when that make is done, you can use :cfile
command to open that file in a quickfix window.

To know when your background make is done, you can have it echo a
message to its stdout, stderr or /dev/tty, which unfortunately
messes up your display, or you can use a Unix command such as
xmessage to display a message in an X window. One nice thing about
using xmessage is that you can be working in a different workspace
from the one in which you ran make and still be informed when make
is done.

HTH,
Gary

Marc Weber

unread,
Oct 17, 2013, 5:12:26 PM10/17/13
to vim_use
Vi as bad at async communication. Still some workarounds exist.
You may want to look at github.com/MarcWeber/vim-addon-async which is
using github.com/MarcWeber/vim-addon-background-cmd which is running a
background shell which calls back into Vim to tell it "job is ready"
by using client-server feature which in turn requires X (or use vim nox
patch)

Alternative solutions exist which use Vim's idle event to poll for
updates. See list of related projects in github.com/MarcWeber/vim-addon-async
which also lists yet another Vim patch (terminal version only).
The async implementation provides a similar API for VimL plugins, but is
also using the vim-addon-background-cmd way calling back into Vim using
client-server. For quickfix I don't use -async because its causing a
noticable delay IMHO.

There is still one difference: Emacs updates a grep /compile list while
you can continue editing. vim-addon-async, vimproc, .. are vim like
solutions.

For an older version of Vim there is als a thread patch which allows to
run a terminal in vim, or see ConqueTerm.

While the order of projects listed here might be biased (cause I'm the
author), I still hope that the overall overview is kind of complete.

Marc Weber

Ben Fritz

unread,
Oct 17, 2013, 11:55:22 PM10/17/13
to vim...@googlegroups.com, gary...@spocom.com
On Thursday, October 17, 2013 3:59:30 PM UTC-5, Gary Johnson wrote:
>
> I looked at ":help remote.txt" but didn't see anything there that
>
> would do what you want, but I don't use the client-server
>
> functionality so I could easily be wrong about that.
>
>

Not directly, but you can call arbitrary Vim functions with --remote-expr

>
> The easiest "solution" is to run your make command in a different
>
> Vim instance.
>
>
>
> Another approach is to run make in the background and send its
>
> output to file. Then, when that make is done, you can use :cfile
>
> command to open that file in a quickfix window.
>
>

Yes, I'd suggest this approach. But you don't need to do the :cfile manually.

http://vim.wikia.com/wiki/Execute_external_programs_asynchronously_under_Windows gives a method on Windows for async grep commands. The idea would be the same for "make" commands.

You shell out to start a command in a background process that will do the compile, AND when that compile is done will use --remote-expr to tell Vim to load a file with :cfile.

There are also some plugins out there to simplify the task I think.

Note, the quickfix window will not update dynamically as the compile happens. But it will allow you to keep using Vim while it is going on.

Andrew Stewart

unread,
Oct 18, 2013, 1:30:04 AM10/18/13
to vim...@googlegroups.com, vim...@googlegroups.com, gary...@spocom.com
There's also vim-dispatch for asynchronous builds.

https://github.com/tpope/vim-dispatch

skywind3000

unread,
Oct 25, 2016, 4:09:14 PM10/25/16
to vim_use
Reply all
Reply to author
Forward
0 new messages