coc.vim 5.7 KB

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