I've been using vim recently to program in C. I have created shortcuts for compiling and running the programs from within vim itself, but recently vim's process has been stopping after executing the program.
foo.c:
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
.vimrc:
set shellcmdflag=-ic
syntax on
autocmd FileType c map <F6> :!gcc -o "%:p:r.out" "%:." <bar> more<CR>
autocmd FileType c map <F7> :!%:p:r.out<CR>
If I hit F6, the program compiles fine. But if I hit F7, I get the following:
Hello World!
[1]+ Stopped vim test.c
I can use fg
to start the process back up, but it's getting slightly annoying to do so. Does anyone know how to fix this?
Best Answer
Don't use an interactive shell to execute commands. (That's the
i
in-ic
.)The default shellcmdflag (
-c
) should work just fine.If you are specifying
-i
in order to get bash to read your.bashrc
file (which is a side-effect of starting an interactive shell), then you would be better off just telling bash to read a startup environment script. Quoting the bash manpage:You can set environment variables inside vim with
:let