:h complete-functions
詳細については、を参照してください:h 'completefunc'
。
または、以下のコードに飛び込みます。
" Scan current buffer for everithing in { }.
fun! GetRegexes()
let rx = '{.\+}'
let res = []
for line in getline(1, '$')
if line =~ rx
call add(res, matchstr(line, rx))
endif
endfor
return res
endfun
fun! MyComplete(findstart, base)
if a:findstart
" locate the start of the completion
let line = getline('.')
let start = col('.') - 1
while start > 0 && line[start] !~ '{'
let start -= 1
endwhile
return start
else
let res = []
for m in GetRegexes()
if m =~ '^' . a:base
call add(res, m)
endif
endfor
return res
endif
endfun
set completefunc=MyComplete
finish
[0-9] {printf("yada yada \n");}
[0-9] {printf("yada \n");}
このファイルを名前を付けて保存し、コマンドcompl.vim
でソースすると、入力を開始して- , -を押して、2 つの要素を持つ補完メニューを呼び出す:so %
ことができます。{pri
CtrlXCtrlU
{printf("yada yada \n");}
{printf("yada \n");}
ニーズに合わせて調整できると思います。
2 つの関数を .vimrc に保存し、MyComlete
そのような補完が必要なバッファーに対して completefunc を設定できます。