coc.vim 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. " TextEdit might fail if hidden is not set.
  2. set hidden
  3. " Some servers have issues with backup files, see #649.
  4. set nobackup
  5. set nowritebackup
  6. " Give more space for displaying messages.
  7. set cmdheight=2
  8. " Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
  9. " delays and poor user experience.
  10. set updatetime=300
  11. " Don't pass messages to |ins-completion-menu|.
  12. set shortmess+=c
  13. " Always show the signcolumn, otherwise it would shift the text each time
  14. " diagnostics appear/become resolved.
  15. set signcolumn=yes
  16. "better nav for omnicomplete
  17. inoremap <expr> <c-j> ("\<C-n>")
  18. inoremap <expr> <c-k> ("\<C-p>")
  19. " Use tab for trigger completion with characters ahead and navigate.
  20. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
  21. " other plugin before putting this into your config.
  22. "inoremap <silent><expr> <TAB>
  23. "\ pumvisible() ? "\<C-n>" :
  24. "\ <SID>check_back_space() ? "\<TAB>" :
  25. "\ coc#refresh()
  26. "inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  27. function! s:check_back_space() abort
  28. let col = col('.') - 1
  29. return !col || getline('.')[col - 1] =~# '\s'
  30. endfunction
  31. " Use <c-space> to trigger completion.
  32. inoremap <silent><expr> <c-space> coc#refresh()
  33. " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
  34. " position. Coc only does snippet and additional edit on confirm.
  35. if has('patch8.1.1068')
  36. " Use `complete_info` if your (Neo)Vim version supports it.
  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. " Use `[g` and `]g` to navigate diagnostics
  42. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  43. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  44. " GoTo code navigation.
  45. nmap <silent> gd <Plug>(coc-definition)
  46. nmap <silent> gy <Plug>(coc-type-definition)
  47. nmap <silent> gi <Plug>(coc-implementation)
  48. nmap <silent> gr <Plug>(coc-references)
  49. " Use K to show documentation in preview window.
  50. nnoremap <silent> K :call <SID>show_documentation()<CR>
  51. function! s:show_documentation()
  52. if (index(['vim','help'], &filetype) >= 0)
  53. execute 'h '.expand('<cword>')
  54. else
  55. call CocAction('doHover')
  56. endif
  57. endfunction
  58. " Highlight the symbol and its references when holding the cursor.
  59. autocmd CursorHold * silent call CocActionAsync('highlight')
  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. " Add `:Format` command to format current buffer.
  68. command! -nargs=0 Format :call CocAction('format')
  69. " Add `:Fold` command to fold current buffer.
  70. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  71. " Add `:OR` command for organize imports of the current buffer.
  72. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
  73. " Add (Neo)Vim's native statusline support.
  74. " NOTE: Please see `:h coc-status` for integrations with external plugins that
  75. " provide custom statusline: lightline.vim, vim-airline.
  76. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  77. " Mappings using CoCList:
  78. " Show all diagnostics.
  79. nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
  80. " Manage extensions.
  81. nnoremap <silent> <space>x :<C-u>CocList extensions<cr>
  82. " Show commands.
  83. nnoremap <silent> <space>c :<C-u>CocList commands<cr>
  84. " Find symbol of current document.
  85. nnoremap <silent> <space>o :<C-u>CocList outline<cr>
  86. " Search workspace symbols.
  87. nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
  88. " Do default action for next item.
  89. nnoremap <silent> <space>j :<C-u>CocNext<CR>
  90. " Do default action for previous item.
  91. nnoremap <silent> <space>k :<C-u>CocPrev<CR>
  92. " Resume latest coc list.
  93. nnoremap <silent> <space>p :<C-u>CocListResume<CR>
  94. nmap <silent> <C-_> <Plug>(pydocstring)