Tuesday, October 4, 2016

Keyword completion as a fallback for omnicompletion

Hello Vim experts,

for certain filetypes I'd find it convenient to fallback to keyword completion
automatically when omnifunc fails, either because omnifunc is not defined or,
more interestingly, because no omnifunc pattern matches. So far, I have come
up with the following code:


fun! MyComplete()
if strlen(&omnifunc) > 0
let c = call(&omnifunc, [1,''])
if c >= 0
let matches = call(&omnifunc, [0, strpart(getline('.'), c,
col('.') - c)])
if !empty(matches)
return "\<c-x>\<c-o>"
end
end
end
return "\<c-x>\<c-p>"
endf

imap <expr><silent> <tab> pumvisible() ? "\<c-n>" : MyComplete()

This does what I want, but it bothers me that I have to use <c-x><c-o> when
I have already retrieved all the matches. I could use completefunc, but then
I would not know how to return the list that <c-x><c-p> produces (is there
a function for that?).

Do you have any hint on how I could solve this more efficiently?

Thanks,
Life


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: