Files
vimlc/lc.vim

63 lines
1.5 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): list<string>
return getbufinfo()
->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
->flattennew()
->sort()
->uniq()
->map( (_, v) => GetMatch(base, v, true) )
->filter( (_, i) => i.len != 0 )
->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)
enddef
def DoLSCmpl(): string
const base = getline('.')
const lines = getbufinfo()
->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
->flattennew()
->sort()
->uniq()
->map( (_, v) => GetMatch(base, v, v:false) )
->filter( (_, v) => GetMatch(base, v, v:false) )
->sort( (x, y) => y[0] - x[0] )
->map( (_, v) => v[1] )
complete(col('.'), lines)
return ''
enddef
# inoremap <C-X><C-L> <C-R>=<SID>DoLSCmpl()<CR>
set completefunc=LineSuffixCompl