~yerinalexey/dotfiles

ref: b75055cfb2820b41efd348481e49a2f487355931 dotfiles/nvim/coc.vim -rw-r--r-- 2.4 KiB
b75055cf — Alexey Yerin bottom: fix indents 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
" CoC configuration

" Smaller update time
set updatetime=400

" Don't pass messages to default completion menu
set shortmess+=c

" Set of extensions
let g:coc_global_extensions = ['coc-marketplace', 'coc-tsserver', 'coc-prettier', 'coc-emmet', 'coc-json', 'coc-eslint', 'coc-snippets']

" Use tab to trigger completion
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

" Show completions on Ctrl+Space (just like VSCode)
inoremap <silent><expr> <C-space> coc#refresh()

" Use Enter to confirm completion, `<C-g>u` means break undo chain at current
" position
if exists('*complete_info')
  inoremap <silent><expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
else
  inoremap <silent><expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
endif

" Use K to show documentation in preview window.
nnoremap <silent> K <Cmd>call <SID>show_documentation()<CR>

function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  else
    call CocAction('doHover')
  endif
endfunction

augroup coc
  au!

  " Highlight the symbol and its references when hovering over it
  autocmd CursorHold * silent call CocActionAsync('highlight')

  " Show help when jumping between placeholders
  autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup END

" Renaming!
nmap <silent> <leader>r <Plug>(coc-rename)

" Restart language server
nmap <silent> <leader>l <Cmd>CocRestart<cr>

" QuickFix and CodeActions
nmap <silent> <leader>f <Plug>(coc-fix-current)
nmap <silent> <leader>c <Plug>(coc-codeaction)
xmap <silent> <leader>c <Plug>(coc-codeaction-selected)

" Various jumps
nmap <silent> <leader>gr <Plug>(coc-references)
nmap <silent> <leader>gy <Plug>(coc-type-definition)
nmap <silent> <leader>gd <Plug>(coc-defenition)
nmap <silent> <leader>gi <Plug>(coc-implementation)

" Show diagnostics and jump between errors/warnings
nmap <silent> <leader>gD <Cmd>CocDiagnostics<cr>
nmap <silent> g[ <Plug>(coc-diagnostic-prev)
nmap <silent> g] <Plug>(coc-diagnostic-next)

" Run command
nmap <silent> <A-e> <Cmd>CocCommand<cr>

" Format file using prettier
command! Prettier :CocCommand prettier.formatFile