The vimscript help files state that when defining a user function:
The function name must start with an uppercase letter, to avoid confusion with builtin functions.
This is enforced except in the following cases that I discovered by looking at other's code.
"This should not work.
"But it does as long as the function is in a file called 'overrides.vim'.
function! overrides#name() abort
echo 'Test overrides\name'
endfunction
"This should not work either.
"But it does as long as the file above is in a folder called 'plugin'.
function! plugin#overrides#name() abort
echo 'Test plugin\overrides\name'
endfunction
let stupid = {}
"This should not work.
"But it does aslong as the stupid Dictionary is defined.
function! stupid.name() abort
echo 'Test stupidname'
endfunction
call overrides#name()
call plugin#overrides#name()
call stupid.name()
I looked everywhere for anything that would explain this syntax. I know this works now. What I am very curious about is, for those of you have used this syntax, where did you learn about it?
Are there other vimscript functionality that are not mentioned anywhere in the help files?
This naming syntax is for autoload
function. Type :help autoload-functions
for help.
AUTOMATICALLY LOADING FUNCTIONS ~
*autoload-functions*
When using many or large functions, it's possible to automatically define them
only when they are used. There are two methods: with an autocommand and with
the "autoload" directory in 'runtimepath'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With