It seems that you're unfortunately using gcc-mingw that doesn't come with gnumake properly configured (:let $CXXFLAGS='-std=c++17 -Wall -Werror'
+ make %<
would have been enough otherwise). Thus you'll have a do a few things manually. And don't misspell the parameters to g++. And forget :!{compilername}
, this is want we had to do 25 years ago with vi. Unlike vi, vim permits to integrate compilation.
" to do once
:let &makeprg='g++ -std=c++17 -Wall -Werror % -o %<'
" to execute each time to compile
:make
:copen
" to navigate the errors
:cc " jump to error under cursor
:cnext " jump to next error
:cprev " jump to previous error
:cclose " close the quickfix window
-> :h quickfix
This shouldn't execute g++ from the wrong directory. If this still does, run :cd %:h
.
The execution should work with :./%
.
And if you wish to have hot keys for that...
nnoremap <silent> <F7> :<c-u>update<cr>:make<cr>
nnoremap <silent> <C-F5> :<c-u>./%<cr>
nnoremap <silent> <F3> :<c-u>cnext<cr>
nnoremap <silent> <S-F3> :<c-u>cprev<cr>
Automatically opening the quickfix windows only if there are errors or executing the result only if there are no errors requires a little more work.