dotfiles

beau's configuration files
git clone https://git.beauhilton.com/dotfiles.git
Log | Files | Refs | README

coc.vim (4585B)


      1 " Some servers have issues with backup files, see #649.
      2 set nobackup
      3 set nowritebackup
      4 
      5 " Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
      6 " delays and poor user experience.
      7 set updatetime=300
      8 
      9 " Don't pass messages to |ins-completion-menu|.
     10 set shortmess+=c
     11 
     12 " Always show the signcolumn, otherwise it would shift the text each time
     13 " diagnostics appear/become resolved.
     14 if has("patch-8.1.1564")
     15   " Recently vim can merge signcolumn and number column into one
     16   set signcolumn=number
     17 else
     18   set signcolumn=yes
     19 endif
     20 
     21 " Use tab for trigger completion with characters ahead and navigate.
     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       \ pumvisible() ? "\<C-n>" :
     26       \ <SID>check_back_space() ? "\<TAB>" :
     27       \ coc#refresh()
     28 inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
     29 
     30 function! s:check_back_space() abort
     31   let col = col('.') - 1
     32   return !col || getline('.')[col - 1]  =~# '\s'
     33 endfunction
     34 
     35 " Use <c-space> to trigger completion.
     36 if has('nvim')
     37   inoremap <silent><expr> <c-space> coc#refresh()
     38 else
     39   inoremap <silent><expr> <c-@> coc#refresh()
     40 endif
     41 
     42 " Make <CR> auto-select the first completion item and notify coc.nvim to
     43 " format on enter, <cr> could be remapped by other vim plugin
     44 inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
     45                               \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
     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 <SID>show_documentation()<CR>
     60 
     61 function! s:show_documentation()
     62   if (index(['vim','help'], &filetype) >= 0)
     63     execute 'h '.expand('<cword>')
     64   elseif (coc#rpc#ready())
     65     call CocActionAsync('doHover')
     66   else
     67     execute '!' . &keywordprg . " " . expand('<cword>')
     68   endif
     69 endfunction
     70 
     71 " Highlight the symbol and its references when holding the cursor.
     72 autocmd CursorHold * silent call CocActionAsync('highlight')
     73 
     74 " Symbol renaming.
     75 nmap <leader>rn <Plug>(coc-rename)
     76 
     77 " Formatting selected code.
     78 xmap <leader>f  <Plug>(coc-format-selected)
     79 nmap <leader>f  <Plug>(coc-format-selected)
     80 
     81 augroup mygroup
     82   autocmd!
     83   " Setup formatexpr specified filetype(s).
     84   autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
     85   " Update signature help on jump placeholder.
     86   autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
     87 augroup end
     88 
     89 " Applying codeAction to the selected region.
     90 " Example: `<leader>aap` for current paragraph
     91 xmap <leader>a  <Plug>(coc-codeaction-selected)
     92 nmap <leader>a  <Plug>(coc-codeaction-selected)
     93 
     94 " Remap keys for applying codeAction to the current buffer.
     95 nmap <leader>ac  <Plug>(coc-codeaction)
     96 " Apply AutoFix to problem on the current line.
     97 nmap <leader>qf  <Plug>(coc-fix-current)
     98 
     99 " Add `:Format` command to format current buffer.
    100 command! -nargs=0 Format :call CocAction('format')
    101 
    102 " Add `:Fold` command to fold current buffer.
    103 command! -nargs=? Fold :call     CocAction('fold', <f-args>)
    104 
    105 " Add `:OR` command for organize imports of the current buffer.
    106 command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')
    107 
    108 " Add (Neo)Vim's native statusline support.
    109 " NOTE: Please see `:h coc-status` for integrations with external plugins that
    110 " provide custom statusline: lightline.vim, vim-airline.
    111 set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
    112 
    113 " Mappings for CoCList
    114 " Show all diagnostics.
    115 nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
    116 " Manage extensions.
    117 nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
    118 " Show commands.
    119 nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
    120 " Find symbol of current document.
    121 nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
    122 " Search workspace symbols.
    123 nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
    124 " Do default action for next item.
    125 nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
    126 " Do default action for previous item.
    127 nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
    128 " Resume latest coc list.
    129 nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>