:make
is indeed the way to go as Jon said.
On Linux-like (it also applies to cygwin, but not to mingw on windows) systems where gnumake is installed, if you don't have a Makefile in your project, and if your project is made of only one file, just type :make
. It will be enough (you can play with $CXXFLAGS
, $CFLAGS
and $LDFLAGS
to tune the compilation options). Then to run the program, type :!./%<
(IIRC).
If your project is made of several files, then you'll need a Makefile to take advantage of :make
.
If you manage your project with CMake, and if you compile your project in a directory (or several -> debug, release, ...) outside the sources tree, then the integration will require a plugin. AFAIK, I'm the only one to propose such a plugin: BuildToolsWrapper integrates the management of CMake (choice of the build directory, possibility to chose between the debug, or release, or whatever build directory). It has to be coupled with one of the local_vimrc plugin.
In all cases, calling directly the compiler from within (or outside) Vim with :!g++ -o %< %
or whatever is what we used to do 15 years ago on vi. Vim has a wonderful feature: it can integrate (yes, like in IDE) the compiler. See :h quickfix
. Navigating between errors directly from the editor is much easier than extracting one error line with our eyes, typing back the line number into the editor, going back to the shell to see what exactly was rejected, ... It may be enough in C, but In C++ when we are "trying to call an overload that doesn't exist", we can't work this way (switching back and forth between the editor and the shell).