-
Notifications
You must be signed in to change notification settings - Fork 127
/
coc.vim
109 lines (85 loc) · 3.69 KB
/
coc.vim
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
if exists('g:vscode')
finish
endif
if exists('g:plug_installing_plugins')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'rodrigore/coc-tailwind-intellisense', {'do': 'npm install'}
finish
endif
" tsserver currently locked due to not picking up local tsdk after 1.11.12
let g:coc_global_extensions = [
\'coc-snippets', 'coc-json', 'coc-tsserver',
\'coc-css', 'coc-eslint', 'coc-react-refactor',
\'coc-vimlsp', 'coc-html', 'coc-db', 'coc-yaml', 'coc-prettier',
\'coc-prisma']
" Manual restarts are often needed when large project or tsconfig changes
" happen
nnoremap <leader>crr :CocRestart<cr>
" Sometimes restart is needed to allow spelling to be added to local folder.
nnoremap <leader>crs :CocSpellRestart<cr>
" Show documentation in preview window
nnoremap <silent>gD :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
inoremap <expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<CR>"
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
" Navigate diagnostic
nmap <silent> gn <Plug>(coc-diagnostic-next)
nmap <silent> gN <Plug>(coc-diagnostic-prev)
" Do codeAction of selected region, ex: `<leader>fp` for current paragraph
xmap <leader>b <Plug>(coc-codeaction-selected)
nmap <leader>b <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
nmap <leader>bb <Plug>(coc-codeaction)
" TODO switch for this when 0.7.9 becomes stable
" nmap <leader>bb <Plug>(coc-codeaction-line)
" Autofix problem of current line
nmap <leader>bc <Plug>(coc-fix-current)
" Map keys for go-tos
nmap <silent> gd <Plug>(coc-definition)
" Format current buffer
nmap <silent> gF :call CocAction('format')<CR>
function! s:organize_imports()
call CocActionAsync()('runCommand', 'tsserver.organizeImports')
endfunction
nmap <silent> <leader>if :call <SID>organize_imports()<CR>
" Map function and class text objects
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
" Use CTRL-S for selections ranges.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Manual trigger completion.
inoremap <silent><expr> <S-enter> coc#refresh()
" Scroll floating window, taken from Coc help docs
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" ------------
" coc-snippets
" ------------
imap <C-j> <Plug>(coc-snippets-expand)
" Use <C-j> for jump to next placeholder, it's default of coc.nvim
let g:coc_snippet_next = '<c-j>'
" Use <C-k> for jump to previous placeholder, it's default of coc.nvim
let g:coc_snippet_prev = '<c-k>'
" Use <C-j> for both expand and jump (make expand higher priority.)
imap <C-j> <Plug>(coc-snippets-expand-jump)
" A shorthand command to quickly restart the coc spell checker so it can pick
" up the presence of the workspace.
command! -nargs=0 CocSpellRestart :call CocAction('reloadExtension', 'coc-spell-checker')