supertab
supertab copied to clipboard
a few questions
Hi
Love the plugin. A couple of questions:
- The default completion method is
. What is it exactly? <CTRL-X><CTRL-P>
? - I configured the plugin like so:
let g:SuperTabSetDefaultCompletionType="context"
let g:SuperTabContextDefaultCompletionType="<c-x><c-k>"
Hoping that if there are no completions, it will complete from the dictionary, but it doesn't :( When I do:
call SuperTabSetDefaultCompletionType('<c-x><c-k>')
it does work for dictionary completions, but then I'm not sure if for example perl completion is "fully operational".
What am I missing?
The default completion method is
<c-p>
. What is it exactly?<CTRL-X><CTRL-P>
?
<c-p>
searches in all the places specified in your complete
setting (:h i_CTRL-P
), while <c-x><c-p>
is limited to matches in the current file (:h i_CTRL-X_CTRL-P
).
I configured the plugin like so: ... Hoping that if there are no completions, it will complete from the dictionary, but it doesn't
What the context
completion type does is determine, based on the text before the cursor, whether or not to kick off omni completion if it looks like you are attempting to complete a method call, etc. If it doesn't look like that, then it will kick off the dictionary completion in your case. Supertab is simply sending keybindings to vim to tell it which completion method to use. It does not examine the results of either completion method to determine if anything was found. For that supertab has completion chaining (:h supertab-completionchaining
) which can look at the results from omni or user completion, and if nothing was returned, fallback to some other method.
If you have a concrete example of what you are trying to complete, what you expect to happen, and what actually happens, then I can probably clear up any confusion about what is going on.
Yeah, I’ve been using completion for some things but when I started reading the docs in depth, I realized that I didn’t know anything :)
So, what I want to do is for vim/your excellent plugin to try to finish programming language kewords, etc. Sort of the thing that happens when I press “CTRL-N” in the INSERT mode. If that fails I would like it to try to complete the word as just an English word. Say I’m in a Perl program and I’m writing a comment. And I forgot how to spell “necessary” — superb would try to complete based on the variables/keywords in the file and if not, look inside the English dictionary.
Actually, that mode of completion would work for everything (even email messages — I think?).
I read about chaining yesterday and couldn’t make it to work the way I described above.
I put this in my .vimrc:
autocmd FileType *
\ if &omnifunc != '' |
\ call SuperTabChain(&omnifunc, "<c-p>") |
\ call SuperTabSetDefaultCompletionType("<c-x><c-k>") |
\ endif
This results in just dictionary completion (vars/keywords in the file are ignored)
I don't get what <c-p>
in the documentation means. Nor what <c-x><c-u>
is supposed to do in the context of supertab.
You've got the right idea, unfortunately supertab can only chain together omni completion (or user completion) with any other completion as a fallback. This is because only omni and user completion have functions that can be called to examine their results. Keyword, dictionary, spelling, and all the other completion methods don't have a way for a plugin to invoke them and examine the results (short of rewriting their functionality in vimscript), so supertab can only send those keybindings to vim, without knowing if anything was suggested or not.
I put this in my .vimrc: ... This results in just dictionary completion (vars/keywords in the file are ignored)
When you set the default completion to <c-x><c-k>
, you're negating the previous chaining call. Since you've supplied &omnifunc
as the thing you want to chain, you need to either set the default completion type to context
or <c-x><c-u>
(supertab injects its own completefunc
, so with using one of those, that function will never be called).
I don't get what
<c-p>
in the documentation means
Which part do you find confusing? I can probably clarify anything that isn't clear.
Nor what
<c-x><c-u>
is supposed to do in the context of supertab.
That depends on what <c-x><c-u>
is being used for. If you are referring to completion chaining, then it's used to invoke the completefunc
that supertab injects to support the chaining.
Keyword, dictionary, spelling, and all the other completion methods don't have a way for a plugin to invoke them and examine the results (short of rewriting their functionality in vimscript), so supertab can only send those keybindings to vim, without knowing if anything was suggested or not.
So, doesn't putting <c-x><c-k>
do the right thing. I.e., I don't want the result of that to be examined. Just want vim to try to complete from the dictionary as the last resort. And the word I'm trying to complete as a test is hous
.
Which part do you find confusing? I can probably clarify anything that isn't clear.
Well, the docs say the default completion mode is <c-p>
, but what does that mode do? There are several mapping in vim that react to <c-p>
. So which part of the documentation describe the <c-p>
you're referring to in the documentation?
And why wouldn't I want the 'context' mode as the default anyway? Isn't it the best of all worlds?
So, what should the chaining configuration be so that the first shot is at "context", then the dictionary completion? Do you mind pasting what you think it would look like?
I think I need to understand how vim completion works in vim in general. Then ask my questions. So let me do my homework first.
So, doesn't putting
<c-x><c-k>
do the right thing. I.e., I don't want the result of that to be examined. Just want vim to try to complete from the dictionary as the last resort.
Supertab's completion chaining only supports chaining &omni
, or &completefunc
, with just one other completion (due to the limitations of vim stated earlier). In the example you posted, that one other completion is set to <c-p>
(keyword completion). If you want dictionary completion the be the second, and last, completion method tried, then you would need to update your example to use: call SuperTabChain(&omnifunc, "<c-x><c-k>")
Well, the docs say the default completion mode is
<c-p>
, but what does that mode do? So which part of the documentation describe theyou're referring to in the documentation?
Supertab sends that keybinding (Ctrl-P) to vim, so it tells vim to run keyword completion. Run the following in vim to see the help documentation for that insert completion method: :h i_CTRL-P
And why wouldn't I want the 'context' mode as the default anyway? Isn't it the best of all worlds?
That's a personal preference and could depend on what you're doing. In this case, yes, I think it is what you want, especially since it is one of the only two methods that will utilize completion chaining.
So, what should the chaining configuration be so that the first shot is at "context", then the dictionary completion? Do you mind pasting what you think it would look like?
It's exactly what you have, but with the default set to context:
autocmd FileType *
\ if &omnifunc != '' |
\ call SuperTabChain(&omnifunc, "<c-p>") |
\ call SuperTabSetDefaultCompletionType("context") |
\ endif
As the supertab completion chaining docs state (:h supertab-completionchaining
):
this feature must be used with g:SuperTabDefaultCompletionType set to either "context" or "<c-x><c-u>".
After this discussion, I think I'm going to update the SuperTabChain
function to take a third argument of some sort, forcing users to choose between context
and <c-x><c-u>
since that may make it more clear that those are the only two options if you want completion chaining.