16

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
user1614244
  • 263
  • 1
  • 2
  • 5

2 Answers2

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

Others can explain this a lot better.

Bernhard
  • 11,992
  • 4
  • 59
  • 69
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
slm
  • 363,520
  • 117
  • 767
  • 871
itsbruce
  • 1,744
  • 1
  • 10
  • 12