coc.vim 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. let g:coc_global_extensions = [
  2. \ 'coc-snippets',
  3. \ 'coc-actions',
  4. \ 'coc-sh',
  5. \ 'coc-java-debug',
  6. \ 'coc-java',
  7. \ 'coc-lists',
  8. \ 'coc-emmet',
  9. \ 'coc-tasks',
  10. \ 'coc-pairs',
  11. \ 'coc-tsserver',
  12. \ 'coc-floaterm',
  13. \ 'coc-html',
  14. \ 'coc-css',
  15. \ 'coc-emoji',
  16. \ 'coc-cssmodules',
  17. \ 'coc-yaml',
  18. \ 'coc-python',
  19. \ 'coc-pyright',
  20. \ 'coc-explorer',
  21. \ 'coc-svg',
  22. \ 'coc-prettier',
  23. \ 'coc-vimlsp',
  24. \ 'coc-xml',
  25. \ 'coc-yank',
  26. \ 'coc-json',
  27. \ 'coc-marketplace',
  28. \ 'coc-tabnine',
  29. \ ]
  30. " Use tab for trigger completion with characters ahead and navigate.
  31. inoremap <silent><expr> <TAB>
  32. \ pumvisible() ? "\<C-n>" :
  33. \ <SID>check_back_space() ? "\<TAB>" :
  34. \ coc#refresh()
  35. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  36. function! s:check_back_space() abort
  37. let col = col('.') - 1
  38. return !col || getline('.')[col - 1] =~# '\s'
  39. endfunction
  40. " Use <c-space> to trigger completion.
  41. inoremap <silent><expr> <c-space> coc#refresh()
  42. " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
  43. " position. Coc only does snippet and additional edit on confirm.
  44. if exists('*complete_info')
  45. inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
  46. else
  47. imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
  48. endif
  49. " GoTo code navigation.
  50. nmap <silent> gd <Plug>(coc-definition)
  51. nmap <silent> gy <Plug>(coc-type-definition)
  52. nmap <silent> gi <Plug>(coc-implementation)
  53. nmap <silent> gr <Plug>(coc-references)
  54. " Use K to show documentation in preview window.
  55. nnoremap <silent> K :call <SID>show_documentation()<CR>
  56. function! s:show_documentation()
  57. if (index(['vim','help'], &filetype) >= 0)
  58. execute 'h '.expand('<cword>')
  59. else
  60. call CocAction('doHover')
  61. endif
  62. endfunction
  63. " Highlight the symbol and its references when holding the cursor.
  64. autocmd CursorHold * silent call CocActionAsync('highlight')
  65. " Symbol renaming.
  66. " nmap <leader>rn <Plug>(coc-rename)
  67. augroup mygroup
  68. autocmd!
  69. " Setup formatexpr specified filetype(s).
  70. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  71. " Update signature help on jump placeholder.
  72. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  73. augroup end
  74. " Applying codeAction to the selected region.
  75. " Example: `<leader>aap` for current paragraph
  76. " xmap <leader>a <Plug>(coc-codeaction-selected)
  77. " nmap <leader>a <Plug>(coc-codeaction-selected)
  78. " Remap keys for applying codeAction to the current line.
  79. " nmap <leader>ac <Plug>(coc-codeaction)
  80. " Apply AutoFix to problem on the current line.
  81. " nmap <leader>qf <Plug>(coc-fix-current)
  82. " Introduce function text object
  83. " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
  84. xmap if <Plug>(coc-funcobj-i)
  85. xmap af <Plug>(coc-funcobj-a)
  86. omap if <Plug>(coc-funcobj-i)
  87. omap af <Plug>(coc-funcobj-a)
  88. " Use <TAB> for selections ranges.
  89. " NOTE: Requires 'textDocument/selectionRange' support from the language server.
  90. " coc-tsserver, coc-python are the examples of servers that support it.
  91. " nmap <silent> <TAB> <Plug>(coc-range-select)
  92. " xmap <silent> <TAB> <Plug>(coc-range-select)
  93. " Add `:Format` command to format current buffer.
  94. command! -nargs=0 Format :call CocAction('format')
  95. " Add `:Fold` command to fold current buffer.
  96. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  97. " Add `:OR` command for organize imports of the current buffer.
  98. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
  99. " Add (Neo)Vim's native statusline support.
  100. " NOTE: Please see `:h coc-status` for integrations with external plugins that
  101. " provide custom statusline: lightline.vim, vim-airline.
  102. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  103. " Mappings using CoCList:
  104. " Show all diagnostics.
  105. " TODO add these to which key
  106. " nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
  107. " " Manage extensions.
  108. " nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
  109. " " Show commands.
  110. " nnoremap <silent> <space>c :<C-u>CocList commands<cr>
  111. " " Find symbol of current document.
  112. " nnoremap <silent> <space>o :<C-u>CocList outline<cr>
  113. " " Search workspace symbols.
  114. " nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
  115. " " Do default action for next item.
  116. " nnoremap <silent> <space>j :<C-u>CocNext<CR>
  117. " " Do default action for previous item.
  118. " nnoremap <silent> <space>k :<C-u>CocPrev<CR>
  119. " " Resume latest coc list.
  120. " nnoremap <silent> <space>p :<C-u>CocListResume<CR>
  121. " Explorer
  122. let g:coc_explorer_global_presets = {
  123. \ 'floating': {
  124. \ 'position': 'floating',
  125. \ },
  126. \ 'floatingLeftside': {
  127. \ 'position': 'floating',
  128. \ 'floating-position': 'left-center',
  129. \ 'floating-width': 30,
  130. \ },
  131. \ 'floatingRightside': {
  132. \ 'position': 'floating',
  133. \ 'floating-position': 'right-center',
  134. \ 'floating-width': 30,
  135. \ },
  136. \ 'simplify': {
  137. \ 'file.child.template': '[selection | clip | 1] [indent][icon | 1] [filename omitCenter 1]'
  138. \ }
  139. \ }
  140. "nmap <silent> <space>e :CocCommand explorer<CR>
  141. " nnoremap <silent> <leader>e :CocCommand explorer<CR>
  142. " nmap <space>f :CocCommand explorer --preset floatingRightside<CR>
  143. autocmd BufEnter * if (winnr("$") == 1 && &filetype == 'coc-explorer') | q | endif
  144. " Snippets
  145. " Use <C-l> for trigger snippet expand.
  146. imap <C-l> <Plug>(coc-snippets-expand)
  147. " Use <C-j> for select text for visual placeholder of snippet.
  148. vmap <C-j> <Plug>(coc-snippets-select)
  149. " Use <C-j> for jump to next placeholder, it's default of coc.nvim
  150. let g:coc_snippet_next = '<c-j>'
  151. " Use <C-k> for jump to previous placeholder, it's default of coc.nvim
  152. let g:coc_snippet_prev = '<c-k>'
  153. " Use <C-j> for both expand and jump (make expand higher priority.)
  154. imap <C-j> <Plug>(coc-snippets-expand-jump)