-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path.vimrc
More file actions
575 lines (494 loc) · 17.3 KB
/
.vimrc
File metadata and controls
575 lines (494 loc) · 17.3 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
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
573
574
575
" Init
" {{{
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
" Core
" {{{
Bundle 'kien/ctrlp.vim'
Bundle 'tpope/vim-dispatch.git'
Bundle 'szw/vim-tags.git'
Bundle 'bling/vim-airline'
Bundle 'edkolev/tmuxline.vim'
"" }}}
"" Helpers & Formatters
"" {{{
Bundle 'sjl/gundo.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'ervandew/supertab'
Bundle 'scrooloose/syntastic'
Bundle 'tomtom/tlib_vim'
Bundle 'tpope/vim-commentary'
Bundle 'tpope/vim-endwise'
Bundle 'tpope/vim-fugitive'
Bundle 'MarcWeber/vim-addon-mw-utils'
Bundle 'tpope/vim-surround'
Bundle 'scrooloose/nerdcommenter'
Bundle 'Raimondi/delimitMate'
"" }}}
"" Languages
"" {{{
Bundle 'ap/vim-css-color'
Bundle 'othree/html5.vim'
Bundle 'pangloss/vim-javascript'
Bundle 'mustache/vim-mustache-handlebars'
Bundle 'tpope/vim-rails'
Bundle 'kchmck/vim-coffee-script'
Bundle 'vim-ruby/vim-ruby'
Bundle 'heartsentwined/vim-emblem'
Bundle 'smolnar/vim-ember-script'
Bundle 'tpope/vim-cucumber'
"" }}}
"" Tools
"" {{{
Bundle 'mattn/gist-vim'
Bundle 'mileszs/ack.vim'
Bundle 'tpope/vim-git'
Bundle 'tpope/vim-bundler'
Bundle 'tpope/vim-rake'
Bundle 'Rip-Rip/clang_complete'
Bundle 'thoughtbot/vim-rspec'
Bundle 'garbas/vim-snipmate'
Bundle 'smolnar/vim-snippets.git'
" }}}
" Settings
" {{{
" Basic {{{
filetype plugin indent on
set backspace=indent,eol,start " make backspace a more flexible
let loaded_matchparen=1 " match paranthesis
set backup " create backup
set backupdir=~/.vim/tmp/backup " where to put backup files
set directory=~/.vim/tmp/swap " directory to place swap files in
"set undodir=~/.vim/tmp/undo " directory to place undo files in
"set undofile " create undo file
set mouse=a " use mouse for everything
set equalalways " split windows equally
set splitright splitbelow " new splits right from current and other below
set autoread " supress warnings
set wildmenu " wildmenu when autocomplting option
set wildmode=full " complete the full match, this is default behaviour
set wildignore=*.o,*.obj,*.bak,*.exe,*.pyc,*.jpg,*.gif,*.png " there files will be ignored when completing in wild menu
set clipboard+=unnamed,unnamedplus,autoselect " share clipboard
set history=1000
set tags=.tags;/ " save tags generated for files in current working directory
set ttyfast " i got a fast terminal!
set ttimeoutlen=50 " Make Esc work faster
" }}}
" UI {{{
colorscheme Monokai " Color scheme
set tabstop=4 " when there's tab, it should be indented by 4 spaces
set shiftwidth=2 " Number of spaces to use for each step of (auto)indent
set shiftround " round the indent to shiftwidth (when at 3 spaces, and I hit > go to 4, not 5)
set autoindent
set infercase " case inferred by default, used for autocompletition in insert mode and so on..
set t_Co=256
set ignorecase " ignore case when searching
set hlsearch " highlight search matches
set incsearch " search as you type
set gdefault " global matching is default
set smartcase " use smartcase, when search query starts with Uppercase, turn off case insensitive search
"set list " show trailing characters
"set listchars=tab:▸\ ,trail:¬,extends:❯,precedes:❮,nbsp:~ " it show ¬ character when as you type, fill free to comment out set list
set number " set line numbering
set novisualbell " do not blink
set lazyredraw " get faster, redraw only when it's needed
set nostartofline
set linespace=0
let c_no_trail_space_error = 1 " see c errors
let java_space_errors = 1 " see java errors
set showcmd " show the command being typed
set ruler " always show current position
set scrolloff=5 " Keep 5 lines (top/bottom) for scop
set sidescrolloff=10 " Keep 10 lines at the size
set showmode " show the current mode (Insert, Visual..)
set expandtab " no real tabs!
set wrap " wrap lines, we dont want long lines
set showbreak=↪ " character show when wrapping line
set foldenable " folding text into clusters (+) according to {{{ }}} or comments for example.
set foldmethod=manual " default options, we create fold manually.
set showmatch " when use insert bracket, briefly jump to matching one (i like it, but i might be annoying)
set infercase " case inferred by default
set shiftround " round the indent to shiftwidth (when at 3 spaces, and I hit > go to 4, not 5)
set shiftwidth=2 " auto-indent amount when using >> <<
set softtabstop=2 " when hitting tab or backspace, how many spaces should a tab be (see expandtab)
set tabstop=4 " real tabs should be 4, and they will show with set list on
set completeopt=longest,menu,preview
" }}}
" Advanced macros
" {{{
" Cursor highlight
:hi CursorLine cterm=NONE ctermbg=8
:hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white
:nnoremap <Leader>c :set cursorline! cursorcolumn!<CR>
set cursorline
"improve autocomplete menu color
highlight Pmenu ctermbg=238
" }}}
"
" Removes trailing spaces
function! TrimWhiteSpace()
if !&binary && &filetype != 'diff'
normal mz
normal Hmy
%s/^\s\+$//e
normal 'yz<CR>
normal `z
endif
endfunction
" Filter and trim whitespaces
autocmd FileWritePre * :call TrimWhiteSpace()
autocmd FileAppendPre * :call TrimWhiteSpace()
autocmd FilterWritePre * :call TrimWhiteSpace()
autocmd BufWritePre * :call TrimWhiteSpace()
" Use relative numbering in insert mode
autocmd InsertEnter * :set nonumber relativenumber
autocmd InsertLeave * :set norelativenumber number
"}}}
" Binding
" {{{
" Map leader
let mapleader = ',' " used for lot of stuff, feel free to change it.
" Open all folds
nnoremap <space> :%foldopen<CR>
" convenient window switching
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Emacs-like keybindings
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
inoremap <C-a> <Esc>^i
inoremap <C-e> <Esc>A
" Save like a pro (CTRL+s)
nnoremap <c-s> :w<cr>
" Quit like a pro
nnoremap <C-M-q> :Kwbd<CR>
nnoremap <leader>q :q<CR>
" this key combination gets rid of the search highlights.
nmap <leader><space> :noh<cr>
" open vertical split and switch to it
nnoremap <leader>v <C-w>v<C-w>l
" open horizontal split and switch to it
nnoremap <leader>h :split<CR>
" tabs - moving around, (CTRL+n to new tab)
map <C-t> :tabnew<CR>
map <C-M-n> :tabedit %<CR>
map <M-Right> :tabnext<cr>
map <M-Left> :tabprevious<cr>
" buffers - moving around
map <A-x-Left> :bprevious<CR>
map <A-x-Right> :bNext<CR>
" Write and quit current buffer
nnoremap <C-M-w> :wq<CR>
" run ctags silently
map <leader>t :silent! !ctags -R . &<CR>
" copy from clipboard with ease (<leader>p => paste what you copied by CTRL+c in clipboard)
nnoremap <leader>p "+p
nnoremap <leader>y "+yy
" start ack search, (using ACK tool, like grep but for source code)
nnoremap <leader>a :Ack
" reformat whole file
nnoremap <leader>= ggVG=
" use :w!! to write to a file using sudo if you forgot to 'sudo vim file'
" (it will prompt for sudo password when writing)
cmap w!! %!sudo tee > /dev/null %
" upper/lower word
nmap <leader>u mQviwU`Q
nmap <leader>l mQviwu`Q
" upper/lower first char of word
nmap <leader>wu mQgewvU`Q
nmap <leader>wl mQgewvu`Q
" cd to the directory containing the file in the buffer
nmap <silent> <leader>cd :lcd %:h<CR>
" Create the directory containing the file in the buffer
nmap <silent> <leader>md :!mkdir -p %:p:h<CR>
" Swap two words
nmap <silent> gw :s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<CR>`'
" Map the arrow keys to be based on display lines, not physical lines
map <Down> gj
map <Up> gk
" Toggle hlsearch with <leader>hs
nmap <leader>sh :set hlsearch! hlsearch?<CR>
" }}}
" Filetypes
" {{{
" HTML, XML {{{
augroup FTHtml
au!
autocmd FileType html,xhtml,wml,cf setlocal ai et sta sw=2 sts=2 " set indent size and stuff
autocmd FileType xml,xsd,xslt setlocal ai et sta sw=2 sts=2 ts=2
autocmd FileType html setlocal iskeyword+=~
augroup END
" CSS, SCSS {{{
augroup FTCss
au!
au BufRead,BufNewFile *.scss.erb set ft=scss
autocmd FileType css,scss silent! setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType css,scss setlocal iskeyword+=-
autocmd FileType css,scss setlocal ai et sta sw=2 sts=2
autocmd FileType scss,sass syntax cluster sassCssAttributes add=@cssColors
au FileType css,scss nnoremap <buffer> <leader>S ?{<CR>jV/\v^\s*\}?$<CR>k:sort<CR>:noh<CR>
" Make {<cr> insert a pair of brackets in such a way that the cursor is
" correctly positioned inside of them AND the following code doesn't get unfolded.
au FileType css,scss inoremap <buffer> {<cr> {}<left><cr>.<cr><esc>k==A<bs>
augroup END
" }}}
" }}}
" Ruby {{{
augroup FTRuby
au!
autocmd FileType eruby,yaml,ruby setlocal ai et sta sw=2 sts=2
autocmd BufNewFile,BufRead *.html.erb set filetype=eruby.html " load html snippets along with erb
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global=1
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
" Rspec {{{
autocmd BufRead *_spec.rb syn keyword rubyRspec describe context it specify it_should_behave_like before after setup subject its shared_examples_for shared_context expect let double mock
highlight def link rubyRspec Identifier
augroup END
" }}}
" Coffescript
" {{{
au BufNewFile,BufReadPost *.coffee setl sw=2 expandtab
"}}}
augroup C
au!
""autocmd FileType c,cpp,h,hpp colorscheme molokai
augroup END
" Git {{{
augroup FTGit
au!
autocmd FileType git,gitcommit setlocal foldmethod=syntax foldlevel=1
autocmd FileType gitcommit setlocal spell
augroup END
" }}}
" }}}
" Plugins
" {{{
" Clang
" {{{
let g:clang_use_library=1
let g:clang_library_path="/usr/lib/"
let g:clang_periodic_quickfix=1 " update quickfix periodically
" }}}
" Html5 plugin
" {{{
let g:html5_event_handler_attributes_complete = 0
let g:html5_rdfa_attributes_complete = 0
let g:html5_microdata_attributes_complete = 0
let g:html5_aria_attributes_complete = 0
" }}}
" vim-javascript
" {{{
let g:html_indent_inctags = "html,body,head,tbody"
let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"
" }}}
" vim-airline
" {{{
set laststatus=2
let g:airline_symbols = {}
let g:airline_powerline_fonts = 1
let g:airline_theme = 'powerlineish'
let g:airline_powerline_fonts=1
let g:airline_left_sep = '⮀'
let g:airline_left_alt_sep = '⮁'
let g:airline_right_sep = '⮂'
let g:airline_right_alt_sep = '⮃'
let g:airline_symbols.branch = '⭠ '
let g:airline_symbols.readonly = '⭤'
let g:airline_symbols.linenr = '⭡'
" }}}
" CtrlP
" {{{
set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux
nnoremap <F3> :CtrlP<CR>
nnoremap <F4> :CtrlPBuffer<CR>
nnoremap <F2> :CtrlPDir<CR>
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn)$',
\ 'file': '\v\.(exe|so|dll|png|jpg)$'
\ }
map <leader>f :CtrlP<cr>
map <leader>b :CtrlPMRU<cr>
map <leader>cv :CtrlP app/views<cr>
map <leader>cc :CtrlP app/controllers<cr>
map <leader>cm :CtrlP app/models<cr>
" }}}
" Gist
" {{{
let g:gist_clip_command = 'xclip -selection clipboard'
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
let g:gist_browser_command = 'google-chrome %URL% &' " NOTE: use your browser!
let g:gist_show_privates = 1
" }}}
" Supertab {{{
let g:SuperTabDefaultCompletionType = 'context'
let g:SuperTabContextDefaultCompletionType = '<c-n>'
" }}}
" Syntastic {{{
nnoremap <C-E> :SyntasticCheck<CR>
let g:syntastic_auto_loc_list=1
let g:syntastic_enable_signs=1
let g:synastic_quiet_warnings=1
" }}}
" Rubycomplete {{{
let g:rubycomplete_rails=1
let g:rubycomplete_classes_in_global=1
let g:rubycomplete_buffer_loading=1
let g:rubycomplete_include_object=1
let g:rubycomplete_include_objectspace=1
" }}}
" Gundo {{{
nnoremap <leader>gu :GundoToggle<CR>
" }}}
" Fugitive {{{
nnoremap <leader>gs :Gstatus<cr>
nnoremap <leader>gc :Gcommit
nnoremap <leader>gd :Gdiff<cr>
" }}}
" NERDTree {{{
nnoremap <F1> :NERDTreeToggle<CR>
let g:NERDTreeMinimalUI=1
let g:NERDTreeDirArrows=1
let g:NERTreeHighlightCursorLine=1
"}}}
"
" NerdTree Tabs {{{
nnoremap <c-F1> :NERDTreeTabsToggle<CR>
let g:nerdtree_tabs_open_on_gui_startup=0
" }}}
" Rails
" {{{
nnoremap <C-p> :completefunc()<CR>
nnoremap <F6> :Rails
nnoremap <F7> :Rgenerate
nnoremap <F8> :Rake
nnoremap <F9> :Einitializer
nnoremap <F10> :Emodel
nnoremap <F11> :Eview
nnoremap <F12> :Econtroller
nnoremap <leader>ra :Rails
nnoremap <leader>rg :Rgenerate
nnoremap <leader>rr :Rake
nnoremap <leader>ri :Einitializer
" routes leads to empty initializer path
nnoremap <leader>ro :Einitializer<CR>
nnoremap <leader>rv :Eview
nnoremap <leader>rc :Econtroller
nnoremap <leader>rm :Emodel
" }}}
" }}}
" GUI setting
" {{{
if has('gui_running')
set guifont=Dejavu\ Sans\ Mono\ 9
set guioptions-=m "remove menu bar
set guioptions-=T "remove toolbar
set guioptions-=r "remove right-hand scroll bar
set guioptions-=l
set guioptions-=h
set guioptions-=b
set guioptions-=R
set guioptions-=L
set showtabline=2 " show tabs in gvim, not vim
set guitablabel=%t " show simple filname as tabname
" Bindings
" {{{
nnoremap <c-o> :browse tabnew :pwd<CR>
nnoremap <C-M-s> :browse saveas :pwd<CR>
nnoremap <C-M-f> :set guifont=*<CR>
" Map Alt-# to switch tabs
map <M-0> 0gt
imap <M-0> <Esc>0gt
map <M-1> 1gt
imap <M-1> <Esc>1gt
map <M-2> 2gt
imap <M-2> <Esc>2gt
map <M-3> 3gt
imap <M-3> <Esc>3gt
map <M-4> 4gt
imap <M-4> <Esc>4gt
map <M-5> 5gt
imap <M-5> <Esc>5gt
map <M-6> 6gt
imap <M-6> <Esc>6gt
map <M-7> 7gt
imap <M-7> <Esc>7gt
map <M-8> 8gt
imap <M-8> <Esc>8gt
map <M-9> 9gt
imap <M-9> <Esc>9gt
" }}}
" }}}
endif
" }}}
" }}}
" Misc
" {{{
"here is a more exotic version of my original Kwbd script
"delete the buffer; keep windows; create a scratch buffer if no buffers left
function s:Kwbd(kwbdStage)
if(a:kwbdStage == 1)
if(!buflisted(winbufnr(0)))
bd!
return
endif
let s:kwbdBufNum = bufnr("%")
let s:kwbdWinNum = winnr()
windo call s:Kwbd(2)
execute s:kwbdWinNum . 'wincmd w'
let s:buflistedLeft = 0
let s:bufFinalJump = 0
let l:nBufs = bufnr("$")
let l:i = 1
while(l:i <= l:nBufs)
if(l:i != s:kwbdBufNum)
if(buflisted(l:i))
let s:buflistedLeft = s:buflistedLeft + 1
else
if(bufexists(l:i) && !strlen(bufname(l:i)) && !s:bufFinalJump)
let s:bufFinalJump = l:i
endif
endif
endif
let l:i = l:i + 1
endwhile
if(!s:buflistedLeft)
if(s:bufFinalJump)
windo if(buflisted(winbufnr(0))) | execute "b! " . s:bufFinalJump | endif
else
enew
let l:newBuf = bufnr("%")
windo if(buflisted(winbufnr(0))) | execute "b! " . l:newBuf | endif
endif
execute s:kwbdWinNum . 'wincmd w'
endif
if(buflisted(s:kwbdBufNum) || s:kwbdBufNum == bufnr("%"))
execute "bd! " . s:kwbdBufNum
endif
if(!s:buflistedLeft)
set buflisted
set bufhidden=delete
set buftype=
setlocal noswapfile
endif
else
if(bufnr("%") == s:kwbdBufNum)
let prevbufvar = bufnr("#")
if(prevbufvar > 0 && buflisted(prevbufvar) && prevbufvar != s:kwbdBufNum)
b #
else
bn
endif
endif
endif
endfunction
command! Kwbd call s:Kwbd(1)
nnoremap <silent> <Plug>Kwbd :<C-u>Kwbd<CR>
" }}}