From ec4c119181dbee4af5646ccbfd5611015b38b273 Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Fri, 25 Aug 2023 12:32:34 -0400 Subject: [PATCH] initial version to replace line completion --- lc.vim | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/lc.vim b/lc.vim index 6461fb1..62f9eac 100644 --- a/lc.vim +++ b/lc.vim @@ -1,16 +1,20 @@ vim9script -def GetMatch(base: string, line: string): list +def GetMatch(base: string, line: string, add_base: bool): list var s = base while stridx(line, s) == -1 s = strpart(s, 1) if strlen(s) == 0 - return [0, ""] + return [0, ""] # vim ignores these endif endwhile const idx = stridx(line, s) const slen = strlen(s) - return [slen, base .. strpart(line, idx + slen)] + if add_base + return [slen, base .. strpart(line, idx + slen)] + else + return [slen, strpart(line, idx + slen)] + endif enddef def LineSuffixCompl(findstart: bool, base: string): any @@ -22,9 +26,26 @@ def LineSuffixCompl(findstart: bool, base: string): any ->flattennew() ->sort() ->uniq() - ->map( (_, v) => GetMatch(base, v) ) + ->map( (_, v) => GetMatch(base, v, v:true) ) ->sort( (x, y) => y[0] - x[0] ) ->map( (_, v) => v[1] ) enddef -setlocal completefunc=LineSuffixCompl +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 =DoLSCmpl() + +set completefunc=LineSuffixCompl