I would like to run :make
in Vim, while also allowing the user to edit a file while we're waiting for the compilation to finish, then when the compilation is finished open the result in a split window (which I know by itself would be done with :make | copen
) with how long it took for the make to run (preferably in a human-readable format, e.g., 5m 32s instead of 332s). Is this possible? I'm guessing using the UNIX time command I could edit my Makefile to do the time measurement, but does Vim have the ability to time the make command itself?
1 Answer
It's possible, with Vim8.
- First you'll need to register the current time with
reltime()
function. - Then, start a job that'll run the content of
&makeprg
with$*
replaced with the target you wish to used (it may be an empty string). Don't forget to register a hook that'll listen for any line produced by the compilation. You'll certainly wish to add it to:caddexpr
. - And also, you'll have to register the close callback. In this one you'll know whether the compilation has succeeded, and you'll compare the new
reltime()
with the registered one.
Note: that while I don't display the compilation time in lh-vim-lib+build-tools-wrapper, it's easy to add (actually I display it when we put the lh/btw/job_build.vim
autoload plugin in verbose mode).
-
1I'm not an advanced Vim scripter, so I have no idea how to do step 1, 2 or 3. Could you boil it down to a set of commands or additions to my
~/.vimrc
? Mar 30, 2017 at 7:38 -
-
@Vitor That creates a split window during the build process but it doesn't show it after the build is completed (i.e., as soon as the build is completed it closes the compilation split window), nor does it show the compilation time. Mar 30, 2017 at 10:45
-
@Brenton Horne. The thing is that a correct solution will take a couple hundred lines -- see my third link. This is not something that fits nicely in a
vimrc
. If you're not afraid of big plugins I can add an option in my build-tool-wrappers plugin to display the compilation time even in non verbose mode. Mar 30, 2017 at 10:56 -
@LucHermitte That option in your plugin sounds great, please. If it works I'll be happy to accept this answer. Mar 30, 2017 at 10:58
:make
though (Like being able to jump to errors and such).