Vim ã® autoload ã§å®ç¾©ããã¦ãã foo#init() ãèªåçã«å¼ã¶ã
å
ãã¿
ã¨ãããäºã§ autocmd SourcePre ã§èªåçã« foo#init() ãå¼ã¶ãããªã¹ã¯ãªãããæ¸ãã¦ã¿ã¾ããã
[ã½ã¼ã¹]
" s:call_init("autoload/hoge/foo.vim") => call hoge#foo#init() function! s:call_init(file) let funcname = substitute(matchstr(substitute(fnamemodify(a:file, ":r"), '\\', '/', 'g'), '.*\/autoload\/\zs.*\ze'), '/', '#', 'g') . "#init()" try execute "call" funcname catch " echo v:exception . v:errmsg endtry endfunction autocmd SourcePre */autoload/* call s:call_init(expand("<afile>"))
autoload é¢æ°ã¯æåã«å¼ã°ããã¨ãã« :source ããã®ã§ããã«ããã¯ã㦠init() ãå¼ã¶ããã«ãã¦ãã¾ãã
ã£ã¦ããautoload ã :source ããå ´åã§ã autocmd SourcePre ã¯ã¡ããã¨å¼ã°ããã®ããç¥ããªãã£ãã