Vim line completion with external file -


can line completion ctrl+x ctrl+l used show line completions specific external file instead of "only" current buffer? dictionaries, lines.

update:

to test did following:

  • created file tt.txt test lines
  • placed file in d:\t1\ (i'm on windows)
  • included file :set path+=d:\\t1\\tt.txt
  • :set complete ? returns complete =.,w,b,u,t,i
  • :set path ? returns path=.,,,d:\t1\tt.txt
  • checkpath returns: included files found
  • typing line should completed matching content tt.txt ctrl+x ctrl+l returns pattern not found

what missing?

i think way achieve want custom complete-function. see help complete-functions (very useful!) documentation. here's attempt @ solution:

first need separate function silently grep file string (if call naked vimgrep function ugly error if there no matches).

function! silentfilegrep( leader, file )     try         exe 'vimgrep /^\s*' . a:leader . '.*/j ' . a:file     catch /.*/         echo "no matches"     endtry endfunction 

now, here's completion function. note path file want search hard-coded in here, change use variable if wish. call silentfilegrep(), dumps results in quickfix list. extract results qflist (trimming leading whitespace) , clear qflist before returning results.

function! linecompletefromfile(findstart,base)     if a:findstart         " column begin searching (first non-whitespace column):         return match(getline("."),'\s')     else         " grep file , build list of results:         let path = <path_to_file>         call silentfilegrep( a:base, path )         let matches = []         thismatch in getqflist()             " trim leading whitespace             call add(matches, matchstr(thismatch.text,'\s.*'))         endfor         call setqflist([])         return matches     endif endfunction 

to use function, need set completefunc option point @ it:

set completefunc=linecompletefromfile 

then can use <c-x><c-u> invoke completion, map <c-x><c-l>.

this seems work pretty me, not exhaustively tested.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -