Autoloading Functions

The main point of autoload is to make it easy to use reusable functions. To use a function from more than one script file, we place it in a script file under the autoload directory. Vim calls this kind of file a library script. We can call the functions in that file from anywhere else in the plugin.

There’s a special syntax for calling autoloaded functions. As an example, if we had a file called mpc.vim in the autoload directory and it contained the function FromAutoload, this is how we would call FromAutoload from another function:

 
function​! ForExample()
 
call​ mpc#FromAutoload()
 
endfunction

Everything before the # represents a part of the path to the mpc.vim file; the last piece before the # is the filename ...

Get The VimL Primer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.