2 let g:coc_global_extensions = [
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>" :
22 inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
24 function! s:check_back_space() abort
25 let col = col('.') - 1
26 return !col || getline('.')[col - 1] =~# '\s'
29 " Use <c-space> to trigger completion.
30 inoremap <silent><expr> <c-space> coc#refresh()
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>"
38 " Use `[g` and `]g` to navigate diagnostics
39 nmap <silent> [g <Plug>(coc-diagnostic-prev)
40 nmap <silent> ]g <Plug>(coc-diagnostic-next)
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)
48 " Use K to show documentation in preview window
49 nnoremap <silent> K :call <SID>show_documentation()<CR>
51 function! s:show_documentation()
52 if (index(['vim','help'], &filetype) >= 0)
53 execute 'h '.expand('<cword>')
55 call CocAction('doHover')
59 " Highlight symbol under cursor on CursorHold
60 autocmd CursorHold * silent call CocActionAsync('highlight')
62 " Remap for rename current word
63 nmap <F2> <Plug>(coc-rename)
65 " Remap for format selected region
66 xmap <leader>f <Plug>(coc-format-selected)
67 nmap <leader>f <Plug>(coc-format-selected)
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')
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)
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)
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)
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)
96 " Use `:Format` to format current buffer
97 command! -nargs=0 Format :call CocAction('format')
99 " Use `:Fold` to fold current buffer
100 command! -nargs=? Fold :call CocAction('fold', <f-args>)
102 " use `:OR` for organize import of current buffer
103 command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
107 " Show all diagnostics
108 nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
110 nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
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>