1

I used to use vim/gvim at windows, and my old .vimrc part for compilation looked like this:

autocmd filetype cpp nnoremap <F5> :w <bar> !g++ -std=c++11 -Wall % -o %:r && %:r.exe <CR>

On windows when I pressed f5 a shell (windows cmd) would open and execute it.

However now I began using vim/gvim on linux and when I press f5 it runs on a built-in shell. Is there a way to run on a external shell? I just can open an external shell by typing :! gnome-terminal, but how can I automatically open a shell with the compiler command like g++ main.cpp -o main, javac Main.java && java Main (whatever)

I looking for a solution for a while haha

I'm still improving my english, any critiscism is welcome!!

JozuTM
  • 13
  • 4

1 Answers1

0
autocmd filetype cpp nnoremap <F4> :w <bar> exec '!g++ '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR>

Try it out!

BTW, maybe here will u find useful information :)

  • thanks for the answer, but it's literally what I have. I asked for a way to run in an external terminal, this will run within vim (btw, this would work on window, but doesn't on ubuntu) – JozuTM Aug 25 '20 at 04:36
  • Oh, sorry then I wrong understood you.. My English is not native so.. – Simon Hryszko Aug 26 '20 at 14:17
  • oh, there's no problem mate, I appreciate the help – JozuTM Aug 27 '20 at 01:18