coc.vim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. " Add `:Format` command to format current buffer.
  60. command! -nargs=0 Format :call CocAction('format')
  61. " Add `:Fold` command to fold current buffer.
  62. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  63. " Add `:OR` command for organize imports of the current buffer.
  64. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
  65. " Add (Neo)Vim's native statusline support.
  66. " NOTE: Please see `:h coc-status` for integrations with external plugins that
  67. " provide custom statusline: lightline.vim, vim-airline.
  68. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  69. " Mappings using CoCList:
  70. " Show all diagnostics.
  71. " TODO add these to which key
  72. " nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
  73. " " Manage extensions.
  74. " nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
  75. " " Show commands.
  76. " nnoremap <silent> <space>c :<C-u>CocList commands<cr>
  77. " " Find symbol of current document.
  78. " nnoremap <silent> <space>o :<C-u>CocList outline<cr>
  79. " " Search workspace symbols.
  80. " nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
  81. " " Do default action for next item.
  82. " nnoremap <silent> <space>j :<C-u>CocNext<CR>
  83. " " Do default action for previous item.
  84. " nnoremap <silent> <space>k :<C-u>CocPrev<CR>
  85. " " Resume latest coc list.
  86. " nnoremap <silent> <space>p :<C-u>CocListResume<CR>
  87. " Explorer
  88. let g:coc_explorer_global_presets = {
  89. \ 'floating': {
  90. \ 'position': 'floating',
  91. \ },
  92. \ 'floatingLeftside': {
  93. \ 'position': 'floating',
  94. \ 'floating-position': 'left-center',
  95. \ 'floating-width': 30,
  96. \ },
  97. \ 'floatingRightside': {
  98. \ 'position': 'floating',
  99. \ 'floating-position': 'right-center',
  100. \ 'floating-width': 30,
  101. \ },
  102. \ 'simplify': {
  103. \ 'file.child.template': '[selection | clip | 1] [indent][icon | 1] [filename omitCenter 1]'
  104. \ }
  105. \ }
  106. "nmap <silent> <space>e :CocCommand explorer<CR>
  107. " nnoremap <silent> <leader>e :CocCommand explorer<CR>
  108. " nmap <space>f :CocCommand explorer --preset floatingRightside<CR>
  109. autocmd BufEnter * if (winnr("$") == 1 && &filetype == 'coc-explorer') | q | endif
  110. " Snippets
  111. " Use <C-l> for trigger snippet expand.
  112. imap <C-l> <Plug>(coc-snippets-expand)
  113. " Use <C-j> for select text for visual placeholder of snippet.
  114. vmap <C-j> <Plug>(coc-snippets-select)
  115. " Use <C-j> for jump to next placeholder, it's default of coc.nvim
  116. let g:coc_snippet_next = '<c-j>'
  117. " Use <C-k> for jump to previous placeholder, it's default of coc.nvim
  118. let g:coc_snippet_prev = '<c-k>'
  119. " Use <C-j> for both expand and jump (make expand higher priority.)
  120. imap <C-j> <Plug>(coc-snippets-expand-jump)