0

I noticed that when functions in plugin/myplugin.vim are named using the autoload convention, function! myplugin#myfunction(), the file autoload/myplugin.vim gets sourced on vim startup, even though no function of that file is ever called during the startup process. This happens for example with vim-peekaboo. Changing the functions peekaboo#{on,off} to e.g. Peekaboo_{on,off} fixes the issue, but I was wondering whether this was documented behavior? Also, is there a canonical way of naming functions in plugin/myplugin.vim?

  • Yes this is documented; this is how autoloaded functions work. Any function with that type of name causes autoload files to be searched and possibly sourced. I dont tend to put many functions in plugin. – D. Ben Knoble Dec 13 '18 at 12:40
  • Thanks, but wouldn't you expect vim to check first whether the function is already defined? – Rastapopoulos Dec 13 '18 at 12:42
  • Read the section on autoloading-functions – D. Ben Knoble Dec 13 '18 at 12:52
  • It says the following (emphasis mine): When such a function is called, and it is not defined yet, Vim will search the "autoload" directories in runtimepath' for a script file called "filename.vim". Or am I missing something? – Rastapopoulos Dec 13 '18 at 13:47
  • Perhaps the function definition causes vim to check if such a function is defined? Particularly if using function! – D. Ben Knoble Dec 13 '18 at 16:01
1

Untested, but my theory is that during startup the definition of a function (particularly using function!) causes vim to check if a function by that name is defined, and this in turn causes the autoload search.

Feedback from contributors to vim would be welcome, in order to decide whether this is a bug or a feature.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.