Closed JohnAppleSeed- closed 7 years ago
I don't get an auto-popup until I type the second letter of a word
Please see :h g:mucomplete#trigger_auto_pattern
. You may try to put this in your vimrc
:
let g:mucomplete#trigger_auto_pattern = { 'default': '\%(\k\|\.\)$' }
or, if you want that pattern only for Go:
let g:mucomplete#trigger_auto_pattern = { 'go': '\%(\k\|\.\)$' }
The regular expression matches a keyword character (\k
) or a dot (\.
) just before the cursor.
I like that it inserts a parenthesis, but is there a way to make it insert a closing parenthesis and place your cursor in between them?
That behaviour is not controlled by µcomplete, but by the omni completion plugin you are using. To verify that, turn off autocompletion (:MUcompleteAutoOff
), type some characters and try to complete with <c-x><c-o>
.
K thanks I can probably switch to this from ycm then.
Now that trigger_auto_pattern has been removed how do I do this with the can_complete function?
I tried
let g:mucomplete#can_complete = { 'default': '\%(\k\|\.\)$' }
but I get the error:
Error detected while processing /home/zxcv/.vim/plugged/vim-mucomplete/autoload/mucomplete.vim:
line 137:
E712: Argument of extend() must be a List or Dictionary
And I read the docs but I don't understand how to do this.
Auto patterns now are completion-type specific. So, for example:
let g:mucomplete#can_complete = {
\ 'default': {
\ 'omni': { t -> strlen(&l:omnifunc) > 0 && t =~# '\%(\k\|\.\)$' }
\ }
\ }
Edit: fixed typo
Admittedly, although the new way is most flexible, for some users it may appear too cumbersome compared to the previous one. If that is the case for you, please open a new issue, so I will think of a better solution.
When I try your solution I get the error:
E121: Undefined variable: t
E15: Invalid expression: { 'default': { 'omni': t -> strlen(&l:omnifunc) > 0 && t =~# '\%(\k|.)$' } }
Does your Vim support lambdas? If :echo has('lambda')
returns 0
, you have to use standard functions, e.g.:
function CanOmnicomplete(t)
return strlen(&l:omnifunc) > 0 && a:t =~# '\%(\k\|\.\)$'
endf
let g:mucomplete#can_complete = {
\ 'default': {
\ 'omni': function('CanOmnicomplete')
\ }
\ }
This solution does work, although I do get 1
when I run :echo has('lambda')
.
This solution is fine for me but I could see how some people might see it as cumbersome. As long as it works I don't care how it's done.
Ah, there was a typo, sorry. Please copy and paste again the first version, it should work now.
yep works now.
@lifepillar I was able to get '.' to trigger completion via the let g:mucomplete#can_complete
setting you gave above. Is there any way to modify that to trigger on '.' but require 2 characters at minimum otherwise like previously?
@electric-ladyland Do you mean, like this:
let g:mucomplete#can_complete = {
\ 'default': {
\ 'omni': { t -> strlen(&l:omnifunc) > 0 && t =~# '\%(\k\k\|\.\)$' }
\ }
\ }
This would trigger omni-completion after a dot or after two keyword characters (\k\k
).
@lifepillar Exactly, thanks much.
For bug reports only, please provide the following details:
:help mucomplete-troubleshooting
.echo g:mucomplete#chains
:{'vim': ['file', 'cmd', 'keyn'], 'default': ['file', 'omni', 'keyn', 'dict']}
setl completeopt
:completeopt=menu,longest,menu,menuone,noinsert,noselect
.vimrc
, if any: