Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I break vim user-function naming rule by using a pound sign (#)

Tags:

vim

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?

like image 505
dkinzer Avatar asked Nov 25 '12 15:11

dkinzer


1 Answers

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'.
like image 132
kev Avatar answered Sep 29 '22 20:09

kev