vimlc/lc.vim

52 lines
1.3 KiB
VimL
Raw Normal View History

2023-05-27 00:29:20 -04:00
vim9script
def GetMatch(base: string, line: string, add_base: bool): list<any>
2023-05-29 13:22:17 -04:00
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, ""] # vim ignores these
2023-05-27 00:29:20 -04:00
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)
if add_base
return [slen, base .. strpart(line, idx + slen)]
else
return [slen, strpart(line, idx + slen)]
endif
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()
->map( (_, v) => GetMatch(base, v, v:true) )
2023-05-27 00:29:20 -04:00
->sort( (x, y) => y[0] - x[0] )
->map( (_, v) => v[1] )
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) )
->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