coc.vim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. " Symbol renaming.
  61. nmap <leader>rn <Plug>(coc-rename)
  62. " Formatting selected code.
  63. xmap <leader>f <Plug>(coc-format-selected)
  64. nmap <leader>f <Plug>(coc-format-selected)
  65. augroup mygroup
  66. autocmd!
  67. " Setup formatexpr specified filetype(s).
  68. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  69. " Update signature help on jump placeholder.
  70. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  71. augroup end
  72. " Applying codeAction to the selected region.
  73. " Example: `<leader>aap` for current paragraph
  74. xmap <leader>a <Plug>(coc-codeaction-selected)
  75. nmap <leader>a <Plug>(coc-codeaction-selected)
  76. " Remap keys for applying codeAction to the current line.
  77. nmap <leader>ac <Plug>(coc-codeaction)
  78. " Apply AutoFix to problem on the current line.
  79. nmap <leader>qf <Plug>(coc-fix-current)
  80. " Introduce function text object
  81. " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
  82. xmap if <Plug>(coc-funcobj-i)
  83. xmap af <Plug>(coc-funcobj-a)
  84. omap if <Plug>(coc-funcobj-i)
  85. omap af <Plug>(coc-funcobj-a)
  86. " Use <TAB> for selections ranges.
  87. " NOTE: Requires 'textDocument/selectionRange' support from the language server.
  88. " coc-tsserver, coc-python are the examples of servers that support it.
  89. nmap <silent> <TAB> <Plug>(coc-range-select)
  90. xmap <silent> <TAB> <Plug>(coc-range-select)
  91. " Add `:Format` command to format current buffer.
  92. command! -nargs=0 Format :call CocAction('format')
  93. " Add `:Fold` command to fold current buffer.
  94. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  95. " Add `:OR` command for organize imports of the current buffer.
  96. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
  97. " Add (Neo)Vim's native statusline support.
  98. " NOTE: Please see `:h coc-status` for integrations with external plugins that
  99. " provide custom statusline: lightline.vim, vim-airline.
  100. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  101. " Mappings using CoCList:
  102. " Show all diagnostics.
  103. nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
  104. " Manage extensions.
  105. nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
  106. " Show commands.
  107. nnoremap <silent> <space>c :<C-u>CocList commands<cr>
  108. " Find symbol of current document.
  109. nnoremap <silent> <space>o :<C-u>CocList outline<cr>
  110. " Search workspace symbols.
  111. nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
  112. " Do default action for next item.
  113. nnoremap <silent> <space>j :<C-u>CocNext<CR>
  114. " Do default action for previous item.
  115. nnoremap <silent> <space>k :<C-u>CocPrev<CR>
  116. " Resume latest coc list.
  117. nnoremap <silent> <space>p :<C-u>CocListResume<CR>