微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我可以使用井号(#)来破坏vim用户功能命名规则

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

The function name must start with an uppercase letter,to avoid
confusion with builtin functions.

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

"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功能在帮助文件中没有提到?

此命名语法用于自动加载功能.键入: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'.

原文地址:https://www.jb51.cc/vim/384820.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐