Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, this is very rough-and-ready, but it appears to work (at least in simple cases).</p> <p>First of all here is a function which performs a vimgrep on a given a file. This needs to be a separate function so it can be called silently later on.</p> <pre><code>function! File_Grep( leader, file ) try exe "vimgrep /" . a:leader . "/j " . a:file catch /.*/ echo "no matches" endtry endfunction </code></pre> <p>Now here is a custom-completion function which calls <code>File_Grep()</code> and returns a list of matching words. The key is the call to the <code>add()</code> function, which appends a match to the list if search term (<code>a:base</code>) appears ANYWHERE in the string. (See <code>help complete-functions</code> for the structure of this function.)</p> <pre><code>function! Fuzzy_Completion( findstart, base ) if a:findstart " find start of completion let line = getline('.') let start = col('.') - 1 while start &gt; 0 &amp;&amp; line[start - 1] =~ '\w' let start -= 1 endwhile return start else " search for a:base in current file let fname = expand("%") silent call File_Grep( a:base, fname ) let matches = [] for this in getqflist() call add(matches, matchstr(this.text,"\\w*" . a:base . "\\w*")) endfor call setqflist([]) return matches endif endfunction </code></pre> <p>Then you just need to tell Vim to use the complete function:</p> <pre><code>set completefunc=Fuzzy_Completion </code></pre> <p>and you can use <code>&lt;c-x&gt;&lt;x-u&gt;</code> to invoke the completion. Of course, the function could be used to search any file, rather than the current file (just modify the <code>let fname</code> line).</p> <p>Even if this isn't the answer you were looking for, I hope it aids you in your quest!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload