Have a look into :h complete-functions
and :h 'completefunc'
for details.
Or dive into the code below:
" 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");}
If you save this file as compl.vim
and source it with :so %
command then you'll be able to start typing {pri
and press Ctrl-X,Ctrl-U to invoke completion menu with 2 elements:
{printf("yada yada \n");}
{printf("yada \n");}
I believe you can adjust it to your needs.
You can save 2 functions into your .vimrc and set completefunc to MyComlete
for buffer where you need that kind of completion.