In short, I need to know in a Makefile whether `make is being invoked from ViM or not. Is there a certain variable (such as ENVIRONMENT or something), that ViM would set to a specific value?.
The reason I need this is the following:
If called from bash, I could do all sorts of wonderful stuff for user (or myself), such as giving messages as to which subsystem is being built and highlighting errors and warnings.
The problem is however that, when called from ViM, the error messages already get captured and introducing \x1b
commands (for color) makes the messages incomprehensible to ViM. What I want to do is basically disable coloring when :make
is issued in ViM.
Even though I'd rather have the Makefile resolve it, I am open to other solutions.
I'd either tell the makefile explicitly that you don't want colouring, or filter it out. If you try to guess inside the makefile, it's liable to break when you use a different editor, or shell, or tweak your environment.
My preference would be to just filter out the non-printable characters:
:set makeprg=make\ $*\ \\\|filter
since this doesn't require explicit workarounds in the makefile. However, the required filter itself is non-trivial: see for example this question on unix.stackexchange.
Alternatively, as already suggested, the easiest way to tell your makefile explicitly is to add a variable to your invocation:
:set makeprg=make\ NO_COLOUR=1
or whatever (make
should be the current value of makeprg
).
.
Inside Vim, you can set environment variables that are inherited by opened shells; e.g.
:let $INSIDE_VIM = 1
If this is just about :make
, you can manipulate the 'makeprg'
that determines what is invoked:
:set makeprg=export\ INSIDE_VIM=1;make
If you're just concerned about the escape sequences for coloring, you could just set $TERM
to something that doesn't understand colors (dumb
maybe?) and if the coloring isn't hard-coded (which unfortunately is a big if in many tools), it should obey the terminal setting and not print the escape sequences.
You can alter your vim binding to SOURCE="vim" make
, so in your makefile the $$SOURCE
variable is set to "vim".
Edit: I see you are in fact not using bindings in vim, you can use them with the following line in your .vimrc
(or /etc/vimrc
) like this:
:nmap <F5> <CR>SOURCE="vim" :make<CR>
This will bind F5 to what you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With