coc.vim 4.6 KB

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