Friday, March 12, 2010

Compile and Run For C/C++ programmers on vim

If the file is named file.cpp or file.c, in the vim command mode just type in:

:!make abc

The first command compiles file abc.cpp to the executable file abc in the current directory. You can then execute it using the second command.

Alternatively, you could use something like :!g++ -g -Wall file.cpp -o file if you want to specify your own compilation options. (Anything more complex and you should be using a Makefile anyway).

1 comment:

  1. In fact, the ! before make is optional. Vim just figures things out for you. Also Note: no makefile needs to be written before using this command.