massive update, probably broken
[dotfiles/.git] / .config / nvim / plugin / coc.vim
1 "Coc:
2 let g:coc_global_extensions = [
3   \ 'coc-snippets',
4   \ 'coc-pairs',
5   \ 'coc-tsserver',
6   \ 'coc-eslint',
7   \ 'coc-prettier',
8   \ 'coc-json',
9   \ 'coc-clangd',
10   \ 'coc-css',
11   \ 'coc-html',
12   \ 'coc-markdownlint',
13   \ 'coc-pyright',
14   \ ]
15
16 " Use tab for trigger completion with characters ahead and navigate.
17 " Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
18 inoremap <silent><expr> <TAB>
19       \ pumvisible() ? "\<C-n>" :
20       \ <SID>check_back_space() ? "\<TAB>" :
21       \ coc#refresh()
22 inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
23
24 function! s:check_back_space() abort
25   let col = col('.') - 1
26   return !col || getline('.')[col - 1]  =~# '\s'
27 endfunction
28
29 " Use <c-space> to trigger completion.
30 inoremap <silent><expr> <c-space> coc#refresh()
31
32 " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
33 " Coc only does snippet and additional edit on confirm.
34 inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
35 " Or use `complete_info` if your vim support it, like:
36 " inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
37
38 " Use `[g` and `]g` to navigate diagnostics
39 nmap <silent> [g <Plug>(coc-diagnostic-prev)
40 nmap <silent> ]g <Plug>(coc-diagnostic-next)
41
42 " Remap keys for gotos
43 nmap <silent> gd <Plug>(coc-definition)
44 nmap <silent> gy <Plug>(coc-type-definition)
45 nmap <silent> gi <Plug>(coc-implementation)
46 nmap <silent> gr <Plug>(coc-references)
47
48 " Use K to show documentation in preview window
49 nnoremap <silent> K :call <SID>show_documentation()<CR>
50
51 function! s:show_documentation()
52   if (index(['vim','help'], &filetype) >= 0)
53     execute 'h '.expand('<cword>')
54   else
55     call CocAction('doHover')
56   endif
57 endfunction
58
59 " Highlight symbol under cursor on CursorHold
60 autocmd CursorHold * silent call CocActionAsync('highlight')
61
62 " Remap for rename current word
63 nmap <F2> <Plug>(coc-rename)
64
65 " Remap for format selected region
66 xmap <leader>f  <Plug>(coc-format-selected)
67 nmap <leader>f  <Plug>(coc-format-selected)
68
69 augroup mygroup
70   autocmd!
71   " Setup formatexpr specified filetype(s).
72   autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
73   " Update signature help on jump placeholder
74   autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
75 augroup end
76
77 " Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
78 xmap <leader>a  <Plug>(coc-codeaction-selected)
79 nmap <leader>a  <Plug>(coc-codeaction-selected)
80
81 " Remap for do codeAction of current line
82 nmap <leader>ac  <Plug>(coc-codeaction)
83 " Fix autofix problem of current line
84 nmap <leader>qf  <Plug>(coc-fix-current)
85
86 " Create mappings for function text object, requires document symbols feature of languageserver.
87 xmap if <Plug>(coc-funcobj-i)
88 xmap af <Plug>(coc-funcobj-a)
89 omap if <Plug>(coc-funcobj-i)
90 omap af <Plug>(coc-funcobj-a)
91
92 " Use <C-d> for select selections ranges, needs server support, like: coc-tsserver, coc-python
93 nmap <silent> <C-d> <Plug>(coc-range-select)
94 xmap <silent> <C-d> <Plug>(coc-range-select)
95
96 " Use `:Format` to format current buffer
97 command! -nargs=0 Format :call CocAction('format')
98
99 " Use `:Fold` to fold current buffer
100 command! -nargs=? Fold :call     CocAction('fold', <f-args>)
101
102 " use `:OR` for organize import of current buffer
103 command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')
104
105
106 " Using CocList
107 " Show all diagnostics
108 nnoremap <silent> <space>a  :<C-u>CocList diagnostics<cr>
109 " Manage extensions
110 nnoremap <silent> <space>e  :<C-u>CocList extensions<cr>
111 " Show commands
112 nnoremap <silent> <space>c  :<C-u>CocList commands<cr>
113 " Find symbol of current document
114 nnoremap <silent> <space>o  :<C-u>CocList outline<cr>
115 " Search workspace symbols
116 nnoremap <silent> <space>s  :<C-u>CocList -I symbols<cr>
117 " Do default action for next item.
118 nnoremap <silent> <space>j  :<C-u>CocNext<CR>
119 " Do default action for previous item.
120 nnoremap <silent> <space>k  :<C-u>CocPrev<CR>
121 " Resume latest coc list
122 nnoremap <silent> <space>p  :<C-u>CocListResume<CR>