coc.vim 5.1 KB

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