I am using a plugin that sets makeprg to some value specific to the filetype's programming language. I want to use my global setting instead, because I also use Makefiles. How can I do this? Thank you!

This happens for me with vim-ledger --- https://github.com/ledger/vim-ledger/blob/master/compiler/ledger.vim#L29-L31 --- and with vim-racket --- https://github.com/wlangstroth/vim-racket/blob/master/ftplugin/racket.vim#L36 --- When it happened for both, I assumed something was going wrong with me and I shouldn't be just commenting out lines of plugins on my local copy.

  • 1
    Welcome to Vi and Vim!
    – D. Ben Knoble
    Commented Sep 20, 2020 at 20:17
  • 1
    Jay can you edit your question and provide more details starting with which plugin you're using?
    – B Layer
    Commented Sep 21, 2020 at 11:24
  • 1
    I believe you are correct. I always want my global setting and never want the local settings of any filetypes. My preference would be to have one thing in my vimrc that will guarantee it can never be overridden, rather than having to do something special for every filetype, but I accept if that's not possible. Thank you! Commented Oct 3, 2020 at 20:07
  • 1
    @JayMcCarthy This may do it... create a file ~/.vim/after/ftdetect/makecheck.vim containing the following line: au BufRead,BufNewFile * if &makeprg != 'XXX' | set makeprg=XXX | endif. Replace XXX with whatever your global setting is. (Note quotes on first instance, not second.) Not a vimrc entry but it's a one-time deal...should work for all filetypes. Can you give it a try?
    – B Layer
    Commented Oct 10, 2020 at 4:05
  • 1
    Actually, it's probably better to use !=# instead of !=. BTW, I did try this using a simple test and it worked but I wanted you to confirm before I add it to my answer.
    – B Layer
    Commented Oct 10, 2020 at 9:19

1 Answer 1


Assuming that the plugin is using the standard scheme for filetype specific configuration...

Probably the simplest way to override is by creating a file in $MYVIMDIR/after/ftplugin with filename that matches the filetype (aka ft) setting when such a file is loaded. The plugin likely has a file of the same name and it will either be in directory ftplugin within its own installation directory or in the shared location for such files, $MYVIMDIR/ftplugin.

As an example, filetype specific settings for Java source files would be in a file named java.vim so to override you'd do:

vim ~/.vim/after/ftplugin/java.vim

(Assuming *nix style home directory.) Inside that file you'd then assign appropriate values to whatever settings you want to override.

In your specific case where you have a custom 'makeprg' value you'll want to do:

set makeprg=<whatever>

(If you just wanted to reset to the default value you could do set makeprg&.)

You can find some additional details in the "DISABLING" section under :h ftplugin

Update: So the above is a valid solution but requires taking action any time a new plugin that overrides makeprg comes along. OP wondered if there's a way to take care of current and future plugins in one fell swoop. This'll do the trick...

In your Vim "home directory" (e.g. ~/.vim) create a file in after/ftdetect. Name doesn't matter. I chose makecheck.vim. Then add the following line to it:

au BufRead,BufNewFile * if &makeprg !=# 'XXX' | set makeprg=XXX | endif

XXX should be replaced with whatever global makeprg value you're using.

As the name suggests, files in the after sub-tree get processed after other Vim files. This ensures the settings within aren't overwritten (by a plugin, for instance). It should be pretty self-explanatory how it works from there.

  • Why after/ftdetect? Those are generally used for setting filetypes. Perhaps after/plugin (or just plugin) is better?
    – D. Ben Knoble
    Commented Oct 13, 2020 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.