Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
5.2 KiB

  1. " Use tab for trigger completion with characters ahead and navigate.
  2. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
  3. " other plugin before putting this into your config.
  4. inoremap <silent><expr> <TAB>
  5. \ pumvisible() ? "\<C-n>" :
  6. \ <SID>check_back_space() ? "\<TAB>" :
  7. \ coc#refresh()
  8. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  9. function! s:check_back_space() abort
  10. let col = col('.') - 1
  11. return !col || getline('.')[col - 1] =~# '\s'
  12. endfunction
  13. " Use <c-space> to trigger completion.
  14. if has('nvim')
  15. inoremap <silent><expr> <c-space> coc#refresh()
  16. else
  17. inoremap <silent><expr> <c-@> coc#refresh()
  18. endif
  19. " Make <CR> auto-select the first completion item and notify coc.nvim to
  20. " format on enter, <cr> could be remapped by other vim plugin
  21. inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  22. " Use `[g` and `]g` to navigate diagnostics
  23. " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
  24. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  25. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  26. " GoTo code navigation.
  27. nmap <silent> gd <Plug>(coc-definition)
  28. nmap <silent> gy <Plug>(coc-type-definition)
  29. nmap <silent> gi <Plug>(coc-implementation)
  30. nmap <silent> gr <Plug>(coc-references)
  31. " Use K to show documentation in preview window.
  32. nnoremap <silent> K :call <SID>show_documentation()<CR>
  33. function! s:show_documentation()
  34. if (index(['vim','help'], &filetype) >= 0)
  35. execute 'h '.expand('<cword>')
  36. elseif (coc#rpc#ready())
  37. call CocActionAsync('doHover')
  38. else
  39. execute '!' . &keywordprg . " " . expand('<cword>')
  40. endif
  41. endfunction
  42. " Highlight the symbol and its references when holding the cursor.
  43. autocmd CursorHold * silent call CocActionAsync('highlight')
  44. " Symbol renaming.
  45. nmap <leader>rn <Plug>(coc-rename)
  46. " Formatting selected code.
  47. xmap <leader>f <Plug>(coc-format-selected)
  48. nmap <leader>f <Plug>(coc-format-selected)
  49. augroup mygroup
  50. autocmd!
  51. " Setup formatexpr specified filetype(s).
  52. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  53. " Update signature help on jump placeholder.
  54. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  55. augroup end
  56. " Applying codeAction to the selected region.
  57. " Example: `<leader>aap` for current paragraph
  58. xmap <leader>a <Plug>(coc-codeaction-selected)
  59. nmap <leader>a <Plug>(coc-codeaction-selected)
  60. " Remap keys for applying codeAction to the current buffer.
  61. nmap <leader>ac <Plug>(coc-codeaction)
  62. " Apply AutoFix to problem on the current line.
  63. nmap <leader>qf <Plug>(coc-fix-current)
  64. " Map function and class text objects
  65. " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
  66. xmap if <Plug>(coc-funcobj-i)
  67. omap if <Plug>(coc-funcobj-i)
  68. xmap af <Plug>(coc-funcobj-a)
  69. omap af <Plug>(coc-funcobj-a)
  70. xmap ic <Plug>(coc-classobj-i)
  71. omap ic <Plug>(coc-classobj-i)
  72. xmap ac <Plug>(coc-classobj-a)
  73. omap ac <Plug>(coc-classobj-a)
  74. " Remap <C-f> and <C-b> for scroll float windows/popups.
  75. if has('nvim-0.4.0') || has('patch-8.2.0750')
  76. nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  77. nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  78. inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  79. inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  80. vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  81. vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  82. endif
  83. " Use CTRL-S for selections ranges.
  84. " Requires 'textDocument/selectionRange' support of language server.
  85. nmap <silent> <C-s> <Plug>(coc-range-select)
  86. xmap <silent> <C-s> <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 for CoCList
  98. " Show all diagnostics.
  99. nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
  100. " Manage extensions.
  101. nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
  102. " Show commands.
  103. nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
  104. " Find symbol of current document.
  105. nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
  106. " Search workspace symbols.
  107. nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
  108. " Do default action for next item.
  109. nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
  110. " Do default action for previous item.
  111. nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
  112. " Resume latest coc list.
  113. nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>