The easiest approach is using the Vim option makeprg. You set the option:
:set makeprg=g++\ %
Note that spaces must be escaped in the makeprg option (annoying Vim misfeature).
You can then build using the command:
:make
The errors will automatically be placed in the quickfix window. You can jump to an error using enter in the quickfix window, and select an error in the quickfix list using:
:cnext :cprevious
To avoid having to write a build script like a Makefile, you can write the
appropriate makeprg setting in a Utl vimscript URL. Utl is
the Universal Text Linking plugin for Vim. Here is a simple example:
// <URL:vimscript:set makeprg=g++\ %>
You can then set makeprg by placing the cursor over the URL and
pressing <Leader>gu.
- See also Build Systems