【问题标题】:How to remap CoC VIM autocomplete key?如何重新映射 CoC VIM 自动完成键?
【发布时间】:2021-05-03 22:29:28
【问题描述】:

我正在尝试将自动完成键从“Enter”键重新映射到“TAB”,因为当我打算转到下一行时,我一直在自动完成。下面的代码是 coc 的默认选项,我认为这是我应该能够重新映射密钥的地方。

" 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>"

我认为将开头的 更改为 会起作用。然而,虽然它允许我使用 TAB 自动完成,但在某些情况下它会创建奇怪的自动缩进。例如:

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


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

我假设我根本不了解 coc 或在 VIM 中重新映射键。

为什么我不能简单地将 更改为 ?如何将自动完成键从“Enter”重新映射到“TAB”?

【问题讨论】:

标签: vim coc.nvim


【解决方案1】:

我不太了解 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>"

【讨论】:

  • 最后一行应该是coc#_select_confirm吗?
  • @sguan 我发布的答案一直对我有用,让我在 TAB 上而不是在 ENTER 上自动完成。我相信coc#_select_confirm 是负责执行自动完成的函数。所以我认为最后一行在高层次上说的是:如果自动完成弹出菜单打开,则执行自动完成,否则执行常规 TAB。
  • 这是错误的。应该是_coc#_select_confirm 就像@sguan 说的那样
猜你喜欢
  • 2021-07-25
  • 1970-01-01
  • 2011-06-09
  • 1970-01-01
  • 1970-01-01
  • 2012-11-28
  • 1970-01-01
  • 2014-03-05
  • 1970-01-01
相关资源
最近更新 更多