girishji / vimcomplete

Async autocompletion for Vim.
MIT License
121 stars 5 forks source link

Allow custom <CR> mapping. #41

Closed adriantrunzo closed 7 months ago

adriantrunzo commented 7 months ago

Issue

I use a custom <CR> mapping for autopairs like so:

inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>\<Plug>AutoPairsReturn"

I can't figure out how to get that mapping to work with vimcomplete.

Actual Behavior

My <CR> mapping is either unmapped or overwritten, depending on the value of noNewlineInCompletion. I think the issue lies here: https://github.com/girishji/vimcomplete/blob/a4c8c4c80af5f481cec4e53a03cd789547188e1c/autoload/vimcomplete/completor.vim#L327

No matter what, vimcomplete changes the behavior of <CR>.

Expected Behavior

The plugin only maps <CR> if I haven't mapped it in my vimrc or provides an option to not modify <CR>.

Discussion

I tried a workaround by adding an autocommand on the BufNewFile and BufReadPost events like used in VimCompEnable:

autocmd Config BufNewFile,BufReadPost *
  \ inoremap <expr> <buffer> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>\<Plug>AutoPairsReturn"

That autocmd didn't work though. I guess it's running before the ones set up in VimCompEnable.

girishji commented 7 months ago

Can you try now? <cr> is mapped only when no prior mapping exist.

adriantrunzo commented 7 months ago

Thanks, this fix works for me.