lifepillar / vim-mucomplete

Chained completion that works the way you want!
MIT License
912 stars 18 forks source link

pumvisible() but no selection = double <cr> #141

Closed dylnmc closed 5 years ago

dylnmc commented 5 years ago

Hi! I have been manually using <c-p> <c-x><c-p> <c-x><c-l> and all that good stuff manually for quite some time now. I decided to give this plugin a whirl again. It's super great! I think that since the last time I used it, there has been a fix for c-p deleting characters and also there are some more options that make using mucomplete easier. I am so used to using the default maps that I do not want smart enter, or <tab> completion. I just want a list of what I can complete with <c-x><c-o> and the like.

The one issue that I notice that I hope you can help me with is that if I have typed something, and I have not selected anything yet but the pop-up completion menu is visible (pumvisibl() is true), then I must type <cr><cr> in order to insert a newline. Please see my configuration of your plugin below, but I have tested it manually after disabling enable_auto_at_startup with the same completeopt, and it seems to work fine without your plugin.

set noinfercase
set completeopt=menu,menuone,noselect
let g:mucomplete#no_mappings = 1
let g:mucomplete#no_popup_mappings = 1
let g:mucomplete#enable_auto_at_startup = 1
let g:mucomplete#always_use_completeopt = 1

I am wondering how <cr> is effectively acting like <c-e> (reject selection and close pum) if nothing has been selected (so ... it doesn't really reject a selection ... just close pum).


Thanks for the awesome plugin. It's very fast, and it works very well.

lifepillar commented 5 years ago

Does the tip MUcomplete does not always insert a new line when I press Enter… in :help mucomplete-tips solve your issue?

lifepillar commented 5 years ago

I am wondering how <cr> is effectively acting like <c-e>

How <cr> should behave is described in :help popupmenu-keys. IMO, Vim does not always behave as described (see, for instance, https://github.com/vim/vim/issues/1653).

lifepillar commented 5 years ago

it seems to work fine without your plugin.

Can you provide a reproducible example?

dylnmc commented 5 years ago

hey hey. Indeed, I use the following:

inoremap <expr> <cr> maps#crExpand()

and

function! maps#crExpand()
    let l:col = col('.')
    let l:pre = pumvisible() ? "\<c-y>" : ''
    if (l:col !=# col('$'))
        return l:pre."\<cr>"
    endif
    let l:mps = map(split(&matchpairs, ','), "split(v:val, ':')")
    let l:i = -1
    let l:bn = bufnr('.')
    for l:mp in split(get(g:, 'crIgnores', ''), ',')
        let l:i = index(l:mps, split(l:mp, ':'))
        if (l:i + 1)
            call remove(l:mps, l:i)
        endif
    endfor
    for l:mp in split(getbufvar(l:bn, 'crIgnores', ''), ',')
        let l:i = index(l:mps, split(l:mp, ':'))
        if (l:i + 1)
            call remove(l:mps, l:i)
        endif
    endfor
    let l:mps +=
    \   map(split(get(g:, 'crMatchpairs', ''), ','), "split(v:val, ':')") +
    \   map(split(getbufvar(l:bn, 'crMatchpairs', ''), ','), "split(v:val, ':')")
    let l:i = index(map(copy(l:mps), 'v:val[0]'), getline('.')[l:col - 2])
    if (l:i + 1)
        return l:pre."\<cr>".l:mps[l:i][1]."\<esc>O"
    else
        return l:pre."\<cr>"
    endif
endfunction

I have now added the l:pre which is "\<c-y>" if pumvisible(), and it works. Thanks.

I thought I had read the entire help, and I did thouroughly read it, but I must have missed this part. Thanks, as always, for your timely and helpful replies and for your assistance.

~dylnmc


p.s. I wrote this function before I knew about filter and some other goody functions, so don't make fun of me /hides\ ;P