7

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?

Luke Davis
  • 1,397
  • 10
  • 26

1 Answers1

5

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.

Antony
  • 2,570
  • 11
  • 19