coc.vim 5.6 KB

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