tags:

views:

176

answers:

2

Is there a way to compile and run a C program from VIM without typing its filename ?

+11  A: 

:!gcc -o somename % && ./somename
When using :!, % will be subsituted by the name of the currently opened file.

When your project becomes larger, you can also write a makefile and compile the current project with :make, if there are any errors, vim will jump to them automatically.

tstenner
+1 for pointing out that % is substituted by the filename.
René Nyffenegger
I like you answer. I want to make it final. Please guide.
Coder
I need 15 votes to make it final :(
Coder
@Coder: No, you can accept the answer. Just click the check. You don't need any amount of votes for that.
rampion
+2  A: 

use the following mapping code in your .vimrc file. for compile and run a c programming file.

map : !gcc % && ./a.out

F8 key for run the mapping.

"%" is taken the current file name.

ungalnanban