Skip to content

Instantly share code, notes, and snippets.

@frandsoh
Created August 25, 2020 21:11
Show Gist options
  • Save frandsoh/96a754a4afa8d6ef8e53b4125156f85d to your computer and use it in GitHub Desktop.
Save frandsoh/96a754a4afa8d6ef8e53b4125156f85d to your computer and use it in GitHub Desktop.

Revisions

  1. frandsoh created this gist Aug 25, 2020.
    61 changes: 61 additions & 0 deletions nvim-coc.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    # coc completion keymap

    ```vim
    " Function to check if character before cursor is a " " (empty) or not
    function! s:check_back_space() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1] =~# '\s'
    endfunction
    let g:coc_snippet_next = '<C-j>'
    let g:coc_snippet_prev = '<C-k>'
    """" <TAB>
    inoremap <silent><S-Space> <C-o>l
    inoremap <silent><expr> <TAB>
    \ pumvisible() ? "\<C-n>" :
    \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
    \ <SID>check_back_space() ? "\<TAB>" :
    \ coc#refresh()
    """" <S-TAB>
    inoremap <expr><S-TAB>
    \ pumvisible() ? "\<C-p>" : "\<C-O>b"
    """" <C-SPACE>
    inoremap <silent><expr> <c-space>
    \ pumvisible() ? coc#_select_confirm() :
    \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
    \ <SID>check_back_space() ? "\<SPACE>" :
    \ coc#refresh()
    """" <SPACE>
    if exists('*complete_info')
    inoremap <silent><expr> <space>
    \ complete_info()["selected"] == "-1" ? "\<SPACE>" :
    \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
    \ "\<SPACE>"
    " inoremap <silent><expr> <BS>
    " \ complete_info()["selected"] != "-1" ? "\<C-E>" :
    " \ "\<C-g>u\<BS>"
    endif
    """" snippet select
    vmap <C-j> <Plug>(coc-snippets-select)
    """" <CR>
    " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
    " position. Coc only does snippet and additional edit on confirm.
    " <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
    if exists('*complete_info')
    "if something from the pum is selected confirm with Enter key
    inoremap <expr><cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
    else
    inoremap <expr><cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
    endif
    ```