I’ve been using Neovim with CoC for a while with no problems. Yesterday I upgraded my OS from Ubuntu 21.04 to 22.04. Without any change to my vim config files, an error pops up. I’ll explain better with examples:
These are my config files (splitted in many files, fancy stuff): https://github.com/fr-mm/dot-files
Error comes from this file (CoC config file): https://github.com/fr-mm/dot-files/blob/bode/files/vim/plugins/coc.vim
In this file, I have this very common snippet used for trigger autocomplete:
inoremap <silent><expr> <TAB>
pumvisible() ? "<C-n>" :
<SID>check_back_space() ? "<TAB>" :
coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "<C-p>" : "<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# 's'
endfunction
Triggering auto-complete with tab works fine, but when I try to use TAB in insert it throws
E117: Unknown function: <SNR>119_check_back_space
What does it mean: check_back_space function is not been recognized, despite been declared right below.
What I tried so far:
- Declare function above use
- Declare in init.vim (first file read by vim)
- Declare another simpler function and use inside inoremap
- Remove <SID> from function call
I’m using NVIM v0.6.1 (LuaJIT 2.1.0-beta3)
2
Answers
I have same problem on my machine (Ubuntu 22.04, nvim v0.8.0-1210, coc.nvim).
I “solved” this problem by removing this stuff:
In my opinion, this is new bug in coc.nvim. My solution isn’t ultimate 🙂
There is new code in their GitHub repo for using tab to autocomplete: https://github.com/neoclide/coc.nvim
Replace these lines in your vimrc
with these lines (from the new version of CoC):
and if you want the same behaviour as before (pressing tab autocompletes the top option first, instead of the second option) then also enter the command
:CocConfig
to bring up your coc configuration file and add this entry to it