I\'d like to compile cpp file w/o turning off vi.
I know the :!g++ file.cpp but I prefer :make so I added this line in .vimrc file
It can be easily achieved by the use of key maps.
First open up your vimrc file and these lines to the file,
autocmd filetype cpp nnoremap :!g++ % -ggdb -o %:r
autocmd filetype cpp nnoremap :!g++ % -ggdb -o %:r && ./%:r
The first line maps the key F4 to compiling the file. The second line maps the key F5 to compile and run.
If you use gdb frequently then this may also come handy.
autocmd filetype cpp nnoremap :!g++ % -ggdb -o %:r && gdb -tui %:r
This line maps the key F10 to compile and start gdb
Hope this helps.