to compile C programs and run it, I use ":make" but I would like to run the compiled program too if the compile is a success.
I wrote
au FileType c setlocal makeprg=g++\ %\ \&\&\ ./a.out
in vimrc, that works, but I have a vim error when there's some mistakes in my code, so vim don't put the cursor on the good line. I get this error :
E40: Can't open errorfile /tmp/vEtUQQ2/0
Is there a workaround, a fix or another way to achieve this ?
You could create a target in your makefile to run the program (say 'run'):
.PHONY : run
run : $(PROG) # assuming $(PROG) is the name of your program
./$(PROG)
...and then in vim you would do:
:make run
There is a way with pure vim to do it, but it is a bit of annoying.
Using QuickFixCmdPost(Autocmd Event) to check if there is building error after ':make' ran. And if there are no errors, run the newly compiled program.
autocmd QuickfixCmdPost make call AfterMakeC()
function! AfterMakeC()
" No any error after make
if len(getqflist()) == 0
!./a.out
endif
" :~)
endfunction
You may want to put the script under namespace in compiler plugin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With