52 lines
1.2 KiB
VimL
52 lines
1.2 KiB
VimL
vim9script
|
|
|
|
class Item
|
|
const len: number
|
|
const val: string
|
|
endclass
|
|
|
|
def GetMatch(base: string, line: string, add_base: bool): Item
|
|
var s = base
|
|
while stridx(line, s) == -1
|
|
s = strpart(s, 1)
|
|
if strlen(s) == 0
|
|
return Item.new(0, "")
|
|
endif
|
|
endwhile
|
|
const idx = stridx(line, s)
|
|
const slen = strlen(s)
|
|
if add_base
|
|
return Item.new(slen, base .. strpart(line, idx + slen))
|
|
else
|
|
return Item.new(slen, strpart(line, idx + slen))
|
|
endif
|
|
enddef
|
|
|
|
def GetMatches(base: string, add_base: bool): list<string>
|
|
return getbufinfo()
|
|
->filter( (_, bf) => bf.listed )
|
|
->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
|
|
->flattennew()
|
|
->sort()
|
|
->uniq()
|
|
->map( (_, v) => GetMatch(base, v, add_base) )
|
|
->filter( (_, i) => i.len > 3 )
|
|
->sort( (x, y) => y.len - x.len )
|
|
->map( (_, i) => i.val )
|
|
enddef
|
|
|
|
def LineSuffixCompl(findstart: bool, base: string): any
|
|
if findstart
|
|
return 0
|
|
endif
|
|
return GetMatches(base, true)
|
|
enddef
|
|
|
|
def DoLSCmpl()
|
|
GetMatches(getline('.'), false)->complete(col('.'))
|
|
enddef
|
|
|
|
inoremap <C-X><C-L> <C-R>=<SID>DoLSCmpl()<CR>
|
|
|
|
set completefunc=LineSuffixCompl
|