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