2

When I set makeprg using:

set makeprg=gcc\ -Wall\ -g\ %\ -o\ %

and then invoke :make Vim does not pass proper filenames, because this command is translated as:

gcc -Wall -g file.c -o file.c

and executed. The compiler is then complaining that input and output files are the same, which is in fact dangerous. My question is how to change the second % in makeprg to have it without .c extension. The command exectuted should be like this:

gcc -Wall -g file.c -o file

I don't know what to put instead the second %.

1

Unless you're using a non-properly configured version of gnumake (Solaris OS, or mingw distribution of gcc under windows), you don't need to modify &makeprg. Its default value is already perfect for GNU compilation tools.

All you need to do is to set $CFLAGS with :let $CFLAGS="-g -Wall", and compile with :make %<.

6

You can modify what is being expanded using so called filename modifiers. See the help at :h filename-modifiers (link).

In your case you can e.g. use :set makeprg=gcc\ -Wall\ -g\ %\ -o\ %<

See also the faq

1
  • Thank you, this is a wonderful answer and it solves my problem PERFECTLY!
    – piotao
    Nov 11 '16 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.