90 lines
3.0 KiB
VimL
90 lines
3.0 KiB
VimL
" Must have extensions!
|
|
let g:coc_global_extensions = ['coc-json', 'coc-clangd', 'coc-snippets', 'coc-elixir']
|
|
let g:coc_config_home = $HOME.'/.config/coc'
|
|
|
|
" -----------------------------------------------------------------------------
|
|
" - coc-snippets config -
|
|
" -----------------------------------------------------------------------------
|
|
" Use <C-l> for trigger snippet expand.
|
|
imap <C-l> <Plug>(coc-snippets-expand)
|
|
|
|
" Use <C-j> for select text for visual placeholder of snippet.
|
|
vmap <C-j> <Plug>(coc-snippets-select)
|
|
|
|
" Use <C-j> for both expand and jump (make expand higher priority.)
|
|
imap <C-j> <Plug>(coc-snippets-expand-jump)
|
|
|
|
" Use <leader>x for convert visual selected code to snippet
|
|
xmap <leader>x <Plug>(coc-convert-snippet)
|
|
|
|
" Use tab for expansion
|
|
inoremap <silent><expr> <TAB>
|
|
\ pumvisible() ? coc#_select_confirm() :
|
|
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
|
|
\ <SID>check_back_space() ? "\<TAB>" :
|
|
\ coc#refresh()
|
|
|
|
function! s:check_back_space() abort
|
|
let col = col('.') - 1
|
|
return !col || getline('.')[col - 1] =~# '\s'
|
|
endfunction
|
|
|
|
let g:coc_snippet_next = '<tab>'
|
|
|
|
" -----------------------------------------------------------------------------
|
|
" - Coc general LSP config -
|
|
" -----------------------------------------------------------------------------
|
|
|
|
" GoTo code navigation.
|
|
nmap <silent> gd <Plug>(coc-definition)
|
|
nmap <silent> gy <Plug>(coc-type-definition)
|
|
nmap <silent> gi <Plug>(coc-implementation)
|
|
nmap <silent> gr <Plug>(coc-references)
|
|
|
|
" Use K to show documentation in preview window.
|
|
nnoremap <silent> K :call <SID>show_documentation()<CR>
|
|
|
|
function! s:show_documentation()
|
|
if (index(['vim','help'], &filetype) >= 0)
|
|
execute 'h '.expand('<cword>')
|
|
elseif (coc#rpc#ready())
|
|
call CocActionAsync('doHover')
|
|
else
|
|
execute '!' . &keywordprg . " " . expand('<cword>')
|
|
endif
|
|
endfunction
|
|
|
|
" Symbol renaming.
|
|
nmap <leader>rn <Plug>(coc-rename)
|
|
|
|
" Formatting selected code.
|
|
xmap <leader>f <Plug>(coc-format-selected)
|
|
nmap <leader>f <Plug>(coc-format-selected)
|
|
|
|
" Applying codeAction to the selected region.
|
|
" Example: `<leader>aap` for current paragraph
|
|
xmap <leader>a <Plug>(coc-codeaction-selected)
|
|
nmap <leader>a <Plug>(coc-codeaction-selected)
|
|
"
|
|
" Remap keys for applying codeAction to the current buffer.
|
|
nmap <leader>ac <Plug>(coc-codeaction)
|
|
nmap <M-CR> <Plug>(coc-codeaction)
|
|
" Apply AutoFix to problem on the current line.
|
|
nmap <leader>qf <Plug>(coc-fix-current)
|
|
|
|
" Map function and class text objects
|
|
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
|
|
xmap if <Plug>(coc-funcobj-i)
|
|
omap if <Plug>(coc-funcobj-i)
|
|
xmap af <Plug>(coc-funcobj-a)
|
|
omap af <Plug>(coc-funcobj-a)
|
|
xmap ic <Plug>(coc-classobj-i)
|
|
omap ic <Plug>(coc-classobj-i)
|
|
xmap ac <Plug>(coc-classobj-a)
|
|
omap ac <Plug>(coc-classobj-a)
|
|
|
|
" Use CTRL-S for selections ranges.
|
|
" Requires 'textDocument/selectionRange' support of language server.
|
|
nmap <silent> <C-s> <Plug>(coc-range-select)
|
|
xmap <silent> <C-s> <Plug>(coc-range-select)
|