Running :make from gVim in Background

2019-01-08 09:55发布

I use gVim in windows to edit my code (mostly C++). I use :make in gVim to compile the project, but this is a blocking operation, that prevents me from using gVim until the compilation is complete. How can I do :make asynchronously and still get the benefits of reading the errors back into Vim and jump to the errors in source code? Bonus points if I get to see the make process in real time. Right now the :make redirects the output into a file, hence I don't get to see the progress of make.

7条回答
相关推荐>>
2楼-- · 2019-01-08 10:27

Have a look at @tpope's dispatch.vim

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

Video Trailer: http://vimeo.com/63116209

查看更多
Animai°情兽
3楼-- · 2019-01-08 10:29

What I do is

:!gvim -c 'MyMake'

( where MyMake is the custom command which can switch to appropriate dir, make, and copen 20. )

and I am doing my job while build goes in the other window.

Other option:
You can redirect make progress to some file from the shell or within vim (:!make&). And then by using

:cfile make_result_file

:cw
 or
:copen 20 

Achieve the same result as you'd use :make

查看更多
女痞
4楼-- · 2019-01-08 10:38

You won't be able to see the progress of make (within Vim) unless you install a very recent version of Vim (v7.4 and many patches, or simply Vim 8). Now there are a few plugins that've taken advantage of it. My BuildToolsWrapper is one of them. I've tested it successfully on linux and on windows.

Before that we needed other tricks. I remember Marc Weber's plugin which was able to emulate background compilation on Windows. There was a few others. I let others list them.

查看更多
等我变得足够好
5楼-- · 2019-01-08 10:38
兄弟一词,经得起流年.
6楼-- · 2019-01-08 10:39

Have a look at my AsyncCommand plugin. It's just wraps the vim syntax required to execute something and load it with --remote. I've uploaded AsyncCommand 2.0 that includes an AsyncMake command.

Add the script to your .vim/plugin and you can build with :AsyncMake or :AsyncMake target. Errors will be opened in your quickfix once the make completes.


Responding to comment for more readable code:

To see the build results on Windows, if you have cygwin/unxutils/something with tail in your path, then in asynccommand.vim, change

call <SID>Async_Impl(tool_cmd, vim_cmd)

to

call <SID>Async_Impl(tool_cmd, vim_cmd)
call <SID>Async_Impl("tail -f ". temp_file, "")

That should change all Async commands to open up a second command window with the output.

查看更多
啃猪蹄的小仙女
7楼-- · 2019-01-08 10:45

Try using

:!start make

(more info on ":help !start") - that way vim doesn't have to wait for the process started to finish - you can just keep on going with your editing).

查看更多
登录 后发表回答