I think the only way to achieve what you want is to execute a custom full function. See help complete-functions for (very useful!) Documentation. Here is my attempt at a solution:
First you need a separate function for the silent grep file for the line (if you just call the naked vimgrep function, you will get an ugly error if there are no matches).
function! SilentFileGrep( leader, file ) try exe 'vimgrep /^\s*' . a:leader . '.*/j ' . a:file catch /.*/ echo "no matches" endtry endfunction
Now, here is your completion function. Please note that the path to the file you want to find is hardcoded here, but you can change it to use the variable if you want. We call SilentFileGrep() , which uploads the results to the quickfix list. Then we extract the results from qflist (trimming the leading space) and clear the qflist before returning the results.
function! LineCompleteFromFile(findstart,base) if a:findstart " column to begin searching from (first non-whitespace column): return match(getline("."),'\S') else " grep the file and build list of results: let path = <path_to_file> call SilentFileGrep( a:base, path ) let matches = [] for thismatch in getqflist() " trim leading whitespace call add(matches, matchstr(thismatch.text,'\S.*')) endfor call setqflist([]) return matches endif endfunction
To use this function, you need to set the completefunc option to point to it:
set completefunc=LineCompleteFromFile
You can then use <CX><CU> to call completion, which you can easily map to <CX><CL> .
This seems to work very well for me, but it is not exhaustively tested.
source share