coc.vim 5.7 KB

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