forked from nviennot/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc.mine.afrojer
More file actions
388 lines (340 loc) · 12.8 KB
/
vimrc.mine.afrojer
File metadata and controls
388 lines (340 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
let g:os = substitute(system('uname'), "\n", "", "")
if $TERM =~ '256color'
set t_Co=256
elseif $TERM =~ '^xterm$'
set t_Co=256
elseif g:os == "Darwin"
set t_Co=256
endif
" Disable background color erase by clearing the t_ut terminal option
set t_ut=
set mouse=a " allow mouse from terminal
command! -nargs=? HighlightLongLines call s:HighlightLongLines('<args>')
function! s:HighlightLongLines(width)
let targetWidth = a:width != '' ? a:width : 79
if targetWidth > 0
exec 'match Todo /\%>' . (targetWidth) . 'v/'
else
echomsg "Usage: HighlightLongLines [natural number]"
endif
endfunction
map <Leader>ll :HighlightLongLines 80<cr>
map <Leader>nl :HighlightLongLines 1000<cr>
function! SetWhitespaceFormat(style)
set copyindent
set preserveindent
set softtabstop=0
if a:style =~ '^android'
set expandtab
set tabstop=4
set shiftwidth=4
set textwidth=120
echomsg "Whitespace format set to 'android'"
elseif a:style =~ '^xnu'
set noexpandtab
set tabstop=4
set shiftwidth=4
set textwidth=100
echomsg "Whitespace format set to 'XNU'"
elseif a:style =~ '^linux'
set noexpandtab
set tabstop=8
set shiftwidth=8
set textwidth=80
echomsg "Whitespace format set to 'kernel'"
elseif a:style =~ '^octopus'
set expandtab
set tabstop=4
set shiftwidth=4
set textwidth=80
echomsg "Whitespace format set to 'Octopus'"
elseif a:style =~ '^latex'
set expandtab
set tabstop=2
set shiftwidth=2
set textwidth=80
echomsg "Whitespace format set to 'LaTeX'"
else
set noexpandtab
set tabstop=4
set shiftwidth=4
set textwidth=100
echomsg "default whitespace format..."
endif
endfunction
set noexpandtab
set tabstop=4
set shiftwidth=4
set textwidth=80
map <Leader>wa :call SetWhitespaceFormat("android")<CR>
map <Leader>wk :call SetWhitespaceFormat("linux")<CR>
map <Leader>wx :call SetWhitespaceFormat("xnu")<CR>
map <Leader>wo :call SetWhitespaceFormat("octopus")<CR>
map <Leader>wl :call SetWhitespaceFormat("latex")<CR>
map <Leader>wd :call SetWhitespaceFormat("default")<CR>
command! -nargs=* GrepSyscall call s:GrepSyscall(<f-args>)
function! s:GrepSyscall(name,path)
let tgtPath = a:path != '' ? a:path : '.'
if a:name != ''
echomsg "Looking for a syscall named ".a:name." in ".tgtPath
exec "grep -sInR 'SYSCALL.*".a:name."' ".tgtPath
else
echomsg "Usage: GrepSyscall [syscall_name] {path}"
endif
endfunction
map <Leader>gs :call GrepSyscall
""""""""""""""""""""""""""""""
" => Minibuffer plugin
""""""""""""""""""""""""""""""
"map <M-j> :bn<cr>
"map <M-k> :bp<cr>
"map <C-h> :tabprev<cr>
"map <C-l> :tabnext<cr>
" force these values (Ctrl-J seems to get messed up somwhere...)
nnoremap <C-j> :wincmd j<CR>
nnoremap <C-k> :wincmd k<CR>
nnoremap <C-h> :wincmd h<CR>
nnoremap <C-l> :wincmd l<CR>
nnoremap <C-N> :cnext<cr>
nnoremap <C-P> :cprev<cr>
if g:os == "Linux"
:command! -bar -nargs=1 OpenURL :!firefox <args>
elseif g:os == "Darwin"
:command! -bar -nargs=1 OpenURL :!open <args>
endif
" CleanClose
nmap fc :call CleanClose(1)<cr>
nmap fq :call CleanClose(0)<cr>
function! CleanClose(tosave)
if (a:tosave == 1)
w!
endif
let todelbufNr = bufnr("%")
let newbufNr = bufnr("#")
if ((newbufNr != -1) && (newbufNr != todelbufNr) && buflisted(newbufNr))
exe "b".newbufNr
else
bnext
endif
if (bufnr("%") == todelbufNr)
new
endif
exe "bd!".todelbufNr
endfunction
""""""""""""""""""""""""""""""""""""""""
let Grep_Skip_Dirs = '.git'
let Grep_Skip_files = '*~ cscope* .svn'
" -s: suppress non-existant/unreadable file errors
" -I: process binary files
" -n: prefix result with line number
" -R: recursive
let Grep_Default_Options = '-s -I -n -R'
nnoremap <silent> <F7> :Rgrep <CR><CR><CR><CR>
map <Leader>ss :setlocal spell!<cr>
map <Leader>tr :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>
map <Leader>me :MBEOpen<cr>
map <Leader>mc :MBECloseAll<cr>
map <Leader>c :call setqflist([])<cr>
if has("unix")
if g:os == "Darwin"
" vnoremap <Leader>y y:call system("pbcopy", getreg("\""))<cr>
" nnoremap <Leader>p :call setreg("\"",system("pbpaste"))<CR>p
vnoremap <Leader>y y:call system("ssh localhost pbcopy 2>/dev/null", getreg(""))<CR><CR>
nnoremap <Leader>p :call setreg("",system("ssh localhost pbpaste 2>/dev/null"))<CR>p
else
vnoremap <Leader>y "*y
nnoremap <Leader>p "*p
endif
endif
" Let mac-vim receive meta-key input
if has("gui_running") && has("unix")
if g:os == "Darwin"
set invmmta
endif
endif
""""""""""""""""""""""""""""""""""""""
" Some Vim-LaTeX settings
set shellslash
set grepprg=grep\ -nH\ $*
if has('gui_running')
let g:tex_flavor='pdflatex'
let g:Tex_DefaultTargetFormat = 'pdf'
"TexLet g:Tex_TreatMacViewerAsUNIX = 1
let Tex_ViewRuleComplete_pdf = '/usr/bin/open -a Preview $*.pdf'
endif
""""""""""""""""""""""""""""""""""""""
" When I write assembly, I write ARM assembly
au BufNewFile,BufRead *.S set filetype=armasm
""""""""""""""""""""""""""""""""""""""
" *.m files are Objective C
au BufNewFile,BufRead *.m set filetype=objc
""""""""""""""""""""""""""""""""""""""
" Pipe kernel buffer into appropriately named file: voila colors
au BufNewFile,BufRead *.crdmesg set filetype=crdmesg
au BufNewFile,BufRead *.dmesg set filetype=xnudmesg
au BufNewFile,BufRead *.xnudmesg set filetype=xnudmesg
" Fugitve key mappings
autocmd User fugitive
\ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' |
\ nnoremap <buffer> .. :edit %:h<CR> |
\ endif
autocmd BufReadPost fugitive://* set bufhidden=delete
"if executable('git-hyper-blame')
" let g:fugitive_blame_cmd = 'hyper-blame'
"endif
""""""""""""""""""""""""""""""""""""""
" Get rid of some very annoying warnings opening stdin
compiler gcc
"set errorformat^=%-G<stdin>:%l:2:\ warning:\ #warning\ syscall\ process_vm_readv\ not\ implemented\ [-Wcpp]
"set errorformat^=%-G<stdin>:%l:2:\ warning:\ #warning\ syscall\ process_vm_writev\ not\ implemented\ [-Wcpp]
"set errorformat^=%-G<stdin>:%l:2:\ warning:\ #warning\ \"TODO:\ return_address\ should\ user\ unwind\ tables\"
"set errorformat^=%-G<stdin>:%l:2:\ warning:\ #warning\ \"TODO:\ return_address\ should\ user\ unwind\ tables\"\ [-Wcpp]
"""""""""""""""""""""""""""""""""""""""
"" Remap autocomplete to ctrl+space
"if has("gui_running")
" " C-Space seems to work under gVim on both Linux and win32
" inoremap <C-Space> <C-n>
"else " no gui
" if has("unix")
" inoremap <Nul> <C-n>
" else
" " I have no idea of the name of Ctrl-Space elsewhere
" endif
"endif
""""""""""""""""""""""""""""""
" => fugitive plugin
""""""""""""""""""""""""""""""
nnoremap <silent> <Leader>gf :Git fetch<CR>
nnoremap <silent> <Leader>gs :Gstatus<CR>
""""""""""""""""""""""""""""""
" => YouCompleteMe plugin
"
" more info: https://valloric.github.io/YouCompleteMe/#options
"
let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'
" Don't ask for permission to load extra conf files
let g:ycm_confirm_extra_conf = 0
" setting this to a high value will effectively turn off identifier completion
" while keeping semantic triggers (e.g. for '.' or '->')
let g:ycm_min_num_of_chars_for_completion = 3
" identifier completion
let g:ycm_auto_trigger = 1
" show detailed diagnostic info (for compilation errors)
let g:ycm_key_detailed_diagnostics = '<leader>d'
" Don't put completion candidate info in a preview window at the top of the file
let g:ycm_add_preview_to_completeopt = 1
""""""""""""""""""""""""""""""
" => deoplete plugin
"
" NOTE: disable for now in favor of vim-lsp-cxx highlighting
"
"if has("python3")
" let g:deoplete#enable_at_startup = 1
" call deoplete#enable()
"endif
""""""""""""""""""""""""""""""
" => vim-gitgutter plugin
""""""""""""""""""""""""""""""
let g:gitgutter_map_keys = 0
nnoremap <silent> <Leader>hn :GitGutterNextHunk<CR>
nnoremap <silent> <Leader>hp :GitGutterPrevHunk<CR>
nnoremap <silent> <Leader>hs :GitGutterStageHunk<CR>
nnoremap <silent> <Leader>hr :GitGutterRevertHunk<CR>
nnoremap <silent> <Leader>hv :GitGutterPreviewHunk<CR>
nnoremap <silent> <Leader>gg :GitGutterToggle<CR>
""""""""""""""""""""""""""""""
" => cscope keybindings
""""""""""""""""""""""""""""""
if is_nvim
lua require("cscope_maps").setup()
else
set cscopequickfix=s-,g-,d-,c-,t-,e-,f-,i-
endif
" The :execute... bits will perform a Ctrl-O to jump back to the previous
" location, and the :copen will open the quickfix buffer. This interacts nicely
" with the cscopequickfix line above: now cscope results will be placed in the
" quickfix buffer, you will still be in the same location in your code, and the
" quickfix buffer will be in focus for easy searching of results.
" Find this C symbol
"nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:copen<CR>
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:cwindow<CR>/<C-R>=expand("<cword>")<CR><CR>
" Find this definition
"nmap <C-\>G :cs find g <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:copen<CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:cwindow<CR>/<C-R>=expand("<cword>")<CR><CR>
" Find functions calling this function
"nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:copen<CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:cwindow<CR>/<C-R>=expand("<cword>")<CR><CR>
" Find assignments to
"nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:copen<CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:cwindow<CR>/<C-R>=expand("<cword>")<CR><CR>
" Find this egrep pattern
"nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:copen<CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:cwindow<CR>/<C-R>=expand("<cword>")<CR><CR>
" Find this file
"nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR> :execute "normal! \<C-O>"<CR>:copen<CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR> :execute "normal! \<C-O>"<CR>:cwindow<CR>/<C-R>=expand("<cword>")<CR><CR>
" Find files #-including this file
"nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR> :execute "normal! \<C-O>"<CR>:copen<CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR> :execute "normal! \<C-O>"<CR>:cwindow<CR>/<C-R>=expand("<cword>")<CR><CR>
" Find functions called by this function
"nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:copen<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR> :execute "normal! \<C-O>"<CR>:cwindow<CR>/<C-R>=expand("<cword>")<CR><CR>
""""""""""""""""""""""""""""""
" => codequery plugin
""""""""""""""""""""""""""""""
let g:codequery_trigger_build_db_when_db_not_found = 1
let g:codequery_auto_switch_to_find_text_for_wrong_filetype = 1
let g:codequery_find_text_cmd = 'Ag!'
nnoremap <silent> <Leader>; :CodeQueryMenu Unite Magic<CR>
nmap <C-\>q :CodeQuery Symbol<CR>
""""""""""""""""""""""""""""""
" => silver searcher (ag) plugin
""""""""""""""""""""""""""""""
set runtimepath^=~/.vim/bundle/ag
" Take it easy on the auto updating
autocmd BufEnter * set updatetime=60000
""""""""""""""""""""""""""""""""""""""
" Append modeline after last line in buffer.
" Use substitute() instead of printf() to handle '%%s' modeline in LaTeX files.
" Taken from: http://vim.wikia.com/wiki/Modeline_magic
function! AppendModeline()
let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d %set :",
\ &tabstop, &shiftwidth, &textwidth, &expandtab ? '' : 'no')
let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
call append(line("$"), l:modeline)
endfunction
nnoremap <silent> <Leader>ml :call AppendModeline()<CR>
""""----------------------------------------------------------------------""""
""""
"""" configuration for the coc.nvim plugin for syntax highlighting
"""" and code completion via clangd
""""
so ~/.vim/vimrc.coc.nvim
""""----------------------------------------------------------------------""""
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
set laststatus=2
function! GitBranch()
return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
endfunction
function! StatuslineGitInfo()
let l:branchname = GitBranch()
return strlen(l:branchname) > 0?' '.l:branchname.' ':''
endfunction
set statusline=
set statusline+=%#StatusLineGit#%{StatuslineGitInfo()}
set statusline+=%#StatusLineNm#
set statusline+=\ \|%#StatusLineFile#%f%#StatusLineNm#\|
set statusline+=\ %#StatusLineFType#%y
set statusline+=%#StatusLineNm#
"set statusline+=\ %m
set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
"set statusline+=\[%{&fileformat}\]
set statusline+=\ %#StatusLineCol#%l:%c
set statusline+=\ %#StatusLineNm#(%p%%)
set statusline+=\ %#StatusLineFunc#%{tagbar#currenttag('%s','','f','scoped-stl')}
set statusline+=%#StatusLineNm#
set statusline+=\ %#StatusLineFunc#%{get(b:,'coc_current_function','')}
set statusline+=%=
set statusline+=\ %#StatusLineDbg#%{coc#status()}