In general, I have makefiles setup anytime I'm working on C projects. To save and compile these projects, I've bound the ' key to do this:
map ' :wa<CR>:!make<CR>
However, I sometimes open up test files that don't have a makefile, and want to compile those quickly as well:
map ' :wa<CR>:!gcc % -o %< && ./&<<CR>
My question is, how do I create a function to detect if a makefile exists, and then execute the appropriate command? The pseudocode would be the following:
If (makefile exists)
run make
else
run gcc on the single file
The only knowledge I have on the vimscript for it would be that I have to bind the ' key to a function. Thanks for any help!
:make
command may also be of interest. It callsmake
by default but can be tweaked to call any command. Nice thing is it captures output and you can jump to errors.