mirror of
https://github.com/tiyn/wiki.git
synced 2025-04-08 01:27:46 +02:00
83 lines
2.1 KiB
Markdown
83 lines
2.1 KiB
Markdown
# Coc in Vim
|
|
|
|
[Conquer of completion](https://github.com/neoclide/coc.nvim) enables full
|
|
language server protocol support for neovim.
|
|
It is written specifically for neovim.
|
|
|
|
The coc config file is located in `.config/nvim/coc-settings.json`.
|
|
|
|
## Installation
|
|
|
|
- Install `nodejs`
|
|
- Install [vim-plug](vim-plug.md)
|
|
- Add coc.vim to your init.vim
|
|
- Add `Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'}`
|
|
to your Plug-Section
|
|
|
|
## Base config
|
|
|
|
Add the base configuration to your vim config file.
|
|
|
|
```vimscript
|
|
" neoclide/coc.nvim
|
|
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
|
|
|
|
if has('nvim')
|
|
inoremap <silent><expr> <c-space> coc#refresh()
|
|
else
|
|
inoremap <silent><expr> <c-@> coc#refresh()
|
|
endif
|
|
|
|
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
|
|
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
|
|
|
|
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)
|
|
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
|
|
|
|
autocmd CursorHold * silent call CocActionAsync('highlight')
|
|
|
|
nmap <F5> <Plug>(coc-rename)
|
|
|
|
xmap <leader>f <Plug>(coc-format-selected)
|
|
nmap <leader>f <Plug>(coc-format-selected)
|
|
|
|
augroup mygroup
|
|
autocmd!
|
|
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
|
|
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
|
|
augroup end
|
|
```
|
|
|
|
## Extensions
|
|
|
|
Extensions can be added to the vim config aswell.
|
|
A basic example for adding a few extensions is:
|
|
|
|
```vimscript
|
|
let g:coc_global_extensions = [
|
|
\ ]
|
|
```
|
|
|