-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
572 lines (470 loc) · 16.7 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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-scriptease'
Plug 'rhysd/vim-go-impl'
Plug 'moll/vim-bbye'
Plug 'rking/ag.vim'
Plug 'mhinz/vim-sayonara'
Plug 'itchyny/lightline.vim'
Plug 'shougo/neocomplete.vim'
"Plug 'Valloric/YouCompleteMe', { 'do': './install.sh' }
Plug 'git://git.wincent.com/command-t.git'
Plug 'fatih/vim-go'
Plug 'fatih/vim-nginx' , {'for' : 'nginx'}
Plug 'fatih/molokai'
Plug 'garyburd/go-explorer'
Plug 'morhetz/gruvbox'
Plug 'w0ng/vim-hybrid'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'SirVer/ultisnips'
Plug 'kchmck/vim-coffee-script', {'for' : 'coffee'}
Plug 'tomtom/tcomment_vim'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'ekalinin/Dockerfile.vim', {'for' : 'Dockerfile'}
Plug 'JazzCore/ctrlp-cmatcher', {'do': './install.sh'}
Plug 'cespare/vim-toml', {'for' : 'toml'}
Plug 'elzr/vim-json', {'for' : 'json'}
Plug 'corylanou/vim-present', {'for' : 'present'}
Plug 'Raimondi/delimitMate'
Plug 'wlangstroth/vim-racket'
Plug 'christoomey/vim-tmux-navigator'
Plug 'bling/vim-airline'
call plug#end()
set nocompatible " be iMproved, required
filetype off " required
filetype plugin indent on " required
"
" Settings
"
set noerrorbells " No beeps
set number " Show line numbers
set backspace=indent,eol,start " Makes backspace key moreowerful.
set showcmd " Show me what I'm typing
set showmode " Show current mode.
set noswapfile " Don't use swapfile
set nobackup " Don't create annoying backup files
set splitright " Split vertical windows right to the current windows
set splitbelow " Split horizontal windows below to the current windows
set encoding=utf-8 " Set default encoding to UTF-8
set autowrite " Automatically save before :next, :make etc.
set autoread " Automatically reread changed files without asking me anything
set laststatus=2
set hidden
set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
"http://stackoverflow.com/questions/20186975/vim-mac-how-to-copy-to-clipboard-without-pbcopy
set clipboard^=unnamed
set clipboard^=unnamedplus
set noshowmatch " Do not show matching brackets by flickering
set nocursorcolumn
set noshowmode " We show the mode with airlien or lightline
set incsearch " Shows the match while typing
set hlsearch " Highlight found searches
set ignorecase " Search case insensitive...
set smartcase " ... but not when search pattern contains upper case characters
set ttyfast
set ttymouse=xterm2
set ttyscroll=3
set lazyredraw " Wait to redraw "
" speed up syntax highlighting
set nocursorcolumn
set nocursorline
syntax sync minlines=256
set synmaxcol=300
set re=1
"set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
let g:neocomplete#enable_at_startup = 1
" open help vertically
command! -nargs=* -complete=help Help vertical belowright help <args>
autocmd FileType help wincmd L
if has("gui_macvim")
" No toolbars, menu or scrollbars in the GUI
set guifont=Source\ Code\ Pro\ Light:h12
set clipboard+=unnamed
set vb t_vb=
set guioptions-=m "no menu
set guioptions-=T "no toolbar
set guioptions-=l
set guioptions-=L
set guioptions-=r "no scrollbar
set guioptions-=R
let macvim_skip_colorscheme=1
let g:molokai_original=1
let g:rehash256 = 1
colorscheme molokai
highlight SignColumn guibg=#272822
"
"
" set background=dark
" colorscheme gruvbox
" let g:gruvbox_contrast_dark = "hard"
" Open ctrlp with cmd+p
" let g:ctrlp_map = '<D-p>'
" Open goto symbol on current buffer
nmap <D-r> :MyCtrlPTag<cr>
imap <D-r> <esc>:MyCtrlPTag<cr>
" Open goto symbol on all buffers
nmap <D-R> :CtrlPBufTagAll<cr>
imap <D-R> <esc>:CtrlPBufTagAll<cr>
" Open goto file
nmap <D-t> :CtrlP<cr>
imap <D-t> <esc>:CtrlP<cr>
" Comment lines with cmd+/
map <D-/> :TComment<cr>
vmap <D-/> :TComment<cr>gv
" Indent lines with cmd+[ and cmd+]
nmap <D-]> >>
nmap <D-[> <<
vmap <D-[> <gv
vmap <D-]> >gv
" This mapping makes Ctrl-Tab switch between tabs.
" Ctrl-Shift-Tab goes the other way.
noremap <C-Tab> :tabnext<CR>
noremap <C-S-Tab> :tabprev<CR>
" switch between tabs with cmd+1, cmd+2,..."
map <D-1> 1gt
map <D-2> 2gt
map <D-3> 3gt
map <D-4> 4gt
map <D-5> 5gt
map <D-6> 6gt
map <D-7> 7gt
map <D-8> 8gt
map <D-9> 9gt
" until we have default MacVim shortcuts this is the only way to use it in
" insert mode
imap <D-1> <esc>1gt
imap <D-2> <esc>2gt
imap <D-3> <esc>3gt
imap <D-4> <esc>4gt
imap <D-5> <esc>5gt
imap <D-6> <esc>6gt
imap <D-7> <esc>7gt
imap <D-8> <esc>8gt
imap <D-9> <esc>9gt
else
"syntax enable
"let g:molokai_original=1
"colorscheme molokai
"highlight SignColumn guibg=#272822
"set t_Co=256
syntax enable
set t_Co=256
set background=dark
colorscheme gruvbox
let g:gruvbox_contrast_dark = "hard"
"syntax enable
""colorscheme jellybeans
"set background=dark
"colorscheme solarized
endif
" This comes first, because we have mappings that depend on leader
" With a map leader it's possible to do extra key combinations
" i.e: <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
" This trigger takes advantage of the fact that the quickfix window can be
" easily distinguished by its file-type, qf. The wincmd J command is
" equivalent to the Ctrl+W, Shift+J shortcut telling Vim to move a window to
" the very bottom (see :help :wincmd and :help ^WJ).
autocmd FileType qf wincmd J
"Dont show me any output when I build something
"Because I am using quickfix for errors
nmap <leader>m :make<CR><enter>
" Some useful quickfix shortcuts
":cc see the current error
":cn next error
":cp previous error
":clist list all errors
map <C-n> :cn<CR>
map <C-m> :cp<CR>
nnoremap <silent> <leader>q :Sayonara<CR>
" function! CloseSplitOrDeleteBuffer()
" let totalBufNr = len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
" let totalWinNr = winnr('$')
"
" " there is only one buffer and one window, close VIM
" if totalBufNr == 1 && totalWinNr == 1
" quit
" endif
"
" let curNr = winnr()
" let curBuf = bufnr('%')
"
" "try to move on next split
" wincmd w
" if winnr() == curNr
" " there is no split, delete the buffer only
" exe 'bdelete!'
" elseif curBuf != bufnr('%')
" "there is split with another buffer, move back and delete it
" wincmd W
" exe 'bdelete!'
" else
" "there is split with same buffer, just close the split
" wincmd W
" close!
" endif
" endfunction
" Replace the current buffer with the given new file. That means a new file
" will be open in a buffer while the old one will be deleted
com! -nargs=1 -complete=file Breplace edit <args>| bdelete #
function! DeleteInactiveBufs()
"From tabpagebuflist() help, get a list of all buffers in all tabs
let tablist = []
for i in range(tabpagenr('$'))
call extend(tablist, tabpagebuflist(i + 1))
endfor
"Below originally inspired by Hara Krishna Dara and Keith Roberts
"http://tech.groups.yahoo.com/group/vim/message/56425
let nWipeouts = 0
for i in range(1, bufnr('$'))
if bufexists(i) && !getbufvar(i,"&mod") && index(tablist, i) == -1
"bufno exists AND isn't modified AND isn't in the list of buffers open in windows and tabs
silent exec 'bwipeout' i
let nWipeouts = nWipeouts + 1
endif
endfor
echomsg nWipeouts . ' buffer(s) wiped out'
endfunction
command! Ball :call DeleteInactiveBufs()
" Close quickfix easily
nnoremap <leader>a :cclose<CR>
" Remove search highlight
nnoremap <leader><space> :nohlsearch<CR>
" Better split switching
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Fast saving
nmap <leader>w :w!<cr>
" Center the screen
nnoremap <space> zz
" Move up and down on splitted lines (on small width screens)
map <Up> gk
map <Down> gj
map k gk
map j gj
" Just go out in insert mode
imap jk <ESC>l
nnoremap <F6> :setlocal spell! spell?<CR>
" Select search pattern howewever do not jump to the next one
nnoremap <leader>c :TComment<CR>
" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
nnoremap n nzzzv
nnoremap N Nzzzv
"nnoremap <leader>. :lcd %:p:h<CR>
autocmd BufEnter * silent! lcd %:p:h
" trim all whitespaces away
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Act like D and C
nnoremap Y y$
" Do not show stupid q: window
map q: :q
" sometimes this happens and I hate it
map :Vs :vs
map :Sp :sp
" ========== Steve Losh hacks ==========="
" Don't move on *
" I'd use a function for this but Vim clobbers the last search when you're in
" a function so fuck it, practicality beats purity.
nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
" iTerm2 is currently slow as balls at rendering the nice unicode lines, so for
" now I'll just use ASCII pipes. They're ugly but at least I won't want to kill
" myself when trying to move around a file.
set fillchars=diff:⣿,vert:│
set fillchars=diff:⣿,vert:\|
" Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
set notimeout
set ttimeout
set ttimeoutlen=10
" Better Completion
set complete=.,w,b,u,t
set completeopt=longest,menuone
" Diffoff
nnoremap <leader>D :diffoff!<cr>
" Resize splits when the window is resized
au VimResized * :wincmd =
" }}}
" Visual Mode */# from Scrooloose {{{
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o>
" ----------------------------------------- "
" File Type settings "
" ----------------------------------------- "
au BufNewFile,BufRead *.vim setlocal noet ts=4 sw=4 sts=4
au BufNewFile,BufRead *.txt setlocal noet ts=4 sw=4
au BufNewFile,BufRead *.md setlocal noet ts=4 sw=4
augroup filetypedetect
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
au BufNewFile,BufRead .nginx.conf*,nginx.conf* setf nginx
augroup END
au FileType nginx setlocal noet ts=4 sw=4 sts=4
" Go settings
au BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4
" coffeescript settings
autocmd BufNewFile,BufReadPost *.coffee setl shiftwidth=2 expandtab
" scala settings
autocmd BufNewFile,BufReadPost *.scala setl shiftwidth=2 expandtab
" lua settings
autocmd BufNewFile,BufRead *.lua setlocal noet ts=4 sw=4 sts=4
" Wildmenu completion {{{
set wildmenu
" set wildmode=list:longest
set wildmode=list:full
set wildignore+=.hg,.git,.svn " Version control
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.DS_Store " OSX bullshit
set wildignore+=*.luac " Lua byte code
set wildignore+=migrations " Django migrations
set wildignore+=go/pkg " Go static files
set wildignore+=go/bin " Go bin files
set wildignore+=go/bin-vagrant " Go bin-vagrant files
set wildignore+=*.pyc " Python byte code
set wildignore+=*.orig " Merge resolution files
" Prettify json
" comes with yajl, install: brew install yajl
" I don't use pythons json tool because it sorts the keys
com! JSONFormat %!json_reformat
" ----------------------------------------- "
" Plugin configs "
" ----------------------------------------- "
" ==================== CtrlP ====================
let g:ctrlp_cmd = 'CtrlPMRU'
let g:ctrlp_match_func = {'match' : 'matcher#cmatch'}
" let g:ctrlp_match_func = {'match': 'cpsm#CtrlPMatch'}
" let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_max_height = 10 " maxiumum height of match window
let g:ctrlp_switch_buffer = 'et' " jump to a file if it's open already
let g:ctrlp_mruf_max=450 " number of recently opened files
let g:ctrlp_max_files=0 " do not limit the number of searchable files
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_cache_dir = $HOME.'/.cache/ctrlp'
let g:ctrlp_buftag_types = {
\ 'go' : '--language-force=go --golang-types=ftv',
\ 'coffee' : '--language-force=coffee --coffee-types=cmfvf',
\ 'markdown' : '--language-force=markdown --markdown-types=hik',
\ 'objc' : '--language-force=objc --objc-types=mpci',
\ 'rc' : '--language-force=rust --rust-types=fTm'
\ }
func! MyCtrlPTag()
let g:ctrlp_prompt_mappings = {
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("t")': ['<c-t>'],
\ }
CtrlPBufTag
endfunc
command! MyCtrlPTag call MyCtrlPTag()
nmap <C-f> :CtrlPCurWD<cr>
imap <C-f> <esc>:CtrlPCurWD<cr>
nmap <C-b> :CtrlPBuffer<cr>
imap <C-b> <esc>:CtrlPBuffer<cr>
" ==================== YouCompleteMe ====================
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_min_num_of_chars_for_completion = 1
" ==================== Fugitive ====================
nnoremap <leader>ga :Git add %:p<CR><CR>
nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gp :Gpush<CR>
vnoremap <leader>gb :Gblame<CR>
" ==================== CommandT ====================
let g:CommandTMaxHeight = 20
let g:CommandTMaxFiles = 500000
let g:CommandTMatchWindowReverse = 1
let g:CommandTMaxCachedDirectories = 0
let g:CommandTHighlightColor = 'Typedef'
nmap <C-t> :CommandT /Users/fatih/Code/koding<cr>
imap <C-t> <esc>:CommandT /Users/fatih/Code/koding<cr>
" ==================== Vim-go ====================
let g:go_fmt_fail_silently = 0
let g:go_fmt_command = "goimports"
let g:go_autodetect_gopath = 1
let g:go_highlight_space_tab_error = 0
let g:go_highlight_array_whitespace_error = 0
let g:go_highlight_trailing_whitespace_error = 0
let g:go_highlight_extra_types = 0
let g:go_highlight_operators = 0
au FileType go nmap <Leader>s <Plug>(go-def-split)
au FileType go nmap <Leader>v <Plug>(go-def-vertical)
au FileType go nmap <Leader>in <Plug>(go-info)
au FileType go nmap <Leader>ii <Plug>(go-implements)
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>g <Plug>(go-gbbuild)
au FileType go nmap <leader>t <Plug>(go-test-compile)
au FileType go nmap <Leader>d <Plug>(go-doc)
au FileType go nmap <Leader>f :GoImports<CR>
au FileType go nmap <Leader>ve <Plug>(go-vet)
au FileType go nmap <Leader>ln :GoLint<CR>
" ==================== delimitMate ====================
let g:delimitMate_expand_cr = 1
let g:delimitMate_expand_space = 1
let g:delimitMate_smart_quotes = 1
let g:delimitMate_expand_inside_quotes = 0
let g:delimitMate_smart_matchpairs = '^\%(\w\|\$\)'
imap <expr> <CR> pumvisible() ? "\<c-y>" : "<Plug>delimitMateCR"
" ==================== Vim-json ====================
let g:vim_json_syntax_conceal = 0
" ==================== UltiSnips ====================
function! g:UltiSnips_Complete()
call UltiSnips#ExpandSnippet()
if g:ulti_expand_res == 0
if pumvisible()
return "\<C-n>"
else
call UltiSnips#JumpForwards()
if g:ulti_jump_forwards_res == 0
return "\<TAB>"
endif
endif
endif
return ""
endfunction
function! g:UltiSnips_Reverse()
call UltiSnips#JumpBackwards()
if g:ulti_jump_backwards_res == 0
return "\<C-P>"
endif
return ""
endfunction
if !exists("g:UltiSnipsJumpForwardTrigger")
let g:UltiSnipsJumpForwardTrigger = "<tab>"
endif
if !exists("g:UltiSnipsJumpBackwardTrigger")
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
endif
au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=g:UltiSnips_Reverse()<cr>"
" ==================== NerdTree ====================
" Open nerdtree in current dir, write our own custom function because
" NerdTreeToggle just sucks and doesn't work for buffers
function! g:NerdTreeFindToggle()
if g:NERDTree.IsOpen()
exec 'NERDTreeClose'
else
exec 'NERDTree'
endif
endfunction
" For toggling
noremap <Leader>n :<C-u>call g:NerdTreeFindToggle()<cr>
let NERDTreeShowBookmarks=1
" vim:ts=2:sw=2:et