Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to set makeprg based on filetype in Vim

📅 2015-May-04 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ make, makeprg, vim ⬩ 📚 Archive

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

© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon📧 Email