coc.vim 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. " Use tab for trigger completion with characters ahead and navigate.
  17. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
  18. " other plugin before putting this into your config.
  19. inoremap <silent><expr> <TAB>
  20. \ pumvisible() ? "\<C-n>" :
  21. \ <SID>check_back_space() ? "\<TAB>" :
  22. \ coc#refresh()
  23. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  24. function! s:check_back_space() abort
  25. let col = col('.') - 1
  26. return !col || getline('.')[col - 1] =~# '\s'
  27. endfunction
  28. " Use <c-space> to trigger completion.
  29. inoremap <silent><expr> <c-space> coc#refresh()
  30. " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
  31. " position. Coc only does snippet and additional edit on confirm.
  32. if exists('*complete_info')
  33. inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
  34. else
  35. imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
  36. endif
  37. " Use `[g` and `]g` to navigate diagnostics
  38. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  39. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  40. " GoTo code navigation.
  41. nmap <silent> gd <Plug>(coc-definition)
  42. nmap <silent> gy <Plug>(coc-type-definition)
  43. nmap <silent> gi <Plug>(coc-implementation)
  44. nmap <silent> gr <Plug>(coc-references)
  45. " Use K to show documentation in preview window.
  46. nnoremap <silent> K :call <SID>show_documentation()<CR>
  47. function! s:show_documentation()
  48. if (index(['vim','help'], &filetype) >= 0)
  49. execute 'h '.expand('<cword>')
  50. else
  51. call CocAction('doHover')
  52. endif
  53. endfunction
  54. " Highlight the symbol and its references when holding the cursor.
  55. autocmd CursorHold * silent call CocActionAsync('highlight')
  56. " Symbol renaming.
  57. nmap <leader>rn <Plug>(coc-rename)
  58. " Formatting selected code.
  59. xmap <leader>f <Plug>(coc-format-selected)
  60. nmap <leader>f <Plug>(coc-format-selected)
  61. augroup mygroup
  62. autocmd!
  63. " Setup formatexpr specified filetype(s).
  64. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  65. " Update signature help on jump placeholder.
  66. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  67. augroup end
  68. " Applying codeAction to the selected region.
  69. " Example: `<leader>aap` for current paragraph
  70. xmap <leader>a <Plug>(coc-codeaction-selected)
  71. nmap <leader>a <Plug>(coc-codeaction-selected)
  72. " Remap keys for applying codeAction to the current line.
  73. nmap <leader>ac <Plug>(coc-codeaction)
  74. " Apply AutoFix to problem on the current line.
  75. nmap <leader>qf <Plug>(coc-fix-current)
  76. " Introduce function text object
  77. " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
  78. xmap if <Plug>(coc-funcobj-i)
  79. xmap af <Plug>(coc-funcobj-a)
  80. omap if <Plug>(coc-funcobj-i)
  81. omap af <Plug>(coc-funcobj-a)
  82. " Use <TAB> for selections ranges.
  83. " NOTE: Requires 'textDocument/selectionRange' support from the language server.
  84. " coc-tsserver, coc-python are the examples of servers that support it.
  85. " nmap <silent> <TAB> <Plug>(coc-range-select)
  86. " xmap <silent> <TAB> <Plug>(coc-range-select)
  87. " Add `:Format` command to format current buffer.
  88. command! -nargs=0 Format :call CocAction('format')
  89. " Add `:Fold` command to fold current buffer.
  90. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  91. " Add `:OR` command for organize imports of the current buffer.
  92. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
  93. " Add (Neo)Vim's native statusline support.
  94. " NOTE: Please see `:h coc-status` for integrations with external plugins that
  95. " provide custom statusline: lightline.vim, vim-airline.
  96. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  97. " Mappings using CoCList:
  98. " Show all diagnostics.
  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>