Is there any way for me to define a command (i.e :compile) to compile C/C++ code inside vim? I know I can use :!g++ %:p for that but is really tricky to type all these special characters.
Thanks in advance.
Is there any way for me to define a command (i.e :compile) to compile C/C++ code inside vim? I know I can use :!g++ %:p for that but is really tricky to type all these special characters.
Thanks in advance.
You can use the :make command in Vim. By default it runs make but you can set the makeprg variable to be whatever program you want.
So for your example.
:set makeprg=g++\ %
and then you can
:make
makeprg is because you don't want to use make, i.e. you don't have a Makefile. Changing makeprg to g++\ % calls g++ directly on your source file, so it's good for quick experimenting.mkdir test && cd test && gvim hello.cpp , write an hello world program, and then, type :make.make: *** No targets specified and no makefile found. Stop.makeprg to python or runhaskell or whatever you like. It doesn't have to be tied to make.