compile directly from vim

后端 未结 6 1230
独厮守ぢ
独厮守ぢ 2021-01-31 05:43

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

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 06:18

    You need the substitution there, try something like:

    set makeprg=gmake\ %:r.o
    

    Oh, this assumes that you've got:

    1. a (M|m)akefile in the directory, or
    2. default SUFFIX rules are available for your environment (which it looks like there aren't)

    Check for the default by entering:

    make -n .o
    

    and see if that gives you something sensible.

    If there is a makefile in another location you can add the -f option to point at the makefile, for example:

    set makeprg=gmake\ -f\ ../some_other_dir/makefile\ %:r.o
    

    BTW For learning about make, and especially gmake, I'd suggest having a look at the excellent book "Managing Projects with GNU Make" (sanitised Amazon link).

    HTH.

    cheers

提交回复
热议问题