3

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

For example: when I call in my .vimrc the command plugin filetype on, is the filetype program read immediately, or after the rest of .vimrc is read? Furthermore, I'm guessing the order is that first Vim checks for a .vim/ftplugin/myfiletype.vim file before loading the "default" myfiletype.vim in $VIMRUNTIME, if it found nothing then runs the default file, and then checks for fies in .vim/after/ftplugin?

Also when set syntax=myfiletypesyntax is called, are those lines read immediately or at the end of file?

  • 1
    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 '16 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 '16 at 19:42
  • 5
    :h syntax-loading – Christian Brabandt Jul 16 '16 at 19:45
3

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, privacy policy and cookie policy

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