Skip to main content
Added how to run the resultant executable
Source Link
Pierz
  • 726
  • 9
  • 11

Vim can be used to compile using gnu make on the current file - even if there's no Makefile for the file (for more details see here):

:make %:r

This way vim provides you with access to the quickfix error feedback from the compiler (:help quickfix) list - :cn Next error, :cp Previous error, :cw New window listing errors.

If you've not got gnu make then you can set the makeprg variable (change to g++ if you're compile C++):

:se makeprg=gcc\ -o\ %<\ %

and then use the vim make command to compile the current file and get a quickfix list of errors in vim:

:make

EDIT: If you also want to run the compiled executable from within vim you can do ('!' executes, '%:r' is the filename without its suffix):

:!./%:r

Vim can be used to compile using gnu make the current file - even if there's no Makefile for the file (for more details see here):

:make %:r

This way vim provides you with access to the quickfix error feedback from the compiler (:help quickfix) list - :cn Next error, :cp Previous error, :cw New window listing errors.

If you've not got gnu make then you can set the makeprg variable:

:se makeprg=gcc\ -o\ %<\ %

and then use the vim make command to compile the current file and get a quickfix list of errors in vim:

:make

Vim can be used to compile using gnu make on the current file - even if there's no Makefile for the file (for more details see here):

:make %:r

This way vim provides you with access to the quickfix error feedback from the compiler (:help quickfix) list - :cn Next error, :cp Previous error, :cw New window listing errors.

If you've not got gnu make then you can set the makeprg variable (change to g++ if you're compile C++):

:se makeprg=gcc\ -o\ %<\ %

and then use the vim make command to compile the current file and get a quickfix list of errors in vim:

:make

EDIT: If you also want to run the compiled executable from within vim you can do ('!' executes, '%:r' is the filename without its suffix):

:!./%:r
Source Link
Pierz
  • 726
  • 9
  • 11

Vim can be used to compile using gnu make the current file - even if there's no Makefile for the file (for more details see here):

:make %:r

This way vim provides you with access to the quickfix error feedback from the compiler (:help quickfix) list - :cn Next error, :cp Previous error, :cw New window listing errors.

If you've not got gnu make then you can set the makeprg variable:

:se makeprg=gcc\ -o\ %<\ %

and then use the vim make command to compile the current file and get a quickfix list of errors in vim:

:make