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).