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 に答える