Mercurial > vim
comparison plugins/coc @ 0:a4ec03f77554
I don't know...
| author | luka |
|---|---|
| date | Fri, 11 Apr 2025 21:07:37 -0400 |
| parents | |
| children | 47fe251d5ce0 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a4ec03f77554 |
|---|---|
| 1 Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
| 2 " https://raw.githubusercontent.com/neoclide/coc.nvim/master/doc/coc-example-config.vim | |
| 3 | |
| 4 " May need for Vim (not Neovim) since coc.nvim calculates byte offset by count | |
| 5 " utf-8 byte sequence | |
| 6 set encoding=utf-8 | |
| 7 " Some servers have issues with backup files, see #649 | |
| 8 set nobackup | |
| 9 set nowritebackup | |
| 10 | |
| 11 " Having longer updatetime (default is 4000 ms = 4s) leads to noticeable | |
| 12 " delays and poor user experience | |
| 13 set updatetime=300 | |
| 14 | |
| 15 " Always show the signcolumn, otherwise it would shift the text each time | |
| 16 " diagnostics appear/become resolved | |
| 17 set signcolumn=yes | |
| 18 | |
| 19 " Use tab for trigger completion with characters ahead and navigate | |
| 20 " NOTE: There's always complete item selected by default, you may want to enable | |
| 21 " no select by `"suggest.noselect": true` in your configuration file | |
| 22 " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by | |
| 23 " other plugin before putting this into your config | |
| 24 inoremap <silent><expr> <TAB> | |
| 25 \ coc#pum#visible() ? coc#pum#next(1) : | |
| 26 \ CheckBackspace() ? "\<Tab>" : | |
| 27 \ coc#refresh() | |
| 28 inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>" | |
| 29 | |
| 30 " Make <CR> to accept selected completion item or notify coc.nvim to format | |
| 31 " <C-g>u breaks current undo, please make your own choice | |
| 32 inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() | |
| 33 \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" | |
| 34 | |
| 35 function! CheckBackspace() abort | |
| 36 let col = col('.') - 1 | |
| 37 return !col || getline('.')[col - 1] =~# '\s' | |
| 38 endfunction | |
| 39 | |
| 40 " Use <c-space> to trigger completion | |
| 41 if has('nvim') | |
| 42 inoremap <silent><expr> <c-space> coc#refresh() | |
| 43 else | |
| 44 inoremap <silent><expr> <c-@> coc#refresh() | |
| 45 endif | |
| 46 | |
| 47 " Use `[g` and `]g` to navigate diagnostics | |
| 48 " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list | |
| 49 nmap <silent> [g <Plug>(coc-diagnostic-prev) | |
| 50 nmap <silent> ]g <Plug>(coc-diagnostic-next) | |
| 51 | |
| 52 " GoTo code navigation | |
| 53 nmap <silent> gd <Plug>(coc-definition) | |
| 54 nmap <silent> gy <Plug>(coc-type-definition) | |
| 55 nmap <silent> gi <Plug>(coc-implementation) | |
| 56 nmap <silent> gr <Plug>(coc-references) | |
| 57 | |
| 58 " Use K to show documentation in preview window | |
| 59 nnoremap <silent> K :call ShowDocumentation()<CR> | |
| 60 | |
| 61 function! ShowDocumentation() | |
| 62 if CocAction('hasProvider', 'hover') | |
| 63 call CocActionAsync('doHover') | |
| 64 else | |
| 65 call feedkeys('K', 'in') | |
| 66 endif | |
| 67 endfunction | |
| 68 | |
| 69 " Highlight the symbol and its references when holding the cursor | |
| 70 autocmd CursorHold * silent call CocActionAsync('highlight') | |
| 71 | |
| 72 " Symbol renaming | |
| 73 nmap <leader>rn <Plug>(coc-rename) | |
| 74 | |
| 75 " Formatting selected code | |
| 76 xmap <leader>f <Plug>(coc-format-selected) | |
| 77 nmap <leader>f <Plug>(coc-format-selected) | |
| 78 | |
| 79 augroup mygroup | |
| 80 autocmd! | |
| 81 " Setup formatexpr specified filetype(s) | |
| 82 autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') | |
| 83 " Update signature help on jump placeholder | |
| 84 autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') | |
| 85 augroup end | |
| 86 | |
| 87 " Applying code actions to the selected code block | |
| 88 " Example: `<leader>aap` for current paragraph | |
| 89 xmap <leader>a <Plug>(coc-codeaction-selected) | |
| 90 nmap <leader>a <Plug>(coc-codeaction-selected) | |
| 91 | |
| 92 " Remap keys for applying code actions at the cursor position | |
| 93 nmap <leader>ac <Plug>(coc-codeaction-cursor) | |
| 94 " Remap keys for apply code actions affect whole buffer | |
| 95 nmap <leader>as <Plug>(coc-codeaction-source) | |
| 96 " Apply the most preferred quickfix action to fix diagnostic on the current line | |
| 97 nmap <leader>qf <Plug>(coc-fix-current) | |
| 98 | |
| 99 " Remap keys for applying refactor code actions | |
| 100 nmap <silent> <leader>re <Plug>(coc-codeaction-refactor) | |
| 101 xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) | |
| 102 nmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) | |
| 103 | |
| 104 " Run the Code Lens action on the current line | |
| 105 nmap <leader>cl <Plug>(coc-codelens-action) | |
| 106 | |
| 107 " Map function and class text objects | |
| 108 " NOTE: Requires 'textDocument.documentSymbol' support from the language server | |
| 109 xmap if <Plug>(coc-funcobj-i) | |
| 110 omap if <Plug>(coc-funcobj-i) | |
| 111 xmap af <Plug>(coc-funcobj-a) | |
| 112 omap af <Plug>(coc-funcobj-a) | |
| 113 xmap ic <Plug>(coc-classobj-i) | |
| 114 omap ic <Plug>(coc-classobj-i) | |
| 115 xmap ac <Plug>(coc-classobj-a) | |
| 116 omap ac <Plug>(coc-classobj-a) | |
| 117 | |
| 118 " Remap <C-f> and <C-b> to scroll float windows/popups | |
| 119 if has('nvim-0.4.0') || has('patch-8.2.0750') | |
| 120 nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" | |
| 121 nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>" | |
| 122 inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>" | |
| 123 inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>" | |
| 124 vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" | |
| 125 vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>" | |
| 126 endif | |
| 127 | |
| 128 " Use CTRL-S for selections ranges | |
| 129 " Requires 'textDocument/selectionRange' support of language server | |
| 130 nmap <silent> <C-s> <Plug>(coc-range-select) | |
| 131 xmap <silent> <C-s> <Plug>(coc-range-select) | |
| 132 | |
| 133 " Add `:Format` command to format current buffer | |
| 134 command! -nargs=0 Format :call CocActionAsync('format') | |
| 135 | |
| 136 " Add `:Fold` command to fold current buffer | |
| 137 command! -nargs=? Fold :call CocAction('fold', <f-args>) | |
| 138 | |
| 139 " Add `:OR` command for organize imports of the current buffer | |
| 140 command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport') | |
| 141 | |
| 142 " Add (Neo)Vim's native statusline support | |
| 143 " NOTE: Please see `:h coc-status` for integrations with external plugins that | |
| 144 " provide custom statusline: lightline.vim, vim-airline | |
| 145 set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} | |
| 146 | |
| 147 " Mappings for CoCList | |
| 148 " Show all diagnostics | |
| 149 nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr> | |
| 150 " Manage extensions | |
| 151 nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr> | |
| 152 " Show commands | |
| 153 nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr> | |
| 154 " Find symbol of current document | |
| 155 nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr> | |
| 156 " Search workspace symbols | |
| 157 nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr> | |
| 158 " Do default action for next item | |
| 159 nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR> | |
| 160 " Do default action for previous item | |
| 161 nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR> | |
| 162 " Resume latest coc list | |
| 163 nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR> |
