Vim will set v:shell_error
with a :make
invocation, same as it does for other ways it executes external commands using the shell.
The most likely reason why you're not seeing the error code of the make
execution in v:shell_error
(and always seeing it return 0) is that on Unix platforms and most common shells Vim defaults to piping the output of execution of 'makeprg'
through the tee
program, in order to have it both displayed on the terminal and saved to a file which gets loaded into the quickfix buffer.
This is controlled by the 'shellpipe'
option, which defaults to 2>&1| tee
on most Unix platforms.
You can override this behavior (but not get to see the output of your 'makeprg'
in the terminal) by overriding it not to include a pipe to tee
. For example:
:set shellpipe=>%s\ 2>&1
Then after running :make
you'll get v:shell_error
to store the error return of the external command.
If you're using bash as your shell and your 'makeprg'
is a single program (rather than a pipeline), you can also use the following to run it through tee
and still capture the exit code of the 'makeprg'
:
:let &shellpipe = ' 2>&1| tee %s; exit ${PIPESTATUS[0]}'
v:shell_error
for:make
. Is this question about Neovim specifically? – Matt Aug 22 '20 at 15:51| tee
in'shellpipe'
, it basically always returns 0 and masks the error return code of themake
program... I'll post an answer shortly. – filbranden♦ Aug 22 '20 at 15:54