coc.vim 5.6 KB

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