fun! RstLabelCompletion(findstart, base) if a:findstart " locate the start of the word let line = getline('.') let start = col('.') - 1 while start > 0 && line[start - 1] =~ '\a' let start -= 1 endwhile return start else let line = line('.') let col = col('.') call cursor(1, 1) let res = [] while search('\.\. _' . a:base, "Wc") > 0 let m = substitute(getline('.'), '.*\.\. _\(.*\):', '\1', '') call add(res, m) endwhile call cursor(line, col) return res endif endfun setlocal completefunc=RstLabelCompletion