coc.vim 5.6 KB

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