I've had some issues reconciling my .vimrc with files in ftplugin and after/ftplugin. In what order are they all read?

For example: When vim encounters the line plugin filetype on in a .vimrc file, is the filetype program read immediately, or after the rest of .vimrc executes? Further, am I correct in assuming that vim checks for a .vim/ftplugin/filetype.vim file before loading the "default" $VIMRUNTIME/ftplugin/filetype.vim (only running the default file if no user version is found), then checks for files in .vim/after/ftplugin?

  • 3
    I'm not going to post this as an answer, because it isn't a full answer, but you can call :scriptnames to see a list of every single file that has been sourced, and the order it was sourced in.
    – DJMcMayhem
    Jul 16, 2016 at 19:23
  • Does that list imply the files are read strictly sequentially? Like a plugin file will never be "cut" inside the .vimrc text?
    – Luke Davis
    Jul 16, 2016 at 19:42
  • 5
    :h syntax-loading Jul 16, 2016 at 19:45

1 Answer 1


When filetype plugin on is encountered in your vimrc, $VIMRUNTIME/ftplugin.vim is immediately executed. This creates an auto command which does the following:

exe 'runtime! ftplugin/' . name . '.vim ftplugin/' . name . '_*.vim ftplugin/' . name . '/*.vim'

This executes all matching files in each directory in 'runtimepath'.

Note that auto commands are executed in the order in which they are defined, so if you have the following in your vimrc:

au filetype php echoerr 'before'
filetype plugin on
au filetype php echoerr 'after'

And have this at the top of $VIMRUNTIME/ftplugin/php.vim:

echoerr 'during'

Then you will see the errors 'before', 'during', 'after' echoed in sequence when you edit a php file.

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.