novice
novice

Reputation: 545

Compiling a C++ program in Vim

I am using Ubuntu 16.04, with Vim

Can't find a way to compile and run my C++ program in Vim.
I have appended this to my vimrc file

nnoremap <silent> <F8> :!clear;gcc % -o %:r && ./%:r<CR>  

from this question: How do I run a C program from VIM?
But it isn't working - my program doesnt seem to compile when I press F8.

Any help would be appreciated.

Upvotes: 0

Views: 4222

Answers (2)

Wen-Chi Guo
Wen-Chi Guo

Reputation: 1

You can simply create a makefile and then add nmap <F8> :make!<CR>:cw<CR> to your vimrc file

Upvotes: 0

Luc Hermitte
Luc Hermitte

Reputation: 32926

You should have gone for the vim way of doing things. In particular in C++.

Calling g++ from :! instead of :make is really counter-productive (:h quickfix).

Follow this path instead: https://stackoverflow.com/a/35702919/15934 (1), unless you are under windows with the poorly configured make from MingW, in which case, follow this path: https://stackoverflow.com/a/22452184/15934

(1) If you want a mapping, it would be something like:

nnoremap <silent> <F8> :update<cr>:make %<<cr>

Upvotes: 1

Related Questions