9

vimscript 帮助文件声明在定义用户函数时:

函数名必须以大写字母开头,以避免与内置函数混淆。

除了我通过查看其他代码发现的以下情况外,这是强制执行的。

"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()

我到处寻找可以解释这种语法的任何东西。我知道这现在有效。我很好奇的是,对于那些使用过这种语法的人来说,你是从哪里了解到它的?

是否还有其他在帮助文件中未提及的 vimscript 功能?

4

1 回答 1

10

此命名语法适用于autoload函数。键入:help autoload-functions寻求帮助。

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'.
于 2012-11-25T15:56:13.967 回答