Humanity

Edit the world by your favorite way

Vimのautoloadのバグ

Lingrのメンバーには既知だろうけど、一応まとめておく。

autoload関数を「exists('*mylib#func')」のように確認するのは、
スクリプトのトップレベルで確認した方がいい。

でないとautoload/mylib.vimとその中に「mylib#func()」が存在していて
「exists('*mylib#func')」が1になるべきところでも0になる。


「トップレベル」というのは、関数の中からとかじゃなく、

function! s:func_using_mylib_func()
    if exists('*mylib#func')
        call mylib#func('hoge')
    endif
endfunction

このように関数の外、グローバルなスコープ(?)で確認した方がいいということ。

let s:mylib_func_exists = exists('*mylib#func')

function! s:func_using_mylib_func()
    if s:mylib_func_exists
        call mylib#func('hoge')
    endif
endfunction

現在のところ、autoload関数、グローバル関数の中で「exists('*mylib#func')」すると0になる挙動が確認されている。