vimlc/lc.vim

31 lines
745 B
VimL
Raw Normal View History

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