I am using vim editor on Linux mint. I want to know if there is any way to compile c program without leaving the editor.
Asked
Active
Viewed 6.3k times
16
-
Check out https://github.com/tpope/vim-dispatch – elig Feb 17 '21 at 01:07
2 Answers
21
There are several possibilities.
One method is to compile using
:!gcc file.c
But a nicer strategy would be to have a Makefile and compile just using
:make
Where the easiest Makefile would look like.
program:
gcc file.c
Bernhard
- 11,992
- 4
- 59
- 69
-
2According to [Is there a vim shortcut for
?](http://unix.stackexchange.com/questions/14353/is-there-a-vim-shortcut-for-name-of-current-file), `:!gcc %` seems handier. – manatwork Oct 22 '12 at 12:21 -
1@manatwork That only works if the current file is actually the main program. – Bernhard Oct 22 '12 at 12:28
-
-
-
2@user1614244 - step 1) learn to use make, step 2) invoke `:make`. Note however that you can set `makeprg` to the build tool of your choice – Useless Oct 22 '12 at 14:24
9
The canonical way to do this in Vim is to use the compiler configuration setting. Your vim installation almost certainly comes with a compiler plugin for gcc. Type :help compiler in Vim to find out more about how this works.
To associate gcc with c source files, you need something like this in your .vimrc:
au BufEnter *.c compiler gcc
-
8How would you go about invoking the compiler once you have set it? – Alex Chamberlain Oct 22 '12 at 22:13