How to set makeprg based on filetype in Vim

The command string set in makeprg in Vim is applied to compile a file or a project when you invoke the :make command.

For most types of files, this usually just invokes the make program. You can see what makeprg is set to for a certain filetype, by opening a file of that type and trying :set makeprg?

You can set any program to run on the current file or any other file when :make is invoked, by setting makeprg yourself.

To set it based on a certain filetype, say for filetype foo, add this to your Vimrc:

autocmd Filetype foo setlocal makeprg=/bin/foo_compiler %

The percent character denotes the path to the currently open file.

Tried with: Vim 7.4 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.