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!