Alex Rivera | Logout

compile directly from vim

Asked 2009-02-12T10:22:51.663
16

I'd like to compile cpp file w/o turning off vi.
I know the :!g++ file.cpp but I prefer :make so I added this line in .vimrc file

au FileType C set makeprg=gcc\ %
au FileType Cpp set makeprg=g++\ %

but I keep getting
"make: ***** No targets specified and no makefile found. Stop.** "message.
can anyone tell me what is wrong with my setting?
I use to compile successfully with the option above.

Edit
Report

2 Answers

6

I should change C,Cpp into c,cpp, then it works fine.

thank you all, especially Rob Wells, your answer helped me a lot. thank you.

answered 2009-02-13T01:00:06.237
-5

First of all, just make the bloody make file. Every tool out there is expecting to work with make and if your compilations are that simple it takes about 30 seconds to write a make file that compiles all c and cpp files into an executable.

Second, if you refuse to use a make file then try

:help system

That should give you enough info to come up with your own command similar to this

:com Mymake call system("g++ ".expand("%"))
answered 2009-02-12T22:17:35.567

Your Answer