|
| 1 | +" if hidden is not set, TextEdit might fail. |
| 2 | +set hidden |
| 3 | + |
| 4 | +" Some servers have issues with backup files, see #649 |
| 5 | +set nobackup |
| 6 | +set nowritebackup |
| 7 | + |
| 8 | +" Better display for messages |
| 9 | +set cmdheight=2 |
| 10 | + |
| 11 | +" You will have bad experience for diagnostic messages when it's default 4000. |
| 12 | +set updatetime=300 |
| 13 | + |
| 14 | +" don't give |ins-completion-menu| messages. |
| 15 | +set shortmess+=c |
| 16 | + |
| 17 | +" always show signcolumns |
| 18 | +set signcolumn=yes |
| 19 | + |
| 20 | +" Use tab for trigger completion with characters ahead and navigate. |
| 21 | +" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin. |
| 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 | +
|
| 28 | +function! s:check_back_space() abort |
| 29 | + let col = col('.') - 1 |
| 30 | + return !col || getline('.')[col - 1] =~# '\s' |
| 31 | +endfunction |
| 32 | + |
| 33 | +let g:coc_snippet_next = '<tab>' |
| 34 | + |
| 35 | +" Use <c-space> to trigger completion. |
| 36 | +inoremap <silent><expr> <c-space> coc#refresh() |
| 37 | +
|
| 38 | +" Endwise / coc.nvim compatibility |
| 39 | +let g:endwise_no_mappings = 1 |
| 40 | + |
| 41 | +" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position. |
| 42 | +" Coc only does snippet and additional edit on confirm. |
| 43 | +inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" |
| 44 | +" Or use `complete_info` if your vim support it, like: |
| 45 | +" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" |
| 46 | + |
| 47 | +augroup vimrc-ruby-settings |
| 48 | + autocmd! |
| 49 | + autocmd FileType ruby imap <expr> <CR> pumvisible() ? "\<C-y>\<Plug>DiscretionaryEnd" : "\<CR>\<Plug>DiscretionaryEnd" |
| 50 | +augroup END |
| 51 | + |
| 52 | +" Use `[g` and `]g` to navigate diagnostics |
| 53 | +nmap <silent> [g <Plug>(coc-diagnostic-prev) |
| 54 | +nmap <silent> ]g <Plug>(coc-diagnostic-next) |
| 55 | +
|
| 56 | +" Remap keys for gotos |
| 57 | +nmap <silent> gd <Plug>(coc-definition) |
| 58 | +nmap <silent> gy <Plug>(coc-type-definition) |
| 59 | +nmap <silent> gi <Plug>(coc-implementation) |
| 60 | +nmap <silent> gr <Plug>(coc-references) |
| 61 | +
|
| 62 | +" Use K to show documentation in preview window |
| 63 | +nnoremap <silent> K :call <SID>show_documentation()<CR> |
| 64 | +
|
| 65 | +function! s:show_documentation() |
| 66 | + if (index(['vim','help'], &filetype) >= 0) |
| 67 | + execute 'h '.expand('<cword>') |
| 68 | + else |
| 69 | + call CocAction('doHover') |
| 70 | + endif |
| 71 | +endfunction |
| 72 | + |
| 73 | +" Highlight symbol under cursor on CursorHold |
| 74 | +autocmd CursorHold * silent call CocActionAsync('highlight') |
| 75 | + |
| 76 | +" Remap for rename current word |
| 77 | +nmap <leader>rn <Plug>(coc-rename) |
| 78 | +
|
| 79 | +" Remap for format selected region |
| 80 | +xmap <leader>f <Plug>(coc-format-selected) |
| 81 | +nmap <leader>f <Plug>(coc-format-selected) |
| 82 | +
|
| 83 | +augroup mygroup |
| 84 | + autocmd! |
| 85 | + " Setup formatexpr specified filetype(s). |
| 86 | + autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') |
| 87 | + " Update signature help on jump placeholder |
| 88 | + autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') |
| 89 | +augroup end |
| 90 | + |
| 91 | +" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph |
| 92 | +xmap <leader>a <Plug>(coc-codeaction-selected) |
| 93 | +nmap <leader>a <Plug>(coc-codeaction-selected) |
| 94 | +
|
| 95 | +" Remap for do codeAction of current line |
| 96 | +nmap <leader>ac <Plug>(coc-codeaction) |
| 97 | +" Fix autofix problem of current line |
| 98 | +nmap <leader>qf <Plug>(coc-fix-current) |
| 99 | +
|
| 100 | +" Create mappings for function text object, requires document symbols feature of languageserver. |
| 101 | +xmap if <Plug>(coc-funcobj-i) |
| 102 | +xmap af <Plug>(coc-funcobj-a) |
| 103 | +omap if <Plug>(coc-funcobj-i) |
| 104 | +omap af <Plug>(coc-funcobj-a) |
| 105 | +
|
| 106 | +" Use <TAB> for select selections ranges, needs server support, like: coc-tsserver, coc-python |
| 107 | +nmap <silent> <TAB> <Plug>(coc-range-select) |
| 108 | +xmap <silent> <TAB> <Plug>(coc-range-select) |
| 109 | +
|
| 110 | +" Use `:Format` to format current buffer |
| 111 | +command! -nargs=0 Format :call CocAction('format') |
| 112 | + |
| 113 | +" Use `:Fold` to fold current buffer |
| 114 | +command! -nargs=? Fold :call CocAction('fold', <f-args>) |
| 115 | + |
| 116 | +" use `:OR` for organize import of current buffer |
| 117 | +command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') |
| 118 | + |
| 119 | +" Add status line support, for integration with other plugin, checkout `:h coc-status` |
| 120 | +set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} |
| 121 | + |
| 122 | +" Using CocList |
| 123 | +" Show all diagnostics |
| 124 | +nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr> |
| 125 | +" Manage extensions |
| 126 | +nnoremap <silent> <space>e :<C-u>CocList extensions<cr> |
| 127 | +" Show commands |
| 128 | +nnoremap <silent> <space>c :<C-u>CocList commands<cr> |
| 129 | +" Find symbol of current document |
| 130 | +nnoremap <silent> <space>o :<C-u>CocList outline<cr> |
| 131 | +" Search workspace symbols |
| 132 | +nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr> |
| 133 | +" Do default action for next item. |
| 134 | +nnoremap <silent> <space>j :<C-u>CocNext<CR> |
| 135 | +" Do default action for previous item. |
| 136 | +nnoremap <silent> <space>k :<C-u>CocPrev<CR> |
| 137 | +" Resume latest coc list |
| 138 | +nnoremap <silent> <space>p :<C-u>CocListResume<CR> |
| 139 | +"" END COC Config |
0 commit comments