coc.vim 5.6 KB

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