3

Is there a way to mix user defined completion and keyword completion in one menu triggered by <c-n>?

Keyword completion is probably the most useful method, but syntax completion triggered by <c-x><c-u> after:

setlocal omnifunc=syntaxcomplete#Complete

really adds efficiency as well. There must be a way to send them both to the same popup menu using complete_add() or something similar - I'm just not exactly sure how to do it.

1 Answer 1

5

Not directly; the built-in completions feed directly into the popup menu; there's no extension point there. You have to re-implement the built-in completion, and then can add the results from another completion function, e.g. 'omnifunc'. My CompleteHelper plugin makes this quite simple:

function! BuiltInComplete( findstart, base ) if a:findstart " Locate the start of the keyword. let l:startCol = searchpos('\k*\%#', 'bn', line('.'))[1] if l:startCol == 0 let l:startCol = col('.') endif return l:startCol - 1 " Return byte index, not column. else " Find matches starting with a:base. let l:matches = [] call CompleteHelper#FindMatches( l:matches, '\V\<' . escape(a:base, '\') . '\k\+', {'complete': &complete}) " Now add the matches from omni completion. let l:matches += call(&omnifunc, [0, a:base]) return l:matches endif endfunction 

General critique

As you can see by the list of completions implemented with the help of my plugin, I favor the opposite: many distinct completions, each triggered by separate keys. At least for me, the overhead of choosing from a long list of completion candidates is much more than the little cognitive processing in choosing the right completion.

1
  • Your plugins are great but the repos on GitHub aren't easily discoverable if you start from the Vim plugins site. Commented Jul 27, 2022 at 17:06