In my .vimrc, I set different makeprg according to the source file type as following :
au BufRead,BufNewFile /home/me/cpp/**/**.cc set makeprg=g++\ %"
au BufRead,BufNewFile /home/me/c/**/**.c set makeprg=gcc\ %\"
It's good practicse but not perfect. the problem with this setting is that you can just have on binary with the default name a.out under a certain directory.
To put it more clearly, let's say there are client.c and server.c under the same diretory. After compile the client.c in vim, you should rename a.out to some other name before you can edit server.c and compile it vim. otherwise the existing a.out will be overwrite.
So I'd like to improve the setting by add -o option to gcc or g++ to explicitly give the binary a name rather than let it named as "a.out". and also I'd like to use the source file name without fiel type extension as the binary name for a gvien source file. for example, for client.c the generated binary's name will be simply client.
Just need your help to tell me how exactly this could be done in vim. thanks in advance.