如何重新MapCoC VIM自动完成键?

v1uwarro  于 2022-11-11  发布在  其他
关注(0)|答案(2)|浏览(131)

I am trying to remap the autocomplete key from the "Enter" key to "TAB" because I keep autocompleting when I intend to go to the next line. The code below is the default option for coc, and I think this is where I should be able to remap the key.

" make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                              \: "\<c-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

I thought that changing the in the beginning to would work. However, although it does allow me to autocomplete using TAB, it creates weird auto indentations in some cases. For example:

//normal behavior
someFunction(){
    //cursor here appropriately indented
}

//behavior after I made the changes mentioned above
someFunction(){
//cursor here}

I assume I just fundamentally don't understand something about coc or remapping keys in VIM.

Why can't I simply change that to ? How can I go about remapping the autocomplete key from "Enter" to "TAB"?

djmepvbi

djmepvbi1#

我不太了解vimscript,但我通过反复试验成功地让一些东西工作起来。

默认设置:

inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

在选项卡上自动完成:

"This expression seems to be responsible for coc formatting on enter
inoremap <silent><expr> <cr> "\C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
"I this just says autocomplete with the first option if pop up menu is open.
"If it is not open, just do a regular tab.
inoremap <silent><expr> <TAB> pumvisible() ? coc#select_confirm() : "\<C-g>u\<TAB>"
nwsw7zdq

nwsw7zdq2#

替换示例coc config中的以下行

inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

与此:

inoremap <silent><expr> <TAB> coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<TAB>"

这是基于@christofuy的回答,但在此行更改后更新。

相关问题