Reputation: 45652
If you start up vim with something like this:
vim -S myscript.vim file.txt
What is the load order of scripts? Does myscript.vim get loaded after or before ~/.vimrc.
If you pass in vimscript commands to vim directly on the command line, when do they get executed relative to sourced and default vimscripts?
Upvotes: 30
Views: 11738
Reputation: 1775
The answer is myscript.vim
gets loaded dead last.
The vim -V
option is a lifesaver here. (Capital -V
, because -v
starts in vi
mode.) Just ran across it, after searching further since although the other answers answered your question, they don't show what wasn't sourced because it wasn't found. If I could send it back in time, I'd save myself a lot of time banging my head against strace
output.
This will not only show you all of the scriptnames that it did source in order, but also all of the scriptnames that it would have sourced if they existed in order. So, you can discover what files you can create to load at the appropriate time.
$ vim -V
Adding it to your vim arguments easily answers the question.
$ vim -V -S myscript.vim file.txt
It shows myscript.vim
as dead last.
It prints a ton, and winds up at a "Press ENTER or type command to continue" prompt, which lets you step through Autocommands.
Upvotes: 5
Reputation: 40947
The help entry is way too long to post here, but it lists the order of everything that vim does at initialization. See :help initialization
.
Upvotes: 35
Reputation: 22256
I believe vimrc is always first. You can run :scriptnames
to get a list of sourced scripts in order in which they were first sourced in your Vim instance.
Upvotes: 41