-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_vimrc
421 lines (344 loc) · 12.8 KB
/
_vimrc
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
" Force use of utf-8
set encoding=utf-8
syntax on
" Add modeline functionality -- it's disabled by default on some distros
set modeline
filetype plugin on
" Mapping from usenet.
imap jj <Esc>
" Per-filetype settings
autocmd FileType java setlocal tw=78 cin foldmethod=marker
autocmd FileType c,cpp setlocal tw=80 cindent noexpandtab
autocmd FileType python setlocal autoindent expandtab sts=4 sw=4 tw=78
autocmd FileType haskell setlocal tw=72 sw=2 sts=2 et
autocmd FileType tex call SetTexSettings()
" 'linebreak' won't work without 'nolist'
autocmd FileType creole setlocal tw=0 fo=t wrap nolist linebreak
autocmd FileType mail setlocal tw=72 fo=tql
autocmd FileType lua setlocal sts=4 sw=4 ai et
autocmd FileType rust setlocal cin
autocmd FileType sh setlocal sts=4 sw=4 si et
autocmd FileType asm setlocal noexpandtab
" Custom filetypes per extension. Not sure this is the recommended way to do it.
autocmd BufRead,BufNewFile *.wiki setlocal ft=creole
autocmd BufRead,BufNewFile *.tex setlocal ft=tex
autocmd BufRead,BufNewFile *.cool setlocal ft=cool
autocmd BufRead,BufNewFile *.cl setlocal ft=cool
autocmd BufRead,BufNewFile *.miC setlocal ft=C
autocmd BufRead,BufNewFile *.g setlocal ft=antlr
autocmd BufRead,BufNewFile *.rkt setlocal ft=scheme
autocmd BufRead,BufNewFile *.[sS] setlocal ft=asm
autocmd BufRead,BufNewFile *.asm setlocal ft=asm
autocmd BufRead,BufNewFile Makefile.* setlocal ft=make
autocmd BufRead,BufNewFile SConstruct* setlocal ft=python tw=0
autocmd BufRead,BufNewFile SConscript* setlocal ft=python tw=0
function! SetTexSettings()
setlocal tw=72
setlocal sw=2
setlocal sts=2
setlocal ai
setlocal et
setlocal noexpandtab
setlocal spell
setlocal spelllang=en_us
syntax spell toplevel
endfunction
" Use vundle for plugin management
set nocompatible
"filetype off
" You will need to install Vundle and YouCompleteMe to use the following
" (commented) lines
"set rtp+=~/.vim/bundle/Vundle.vim
"call vundle#begin()
"Plugin 'Valloric/YouCompleteMe'
"call vundle#end()
filetype plugin indent on
" vundle end
" Done youcompleteme
set autowrite
set nowrap
" Use /tmp as directory for temporary files
set dir=/tmp
" Ripped off from Alexandru Mosoi
set statusline=%<%f\ %y%h%m%r%=%-24.(0x%02B,%l/%L,%c%V%)\ %P
set laststatus=2
set wildmenu
set softtabstop=4
" /ripoff
" Ripped off from Cosmin Ratiu, on SO list; 30 Jun 2009
if has("cscope")
" Look for a 'cscope.out' file starting from the current directory,
" going up to the root directory.
let s:dirs = split(getcwd(), "/")
let s:cscope = 0
let s:ctags = 0
while s:dirs != []
let s:path = "/" . join(s:dirs, "/")
if (s:cscope == 0 && filereadable(s:path . "/cscope.out"))
set nocscopeverbose
execute "cs add " . s:path . "/cscope.out " . s:path . " -v"
set cscopeverbose
let s:cscope = 1
endif
if (s:ctags == 0 && filereadable(s:path . "/tags"))
execute "set tags=" . s:path . "/tags"
let s:ctags = 1
endif
if (s:cscope == 1 && s:ctags == 1)
break
endif
let s:dirs = s:dirs[:-2]
endwhile
set csto=1 " use cscope first, then ctags
set cst " Use cstag instead of tag (search both cscope and tags)
set csverb " Make cs verbose
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>a :cs find a <C-R>=expand("<cword>")<CR><CR>
nmap <C-\|>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\|>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\|>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\|>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\|>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\|>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\|>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\|>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>
nmap <C-\|>a :vert scs find a <C-R>=expand("<cword>")<CR><CR>
" Open a quickfix window for the following queries.
"set cscopequickfix=s-,c-,d-,i-,t-,e-,g-
endif
" More tabs -- we have enough memory.
set tabpagemax=20
" Mark tabs and spaces
set list listchars=tab:᚛·,
map Q gq
" Highlight current line
set cursorline
" Open new vertical splits to the right of current one.
set splitright
set hidden
set smartcase
set ignorecase
nnoremap <F9> :cwindow<CR>
nnoremap <F10> :ccl<CR>
nnoremap - gT
nnoremap = gt
nnoremap <C-s> nop
vnoremap <C-k> :<C-u>silent! '<,'>m '<-2<CR>`[V`]
vnoremap <C-j> :<C-u>silent! '<,'>m '>+1<CR>`[V`]
nnoremap <silent><leader>, :noh<cr>
" Set folding options
autocmd ColorScheme * highlight Folded ctermbg=black ctermfg=41
set foldlevel=5
" Fold methods and structures automatically
set foldmethod=syntax
nmap , <leader>
" Toggle folding under the cursor using C-f;
" if in insert mode, return to normal and close fold
nnoremap <C-f> za
inoremap <C-f> <esc>zc
" Toggle foldings file-wide using C-g;
" if used in insert mode, first return to normal mode
nnoremap <C-g> :call ToggleFileFolds()<CR>
inoremap <C-g> <esc>:call ToggleFileFolds()<CR>i
" Go to previous buffer when deleting the buffer in stead of killing the
" current split (or tab)
nnoremap <silent> <leader>b :bp\|bd#<CR>
" Make ci\X and di\X commands act similar to ci" and di" respectively
nnoremap <silent> ci( hf(ci(
nnoremap <silent> ci[ hf[ci[
nnoremap <silent> ci{ hf{ci{
nnoremap <silent> di( hf(di(
nnoremap <silent> di[ hf[di[
nnoremap <silent> di{ hf{di{
" Make also C-w work in insert mode
inoremap <silent> <C-w>h <C-o><C-w>h
inoremap <silent> <C-w>j <C-o><C-w>j
inoremap <silent> <C-w>k <C-o><C-w>k
inoremap <silent> <C-w>l <C-o><C-w>l
" Comment/uncomment convenience
nnoremap <silent> <C-S-C> :call ToggleComment()<CR>
vnoremap <silent> <C-S-C> :call ToggleComment()<CR>gv
function! ToggleComment() range
" If the first line is not lead by the // comment, comment the lines
if (match(getline(a:firstline), '^\s*//') == -1)
execute a:firstline . ',' . a:lastline . 's,^\(\s*\),\1//,'
else
execute a:firstline . ',' . a:lastline . 's,^\(\s*\)//,\1,'
endif
endfunction
" Helper function to figure values of macros in enums
" If an 'enum' is not found at the start of the line, will display the current
" line number
function! EnumValue() range
let l:enumStart = search('^enum.\+{', 'bnW') + 1
let l:lastEndBracket = search('}', 'bnW') + 1
if (l:lastEndBracket >= l:enumStart)
echo "Not in an enum"
return
endif
for l:line in range(a:firstline, a:lastline)
let l:lineStr = getline(l:line)
let l:trimmedLine = matchstr(l:lineStr, '[a-zA-Z0-9_]\+')
echo l:trimmedLine . ' -> ' . (l:line - l:enumStart)
endfor
endfunction
" Helper function to toggle all folds at file level
function! ToggleFileFolds()
if &foldlevel == 0
normal zR
else
normal zM
endif
endfunction
" Align subsequent lines to open parantheses in C sources. Via andradaq.
" Values:
" (0 -> align next line with the last unclosed parentheses
" W4 -> if the open parentheses is the last charater on the line, indent next
" > line 4 characters to the right
" :0 -> align cases in switch clauses with the 'switch'
" l1 -> align subsequent lines with the case statement, not what follows it
set cinoptions=(0,W4,:0,l1
" Restore position inside previously opened file. From vim.wikia.
function! ResCur()
if line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
autocmd BufWinEnter * call ResCur()
augroup END
" Set colorscheme and other quality of life stuff
set t_Co=256
colorscheme mopkai
set mouse=
set completeopt=longest,menuone
set number relativenumber
set colorcolumn=80
" highlight as the search phrase is entered
set incsearch
" Keep the current line 10 lines from top/bottom
set scrolloff=10
" Aid to help with hex editing
command! -bar Hex call ToggleHex()
function! ToggleHex()
if !exists("b:editHex") || !b:editHex
let b:editHex=1
%!xxd -g1
else
let b:editHex=0
%!xxd -r
endif
endfunction
command! -bar GitBlame execute '!git blame "%" -L ' . line(".") . ',' . line(".")
nnoremap <leader>g :GitBlame<CR>
" Enter key will select a list item, if a list is visible
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
" Enable recursive search
" set path+=**
" Highlight trailing whitespaces
highlight UselessWhitespace ctermbg=darkred
match UselessWhitespace /\s\+$/
autocmd ColorScheme * highlight UselessWhitespace ctermbg=darkred
set bs=2
" Get color of a group
function! GetHighlightColor(group, what)
let l:highlight = execute('hi ' . a:group)
for item in split(l:highlight, '\s\+')
if match(item, a:what . '=') != -1
return split(item, '=')[1]
endif
endfor
return ''
endfunction
" Set highlight color to group for 'what' parameter
function! SetColor(group, color, what)
if (a:color != '')
exec 'hi ' . a:group . ' ' . a:what . '=' . a:color
echo a:what . '=' . a:color . ' set for color group ' . a:group
endif
endfunction
" Restore colors to their initial values - called when changing color groups
function! RestoreColors()
let l:highlightGroup = s:highlightGroups[s:highlightIdx]
call SetColor(l:highlightGroup, s:groupColorBG, 'ctermbg')
call SetColor(l:highlightGroup, s:groupColorFG, 'ctermfg')
endfunction
" Initialize highlightGroups array if not yet defined
if !exists('s:highlightGroups')
let highlights = execute('highlight')
let hlGroups = substitute(highlights, '\s\+[^\n]*', '', 'g')
let s:highlightGroups = split(hlGroups)
endif
" Initialize current cycle color if not defined
if !exists('s:crtcol')
let s:crtcol = 0
endif
" Initialize index of color in highlightGroups array
if !exists('s:highlightIdx')
let s:highlightIdx = 0
let highlightGroup = s:highlightGroups[s:highlightIdx]
let s:groupColorBG = GetHighlightColor(highlightGroup, 'ctermbg')
let s:groupColorFG = GetHighlightColor(highlightGroup, 'ctermfg')
endif
" Highlight background of 'highlightIdx'th group using the next color relative
" to 'crtcol'
function! TryNextColor()
if (s:crtcol < 255)
let s:crtcol = s:crtcol + 1
endif
call SetColor(s:highlightGroups[s:highlightIdx], s:crtcol, 'ctermbg')
endfunction
" Highlight background of 'highlightIdx'th group using the previous color
" relative to 'crtcol'
function! TryPrevColor()
if (s:crtcol > 0)
let s:crtcol = s:crtcol - 1
endif
call SetColor(s:highlightGroups[s:highlightIdx], s:crtcol, 'ctermbg')
endfunction
" Select next color group relative to 'highlightIdx'. Reset colors for
" previously selected group first, set color to 0 for the new group
function! TryNextColorGroup()
" Restore colors for current group
call RestoreColors()
if (s:highlightIdx < len(s:highlightGroups) - 1)
let s:highlightIdx = s:highlightIdx + 1
endif
" Save colors for next group
let l:highlightGroup = s:highlightGroups[s:highlightIdx]
let s:groupColorBG = GetHighlightColor(l:highlightGroup, 'ctermbg')
let s:groupColorFG = GetHighlightColor(l:highlightGroup, 'ctermfg')
let s:crtcol = 0
call SetColor(s:highlightGroups[s:highlightIdx], s:crtcol, 'ctermbg')
echo 'Current color group: ' . l:highlightGroup
endfunc
" Select previous color group relative to 'highlightIdx'. Reset colors for
" previously selected group first, set color to 0 for the new group
function! TryPrevColorGroup()
" Restore colors for current group
call RestoreColors()
if (s:highlightIdx > 0)
let s:highlightIdx = s:highlightIdx - 1
endif
" Save colors for next group
let l:highlightGroup = s:highlightGroups[s:highlightIdx]
let s:groupColorBG = GetHighlightColor(l:highlightGroup, 'ctermbg')
let s:groupColorFG = GetHighlightColor(l:highlightGroup, 'ctermfg')
let s:crtcol = 0
call SetColor(s:highlightGroups[s:highlightIdx], s:crtcol, 'ctermbg')
echo 'Current color group: ' . l:highlightGroup
endfunc
" Convenience mappings for functions to cycle through colors
nnoremap <silent><F7> :call TryPrevColor()<CR>
nnoremap <silent><F8> :call TryNextColor()<CR>
nnoremap <silent><F5> :call TryPrevColorGroup()<CR>
nnoremap <silent><F6> :call TryNextColorGroup()<CR>