I understand it's the place to put things that should have the final say and not be overridden by another source, but I'm unclear on how to decide when to put something in, say, ~/.vim/after/ftplugin/ rather than ~/.vim/ftplugin/.

Do people generally use ~/.vim/ftplugin/ and only move stuff into ~/.vim/after/ftplugin/ if they observe unwanted behavior, or do they just put it all in the after-directory right away?


Generally, if you want to add your own plugin, or replace a standard plugin with your own, it would go into ~/.vim/plugin or ~/.vim/ftplugin. If instead you want to keep the functionality of an existing plugin but add to it, or change just a few settings made by it, then your plugin would go into ~/.vim/after/plugin or ~/.vim/after/ftplugin.

  • For some reason I always assumed Vim searched the runtimepath and sourced each file that matched the search criteria, rather than just sourcing the first match it found. It kind of sounds like stuff in the after-directory gets that kind of "in-addition-to" treatment, but maybe everything else gets treated more like the Unix PATH variable, where the first match wins? – ivan Jun 27 '17 at 2:07
  • 6
    Vim does source each file that matches the search criteria, but properly-written plugins have a test near their top of the form, if exists("g:loaded_<plugin name>") finish endif let g:loaded_<plugin name> = 1. The plugin that's loaded first "wins" and subsequent plugins of the same name exit early through the finish command. That's how a plugin in your ~/.vim/plugin directory, for example, can prevent a plugin in $VIMRUNTIME/plugin from loading completely. That test is not included in after plugin files. – garyjohn Jun 27 '17 at 5:22
  • Ok, I think I get it now. Since all matching files will be sourced, use a finish guard-clause when you want to load only the first match, and use the after-directory (without a finish guard-clause) when you need to override a setting that's affected by one of the other sources. – ivan Jun 27 '17 at 12:12

if vanilla vim recognizes a certain filetype and you want to modify the shipped behavior then your own settings go into ~/.vim/after/ftplugin/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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