A script in autoload
is loaded when a function that is defined in your autoload
script is called.
The autoload
scripts have been introduced to optimize the Vim startup time. Instead of loading all the Vim scripts to make all the plugin functions available some Vim scripts loading are postponed to the moment a function that is defined in it is called.
Suppose you have a file: ~/.vim/autoload/foo.vim
with the following content:
function! foo#bar()
echom 'foo#bar()'
endfunction
The script autoload/foo.vim
will only be loaded when another scripts or call
command calls foo#bar()
:call foo#bar()
More information with: :help autoload
Remark: If you want your script to be sourced at startup unconditionally you can put it in the plugin
folder.
More information with :help standard-plugin