Coc.nvim: Using <cr> for confirm completion (from docs) is breaking coc.nvim

Created on 29 Mar 2019  路  5Comments  路  Source: neoclide/coc.nvim

coc.nvim is freezing when trying to hit enter in insert mode with recommended mappings in place. This could just be me misunderstanding what's happening, but I don't believe this was happening before I updated coc.nvim recently because I haven't changed any mappings.

Result from CocInfo

## versions

vim version: NVIM v0.4.0-dev
node version: v8.9.0
coc.nvim version: 0.0.63
term: iTerm.app
platform: darwin

## Error messages

## Output channel: watchman
[Info  - 10:25:26] watchman watching project: /Users/ctay20/code/cougar
[Info  - 10:25:26] subscribing "**/.eslintr{c.js,c.yaml,c.yml,c,c.json}" in /Users/ctay20/code/cougar
[Info  - 10:25:26] subscribing "**/.eslintignore" in /Users/ctay20/code/cougar
[Info  - 10:25:26] subscribing "**/package.json" in /Users/ctay20/code/cougar
[Info  - 10:25:26] subscribing "**/{.prettierrc,.prettierrc.json,.prettierrc.yaml,.prettierrc.yml,.prettierrc.js,package.json,prettier.config.js}" in /Users/ctay20/code/cougar
[Info  - 10:25:36] subscribing "**/[tj]sconfig.json" in /Users/ctay20/code/cougar
[Info  - 10:25:36] subscribing "**/package.json" in /Users/ctay20/code/cougar
[Info  - 10:25:36] subscribing "**/*.ts" in /Users/ctay20/code/cougar
[Info  - 10:25:36] subscribing "**/*.js" in /Users/ctay20/code/cougar

## Output channel: prettier

## Output channel: tsserver
[Info  - 10:25:36] Forking TSServer
PATH: /Users/ctay20/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.cargo/bin:/opt/X11/bin:/Users/ctay20/.cargo/bin:/Users/ctay20/.cargo/bin 
[Info  - 10:25:36] Started TSServer
{
  "path": "/Users/ctay20/code/cougar/node_modules/typescript/lib",
  "_api": {
    "versionString": "3.3.3333",
    "version": "3.3.3333"
  }
}

## Output channel: eslint
[Info  - 10:25:36] ESLint server running in node v8.9.0
[Info  - 10:25:37] ESLint library loaded from: /Users/ctay20/code/cougar/node_modules/eslint/lib/api.js

Describe the bug
When using the recommended mapping from the docs for using <cr> to confirm completion, coc.nvim freezes.

To Reproduce

  1. Add inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" OR inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>" to your init.vim
  2. open a file with coc.nvim envabled.
  3. Enter insert mode and try to press enter
  4. vim will freeze, and only when you hit <C-c> to kill the command does it dump the mapping command

```vim
set nocompatible
set runtimepath^=/path/to/coc.nvim
filetype plugin indent on
syntax on
set hidden

" Use for confirm completion, <C-g>u means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap pumvisible() ? "\" : "\u\"

" OR this mapping also breaks it in same manor
" Make select the first completion item and confirm completion when no item have selected
inoremap pumvisible() ? coc#_select_confirm() : "\u\"
```

Screenshots
mapping_bug

Can't reproduce

Most helpful comment

Yup yup, for me it was due to t-pope/endwise

All 5 comments

It could be caused by your other plugin changed the keymap of <CR>.
Checkout :verbose imap <CR>

Yup yup, for me it was due to t-pope/endwise

Yup yup, for me it was due to t-pope/endwise

curious: what did you do to resolve it?

Added to .vimrc

" Endwise
" disable mapping to not break coc.nvim (I don't even use them anyways)
let g:endwise_no_mappings = 1

I had the same problem, however, it was due to recursion, not re-mapping.
Config pulled directly from Readme.md uses imap

Solution
Replace: imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"

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

  • note that I'm using VIM not NVIM
  ## versions

  vim version: VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 11 2019 19:08:24)
  node version: v10.19.0
  coc.nvim version: 0.0.78-bcb2fe977c
  term: dumb
  platform: linux

  ## Output channel: tsserver

  [Info  - 4:51:57 AM] Forking TSServer
  PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
  [Info  - 4:51:57 AM] Started TSServer
  {
    "path": "/root/.config/coc/extensions/node_modules/coc-tsserver/node_modules/typescript/lib",
    "_pathLabel": "",
    "_api": {
      "versionString": "3.8.3",
      "version": "3.8.3"
    }
  }


Was this page helpful?
0 / 5 - 0 ratings