I was trying to change my coc.nvim autocomplete key, and found this question in Stack Overflow, but the guy who answer this question doesn't explain really good how to customize it as you want, so I will explain it to help the NeoVim users that are racking the brain for this as I was.
If you want to bind Tab for autocompletion, paste this in your .vimrc or init.vim
inoremap <silent><expr> <tab> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<TAB>"
inoremap <silent><expr> <cr> "\<c-g>u\<CR>"
So, you have to make 2 insert mode remaps, in this case I will remap my completion to Tab key.
inoremap <silent><expr> <tab> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<TAB>"
Obs: If you want to bind other key to autocomplete:
inoremap <silent><expr> [the key that you want to autocomplete] pumvisible() ? coc#_select_confirm() : "\<C-g>u\<TAB>"
Now, CoC will autocomplete with Tab key too, but Enter is also autocompleting, I want to bind Enter by just be Enter, not an autocompletion key.
In VimScript Enter is represented by <cr>
inoremap <silent><expr> <cr> "\<c-g>u\<cr>"
Obs:
inoremap <silent><expr> [this is the current autocompletion key] "\<c-g>u\[this is the bind that I am giving to the key]"