0

I want to be able to compile and run C++ files directly from inside vim. I have a custom compilation alias gmm defined in ~/.bash_aliases. I do not want to copy it over to my ~/.vim/ftplugin/cpp.vim file as it is quite a big command (several warning flags and stuff).

If I use the following I get an error:

nnoremap <F4> :w<CR>:vs \| te gmm % && ./a.out < in<CR>i
inoremap <F4> <esc>:w<CR>:vs \| te gmm % && ./a.out < in<CR>i

since vim cannot find the gmm alias. Is there any way to make the alias available to the cpp.vim file?

12
  • Have you tried something like :term bash -ilc gmm May 13, 2020 at 13:49
  • @ChristianBrabandt If i execute it inside vim, it says "Command gmm not found. Did you mean..." May 13, 2020 at 13:51
  • I think you need to configure the $BASH_ENV variable, e.g let $BASH_ENV = "$HOME/.bash_aliases"
    – Biggybi
    May 13, 2020 at 13:55
  • 1
    Welcome to this site Gauran! :) I feel like this is a duplicate of this question because the solution will probably be the same. Also if you want to do this kind of compilation I strongly recommend that you take a look at :h 'makeprg' to do it the right way :)
    – statox
    May 13, 2020 at 14:16
  • 1
    Thank you statox and @filbranden ! I setup gmm a custom bash script, added it to path, and setup makeprg and now it works perfectly! May 14, 2020 at 6:12

0

Browse other questions tagged or ask your own question.