gpt4 book ai didi

vim - 为什么我可以通过使用井号 (#) 来破坏 vim 用户函数命名规则

转载 作者:行者123 更新时间:2023-12-04 07:25:11 24 4
gpt4 key购买 nike

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 功能?

最佳答案

此命名语法适用于 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'.

关于vim - 为什么我可以通过使用井号 (#) 来破坏 vim 用户函数命名规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13552614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com