vimlc/lc.vim

31 lines
745 B
VimL

vim9script
def GetMatch(base: string, line: string): list<any>
var s = base
while stridx(line, s) == -1
s = strpart(s, 1)
if strlen(s) == 0
return [0, ""]
endif
endwhile
const idx = stridx(line, s)
const slen = strlen(s)
return [slen, base .. strpart(line, idx + slen)]
enddef
def LineSuffixCompl(findstart: bool, base: string): any
if findstart
return 0
endif
return getbufinfo()
->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
->flattennew()
->sort()
->uniq()
->map( (_, v) => GetMatch(base, v) )
->sort( (x, y) => y[0] - x[0] )
->map( (_, v) => v[1] )
enddef
setlocal completefunc=LineSuffixCompl