-
Notifications
You must be signed in to change notification settings - Fork 10
/
vimrc
554 lines (473 loc) · 15.5 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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/vundle'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'kien/ctrlp.vim'
Plugin 'vim-perl/vim-perl'
Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/syntastic'
Plugin 'vim-scripts/matchit.zip'
Plugin 'mattn/gist-vim'
Plugin 'mattn/webapi-vim'
Plugin 'marcweber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
Plugin 'honza/vim-snippets'
Plugin 'bling/vim-airline'
Plugin 'airblade/vim-gitgutter'
"Plugin 'nathanaelkane/vim-indent-guides'
Plugin 'altercation/vim-colors-solarized'
Plugin 'Lokaltog/vim-distinguished'
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'cakebaker/scss-syntax.vim'
Plugin 'groenewege/vim-less'
Plugin 'michalliu/sourcebeautify.vim'
" ctags
set tags=./tags,./../tags,./../../tags,./../../../tags,tags
nmap ,ct :!(cd %:p:h;ctags *)&
" vim-jsx
let g:javascript_conceal=1
" slimv options
let g:slimv_keybindings=1
let g:lisp_rainbow=1
let g:slimv_leader=',s'
" Gist options - put code in clipboard
let g:gist_clip_command = 'pbcopy'
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
" Use our user unless we have a sudo user, then is it
let luser = substitute(system('whoami'), '\n', '', '')
if strlen($SUDO_USER)
let luser = $SUDO_USER
endif
let g:syntastic_enable_perl_checker = 1
" turn on indent-guides
"nautocmd VimEnter * IndentGuidesEnable
"let g:indent_guides_guide_size=1
set number
set nocompatible
"set wildignore+=*CVS
" snipmate
filetype on
filetype plugin on
filetype indent on
" folding
"let perl_fold=1
"let perl_extended_vars = 1
set laststatus=2
" backspaces over everything in insert mode
set backspace=indent,eol,start
" Indent
set autoindent
set tabstop=2
set shiftwidth=2
set smartindent
set expandtab
syntax on
set textwidth=79
set formatoptions=qrn1
"if version >= 703
if exists('+colorcolumn')
set colorcolumn=80
endif
" folding
set foldmethod=indent
" mojo
let mojo_highlight_data = 1
" Sidebar folder navigation
let NERDTreeShowLineNumbers=1
let NERDTreeShowBookmarks=1
let NERDTreeChDirMode=2
let NERDTreeWinSize=35
"let NERDTreeIgnore=['CVS']
set incsearch
set ignorecase
set smartcase
set visualbell
set noerrorbells
set hlsearch
set history=500
" scrolling
"set ruler
set scrolloff=20 " Scroll with 10 line buffer
" clear recent search highlighting with space
:nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
" save files as root without prior sudo
cmap w!! w !sudo tee % >/dev/null
set nobackup
set noswapfile
"" git branch
"set statusline=%f\ " tail of the filename
""set statusline=
"set statusline+=%{fugitive#statusline()}
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
"
"set statusline+=%= "left/right separator
"set statusline+=%{StatuslineCurrentHighlight()}\ "current highlight
"set statusline+=%c, "cursor column
"set statusline+=%l/%L "cursor line/total lines
"set statusline+=\ %P\ "percent through file
"set laststatus=2 " Always show status line
"
"" warning for mixed indenting
"set statusline+=%#error#
"set statusline+=%{StatuslineMixedIndentingWarning()}
"set statusline+=%*
"
"set statusline+=%h "help file flag
"set statusline+=%y "filetype
"set statusline+=%r "read only flag
"set statusline+=%m "modified flag
set list
set listchars=tab:.\ ,trail:.,extends:#,nbsp:.
colorscheme jellybeans
" font
if has("gui_gnome")
set guifont=Monospace\ 8
set list
set listchars=tab:▸\ ,eol:¬,extends:#,nbsp:.,trail:.
elseif has("gui_macvim")
"set guifont=Menlo:h12
"set guifont=Monaco:h12
"set guifont=Monaco\ for\ Powerline:h12
"let g:Powerline_symbols = 'fancy'
set list
set listchars=tab:▸\ ,eol:¬,extends:#,nbsp:.,trail:.
endif
"if &t_Co >= 256 || has("gui_running")
if has("gui_running")
"set guifont=Monaco:h11
"set guifont=Consolas:h12
"set guifont=Inconsolata:h13
set guifont=Source\ Code\ Pro\ Light:h11
"set guifont=Helvetica\ Neue\ Light:h11
colorscheme tempire
set guioptions-=r
set go-=L
set go-=T
else
colorscheme jellybeans
endif
" line tracking
set numberwidth=5
set cursorline
set cursorcolumn
" turn off cursor blinking
set guicursor+=a:blinkon0
function! StatuslineCurrentHighlight()
let name = synIDattr(synID(line('.'),col('.'),1),'name')
if name == ''
return ''
else
return '[' . name . ']'
endif
endfunction
" shortcuts
inoremap jj <Esc>
nnoremap ; :
let mapleader = ','
nnoremap <Leader>a :Ack
noremap <Leader>, :NERDTreeToggle<cr>
map <Leader>t :tabnew<cr>
map <Leader>h :tabprevious<cr>
map <Leader>l :tabnext<cr>
map <Leader>w :tabclose<cr>
map <Leader>pd :!perldoc %<cr>
"map <Leader>cs :colorscheme sri<cr>
map <Leader>f :TlistToggle<cr>
map <Leader>M :!morbo %<cr>
map <Leader>x :!perl -Ilib %<cr>
map <leader>H :call HexHighlight()<cr>
map <leader>tts :%s/\s\+$//<cr>
map <leader>term :ConqueTerm bash<cr>
map <leader>b :TagbarToggle<cr>
map <leader>sp :setlocal spell! spelllang=en_us<CR> " toggle spellcheck
"
" cd to directory of current file
map <leader>cd :cd %:p:h<cr>
map <leader>F :NERDTreeFind<cr>
map <leader>R :source ~/.vimrc<cr>
map <leader>pull :silent !sandbox pull %<cr>
map <leader>push :silent !sandbox push %<cr>
map <leader>same :!sandbox same %<cr>
map <leader>rt :!sandbox rtest %<cr>
map <leader>diff :!sandbox diff %<cr>
nnoremap <F5> :GundoToggle<cr>
" http://vim.wikia.com/wiki/Redirect_g_search_output
nmap <leader>s :redir @a<cr>:g//<cr>:redir END<cr>:new<cr>:put! a<cr><cr>zRggd<cr>
" Move single lines up-down
nmap <c-up> ddkP
nmap <c-down> ddp
"nmap <c-up [e
"nmap <c-down> ]e
" Resize vertical windows
nmap + <c-w>+
nmap _ <c-w>-
" Resize horizontal windows
nmap > <c-w>>
nmap < <c-w><
" Move multiple lines up-down
vmap <c-up> xkP`[V`]
vmap <c-down> xp`[V`]
"vmap <c-up> [egv
"vmap <c-down> ]egv
"Insert on empty line, with lines above and below (for mojocasts)
nmap oo o<Esc>O
" autocompletion
imap <Leader><Tab> <C-X><C-O>
" Autocomplpop perl autocompletion
"let g:acp_behaviorPerlOmniLength = 4
"let g:acp_completeoptPreview = 0
" local set in perlomni.vim plugin does not work as expected..set globally
"set omnifunc=PerlComplete
" perldoc for module || perl command
noremap K :!perldoc <cword> <bar><bar> perldoc -f <cword><cr>
" Opens nerdtree and puts focus in edited file
"autocmd VimEnter * NERDTree
"autocmd VimEnter * wincmd p
" file types
au BufRead,BufNewFile *.asd,*.lisp set filetype=lisp
au BufRead,BufNewFile *.t,*.cgi set filetype=perl
au BufRead,BufNewFile *.conf set filetype=apache
au BufRead,BufNewFile *.app set filetype=erlang
" haskell support (vim2hs)
let g:haskell_conceal_wide = 1
let g:neocomplcache_enable_at_startup = 1
let g:acp_enableAtStartup = 0
let g:neocomplcache_enable_smart_case = 1
let g:neocomplcache_enable_camel_case_completion = 1
let g:neocomplcache_enable_underbar_completion = 1
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
"au FileType haskell nmap <Leader>gt :GhcModType<cr>
"au FileType haskell nmap <Leader>gc :GhcModTypeClear<cr>
au FileType haskell nmap gt :GhcModType<cr>
au FileType haskell nmap gc :GhcModTypeClear<cr>
"autocmd BufWritePost *.hs call s:check_and_lint()
"autocmd BufWritePost *.hs GhcModCheckAsync
"let &l:statusline = '%{empty(getqflist()) ? "[No Errors]" : "[Errors Found]"}' . (empty(&l:statusline) ? &statusline : &l:statusline)
" markdown support - turn-on distraction free writing mode for markdown files
"au BufNewFile,BufRead *.{md,mdown,mkd,mkdn,markdown,mdwn} call DistractionFreeWriting()
au BufNewFile,BufRead *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=markdown
" compile erlang files
autocmd BufRead,BufNewFile *.erl nmap <Leader>C :!erlc %<cr>
" save/retrieve folds automatically
au BufWinLeave * silent! mkview
au BufWinEnter * silent! loadview
" ,T perl tests
"nmap <Leader>T :let g:testfile = expand("%")<cr>:echo "testfile is now" g:testfile<cr>:call Prove (1,1)<cr>
function! Prove ( verbose, taint )
if ! exists("g:testfile")
let g:testfile = "t/*.t"
endif
if g:testfile == "t/*.t" || g:testfile =~ "\.t$"
let s:params = "lrc"
if a:verbose
let s:params = s:params . "v"
endif
" if a:taint
" let s:params = s:params . "t"
" endif
"execute !HARNESS_PERL_SWITCHES=-MDevel::Cover prove -" . s:params . " " . g:testfile
execute "!prove --timer --normalize --state=save -" . s:params . " " . g:testfile
"TEST_VERBOSE=1 prove -lvc --timer --normalize --state=save
else
call Compile ()
endif
endfunction
function! Compile ()
if ! exists("g:compilefile")
let g:compilefile = expand("%")
endif
execute "!perl -wc -Ilib " . g:compilefile
endfunction
autocmd BufRead,BufNewFile *.t,*.pl,*.plx,*.pm nmap <Leader>te :let g:testfile = expand("%")<cr>:echo "testfile is now" g:testfile<cr>:call Prove (1,1)<cr>
" markdown
"augroup mkd
"autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:>
"augroup END
" open installed perl modules
au FileType perl command! -nargs=1 PerlModuleSource :tabnew `perldoc -lm <args>`
au FileType perl setlocal iskeyword+=:
au FileType perl nmap <leader>P :PerlModuleSource <cword><cr>zR<cr>
" perltidy
au FileType perl command! -range=% -nargs=* Tidy <line1>,<line2>!perltidy
au FileType perl nmap <Leader>pt mz:Tidy<cr>'z:delmarks z<cr> " normal mode
au FileType perl vmap <Leader>pt :Tidy<cr> " visual mode
" js, css, & html tidy config (vim-jsbeautify)
let g:jsbeautify = {'indent_size': 2, 'indent_char': ' ', 'max_char': 5}
let g:htmlbeautify = {'indent_size': 2, 'indent_char': ' ', 'max_char': 80, 'brace_style': 'expand', 'unformatted': ['a', 'sub', 'sup', 'b', 'i', 'u']}
let g:csseautify = {'indent_size': 2, 'indent_char': ' ', 'max_char': 80, 'brace_style': 'expand'}
" js
"au FileType javascript command! -range=% -nargs=* Tidy <line1>,<line2> :call JsBeautify()
"au FileType javascript nmap <Leader>pt mz:Tidy<cr>'z:delmarks z<cr> " normal mode
"au FileType javascript vmap <Leader>pt :Tidy<cr> " visual mode
au FileType javascript nmap <buffer> <leader>pt :call JsBeautify()<cr>
au FileType html nmap <buffer> <leader>pt :call HtmlBeautify()<cr>
au FileType css nmap <buffer> <leader>pt :call CSSBeautify()<cr>
" csstidy
"au FileType css command! -range=% -nargs=* Tidy <line1>,<line2>!csstidy
"au FileType css nmap <Leader>pt mz:Tidy<cr>'z:delmarks z<cr> " normal mode
"au FileType css vmap <Leader>pt :Tidy<cr> " visual mode
" json tidy
"au FileType json set filetype=javascript foldmethod=syntax
"au FileType json command! -range=% -nargs=* Tidy <line1>,<line2>!json_xs -f json -t json-pretty
"au FileType json nmap <Leader>pt :Tidy<cr> " normal mode
"au FileType json vmap <Leader>pt :Tidy<cr> " visual mode
" xmlfolding
"au BufNewFile,BufRead *.xml,*.htm,*.html so bundle/plugin/XMLFolding.vim
" ack shortcut
let g:ackprg="ack-grep -H --nocolor --nogroup --column"
" Show syntax highlighting groups for word under cursor
"nmap <C-S-P> :call <SID>SynStack()<CR>
"function! <SID>SynStack()
"if !exists("*synstack")
"return
"endif
"echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
"endfunc
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
" Automatic tabularize with pipes |
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
function! StatuslineMixedIndentingWarning()
if !exists("b:statusline_tab_warning")
let tabs = search('^\t', 'nw') != 0
let spaces = search('^ ', 'nw') != 0
if tabs && spaces
let b:statusline_tab_warning = '[mixed-indenting]'
elseif (spaces && !&et) || (tabs && &et)
let b:statusline_tab_warning = '[&et]'
else
let b:statusline_tab_warning = ''
endif
endif
return b:statusline_tab_warning
endfunction
" return the syntax highlight group under the cursor ''
function! StatuslineCurrentHighlight()
let name = synIDattr(synID(line('.'),col('.'),1),'name')
if name == ''
return ''
else
return '[' . name . ']'
endif
endfunction
function! ScreencastPrep()
" disable blinking cursor
set guicursor+=n:hor10-blinkon0
" disable autocomplete
AcpDisable
" disable colorcolumn
set colorcolumn=0
"set guifont=Menlo:h14
set guifont=Monaco:h14
set ts=2
set sw=2
NoMatchParen "opposite: DoMatchParen
endfunction
function! ScreencastPrep1080()
" disable blinking cursor
set guicursor+=n:hor10-blinkon0
" disable autocomplete
AcpDisable
" disable colorcolumn
set colorcolumn=0
"set guifont=Menlo:h20
"set guifont=Monaco:h26
set guifont=Consolas:h29
set ts=2
set sw=2
NoMatchParen "opposite: DoMatchParen
endfunction
function! s:check_and_lint()
let l:qflist = ghcmod#make('check')
call extend(l:qflist, ghcmod#make('lint'))
call setqflist(l:qflist)
cwindow
if empty(l:qflist)
echo "No errors found"
endif
endfunction
function! DoPrettyXML()
" save the filetype so we can restore it later
let l:origft = &ft
set ft=
" delete the xml header if it exists. This will
" permit us to surround the document with fake tags
" without creating invalid xml.
1s/<?xml .*?>//e
" insert fake tags around the entire document.
" This will permit us to pretty-format excerpts of
" XML that may contain multiple top-level elements.
0put ='<PrettyXML>'
$put ='</PrettyXML>'
silent %!xmllint --format -
" xmllint will insert an <?xml?> header. it's easy enough to delete
" if you don't want it.
" delete the fake tags
2d
$d
" restore the 'normal' indentation, which is one extra level
" too deep due to the extra tags we wrapped around the document.
silent %<
" back to home
1
" restore the filetype
exe "set ft=" . l:origft
endfunction
"command! PrettyXML call DoPrettyXML()
"function! DistractionFreeWriting()
"colorscheme iawriter
"set background=light
"set gfn=Cousine:h14 " font to use
"set lines=40 columns=120 " size of the editable area
"set listchars=tab:▸\ ,extends:#,nbsp:.,trail:.
"set guioptions-=r " remove right scrollbar
"set laststatus=0 " don't show status line
"set noruler " don't show ruler
"set linebreak " break the lines on words
"set nocursorline
"set nocursorcolumn
"set nonumber
"set cc=
"if has("gui_macvim")
"set fuoptions=background:#00f5f6f6 " macvim specific setting for editor's background color
"set fullscreen " go to fullscreen editing mode
"endif
"endfunction
"function! ToggleIndentGuidesSpaces()
"if exists('b:iguides_spaces')
"call matchdelete(b:iguides_spaces)
"unlet b:iguides_spaces
"else
"let pos = range(1, &l:textwidth, &l:shiftwidth)
"call map(pos, '"\\%" . v:val . "v"')
"let pat = '\%(\_^\s*\)\@<=\%(' . join(pos, '\|') . '\)\s'
"let b:iguides_spaces = matchadd('CursorLine', pat)
"endif
"endfunction
"function! ToggleIndentGuidesTabs()
"if exists('b:iguides_tabs')
"setlocal nolist
"let &l:listchars = b:iguides_tabs
"unlet b:iguides_tabs
"else
"let b:iguides_tabs = &l:listchars
"setlocal listchars=tab:┆\ "protect the space
"setlocal list
"endif
"endfunction