]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/vim/coc.vim
nebula: comment about possible cipher
[julm/julm-nix.git] / home-manager / profiles / vim / coc.vim
1 " Custom statusline report
2 function! CocStatus() abort
3 let info = get(b:, 'coc_diagnostic_info', {})
4 if empty(info) | return '' | endif
5 let msgs = []
6 if get(info, 'warning', 0)
7 call add(msgs, 'W' . info['warning'])
8 endif
9 if get(info, 'information', 0)
10 call add(msgs, 'I' . info['information'])
11 endif
12 if get(info, 'hint', 0)
13 call add(msgs, 'H' . info['hint'])
14 endif
15 return join(msgs, ' ') . ' ' . get(g:, 'coc_status', '')
16 endfunction
17 function! CocStatusDiagnosticError() abort
18 let info = get(b:, 'coc_diagnostic_info', {})
19 if !empty(info) && get(info, 'error', 0)
20 return ('E' . info['error'])
21 endif
22 return ''
23 endfunction
24 " Refresh statusline when g:coc_status changes
25 autocmd User CocStatusChange let &statusline=&statusline
26 "autocmd CursorHold let &statusline=&statusline
27
28 " Get correct comment highlighting in coc-settings.json
29 autocmd FileType json syntax match Comment +\/\/.\+$+
30 " Highlights
31 hi CocErrorFloat ctermfg=darkred
32 hi CocErrorSign term=standout ctermfg=15 ctermbg=1 guifg=White guibg=Red
33 hi CocWarningSign term=standout ctermfg=15 ctermbg=130 guifg=White guibg=Orange
34 "hi! link CocErrorSign ErrorMsg
35 "hi! link CocWarningSign WarningMsg
36 hi CocFloating ctermbg=gray ctermfg=black
37 hi CocHintSign ctermbg=gray ctermfg=black
38 hi CocInfoSign ctermbg=darkblue ctermfg=black
39 " Some servers have issues with backup files, see #649.
40 "set nobackup
41 "set nowritebackup
42 " Give more space for displaying messages.
43 "set cmdheight=2
44
45 " Completion
46 set completeopt=noinsert,noselect,menuone
47 " Don't pass messages to |ins-completion-menu|.
48 set shortmess+=c
49 " Use tab for trigger completion with characters ahead and navigate.
50 " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
51 " other plugin before putting this into your config.
52 inoremap <silent><expr> <TAB>
53 \ pumvisible() ? "\<C-n>" :
54 \ <SID>check_back_space() ? "\<TAB>" :
55 \ coc#refresh()
56 function! s:check_back_space() abort
57 let col = col('.') - 1
58 return !col || getline('.')[col - 1] =~# '\s'
59 endfunction
60
61 inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
62
63 " Use <c-space> to trigger completion.
64 inoremap <silent><expr> <c-space> coc#refresh()
65
66 " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
67 " Coc only does snippet and additional edit on confirm.
68 if has('patch8.1.1068')
69 " Use `complete_info` if your (Neo)Vim version supports it.
70 inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
71 else
72 imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
73 endif
74
75 " Use `[g` and `]g` to navigate diagnostics
76 "nmap <silent> [g <Plug>(coc-diagnostic-prev)
77 "nmap <silent> ]g <Plug>(coc-diagnostic-next)
78
79 " GoTo code navigation.
80 nmap <silent> gd <Plug>(coc-definition)
81 nmap <silent> gr <Plug>(coc-references)
82 " Do not seem to work for haskell-ide-engine
83 nmap <silent> gy <Plug>(coc-type-definition)
84 nmap <silent> gi <Plug>(coc-implementation)
85
86 " Use H to show documentation in preview window.
87 nnoremap <silent> H :call <SID>show_documentation()<CR>
88 function! s:show_documentation()
89 if (index(['vim','help'], &filetype) >= 0)
90 execute 'h '.expand('<cword>')
91 else
92 call CocAction('doHover')
93 endif
94 endfunction
95
96 " Escape hides floating window
97 nmap <silent> <c-[> <esc>:noh<cr><Plug>(coc-float-hide)
98
99 " Highlight the symbol and its references when holding the cursor.
100 autocmd CursorHold * silent call CocActionAsync('highlight')
101
102 " Symbol renaming.
103 nmap <leader>rn <Plug>(coc-rename)
104
105 " Formatting selected code.
106 xmap <leader>f <Plug>(coc-format-selected)
107 nmap <leader>f <Plug>(coc-format-selected)
108
109 augroup coc
110 autocmd!
111 " Setup formatexpr specified filetype(s).
112 autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
113 " Update signature help on jump placeholder.
114 autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
115 augroup end
116
117 " Applying codeAction to the selected region.
118 " Example: `<leader>aap` for current paragraph
119 xmap <leader>a <Plug>(coc-codeaction-selected)
120 nmap <leader>a <Plug>(coc-codeaction-selected)
121
122 " Remap keys for applying codeAction to the current line.
123 nmap <leader>al <Plug>(coc-codeaction)
124 " Apply AutoFix to problem on the current line.
125 nmap <leader>qf <Plug>(coc-fix-current)
126
127 " Introduce function text object
128 " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
129 xmap if <Plug>(coc-funcobj-i)
130 xmap af <Plug>(coc-funcobj-a)
131 omap if <Plug>(coc-funcobj-i)
132 omap af <Plug>(coc-funcobj-a)
133
134 " Use <TAB> for selections ranges.
135 " NOTE: Requires 'textDocument/selectionRange' support from the language server.
136 " coc-tsserver, coc-python are the examples of servers that support it.
137 "nmap <silent> <TAB> <Plug>(coc-range-select)
138 "xmap <silent> <TAB> <Plug>(coc-range-select)
139
140 " Add `:Format` command to format current buffer.
141 command! -nargs=0 Format :call CocAction('format')
142 " Add `:Fold` command to fold current buffer.
143 command! -nargs=? Fold :call CocAction('fold', <f-args>)
144 command! -nargs=? Unfold :0,$foldopen
145 " Add `:OR` command for organize imports of the current buffer.
146 command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
147
148 " CocList
149 " Show all diagnostics.
150 nnoremap <silent> <space>fa :<C-u>CocList diagnostics<cr>
151 " Manage extensions.
152 nnoremap <silent> <leader>fe :<C-u>CocList extensions<cr>
153 " Show commands.
154 nnoremap <silent> <leader>fc :<C-u>CocList commands<cr>
155 " Find symbol of current document.
156 nnoremap <silent> <leader>fo :<C-u>CocList outline<cr>
157 " Search workspace symbols.
158 nnoremap <silent> <leader>fs :<C-u>CocList -I symbols<cr>
159 " Do default action for next item in the last list.
160 nnoremap <silent> <leader>fj :<C-u>CocNext<CR>
161 " Do default action for previous item in the last list.
162 nnoremap <silent> <leader>fk :<C-u>CocPrev<CR>
163 " Resume latest coc list.
164 nnoremap <silent> <leader>fp :<C-u>CocListResume<CR>
165 " Find files in cwd.
166 nnoremap <silent> <leader>ff :<C-u>CocList files<CR>
167 " List all errors (bugs).
168 nnoremap <silent> <leader>fb :<C-u>CocList locationlist<CR>
169 " Find buffers.
170 "TODO map <c-s> and <c-v> to open with splits.
171 nnoremap <silent> <leader>bf :<C-u>CocList buffers<CR>
172