-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvimrc
541 lines (439 loc) · 16.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
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
" -----------------------------------------------------------------------------
" | VIM Settings |
" | (see gvimrc for gui vim settings) |
" -----------------------------------------------------------------------------
set nocompatible " We don't want vi compatibility.
let mapleader = ","
let maplocalleader = "\\"
set wildmenu
set wildmode=list:longest,full
set lazyredraw
set autowriteall
set autoread
if has("nvim")
set termguicolors
endif
" Show syntax highlighting groups for word under cursor
nmap <C-S-S> :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
function! <SID>StripTrailingWhitespaces()
if mode() == 'n'
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endif
endfunction
if has('autocmd')
augroup buffer_filetype_autocmds
au!
autocmd FileType html let g:html_indent_strict=1
autocmd BufEnter {Gemfile,Rakefile,Guardfile,Capfile,Vagrantfile,Thorfile,config.ru,*.rabl} setfiletype ruby
autocmd BufEnter *.template setfiletype json
autocmd BufEnter *.j setfiletype objc
autocmd BufEnter *.md setfiletype markdown
autocmd BufWritePre ?* :call <SID>StripTrailingWhitespaces()
autocmd BufEnter *.yml.sample setfiletype yaml
autocmd BufLeave,FocusLost ?* nested :wa
autocmd BufReadPost #* set bufhidden=delete
autocmd BufEnter *nginx.conf setfiletype nginx
augroup END
endif
command! -nargs=0 -bar Qargs execute 'args ' . QuickfixFilenames()
function! QuickfixFilenames()
" Building a hash ensures we get each buffer only once
let buffer_numbers = {}
for quickfix_item in getqflist()
let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
endfor
return join(values(buffer_numbers))
endfunction
" explicitly implementing suspend to force reloading changed files
noremap <c-z> :suspend<cr>:silent! checktime<cr>
" Shortcuts********************************************************************
nmap <silent> <unique> <leader>w :w<CR>
nmap <silent> <unique> <leader>W :wa<CR>
nmap <silent> <unique> <leader>p "*p
nmap <silent> <unique> <C-S-Down> :A<CR>
nmap <silent> <unique> <Space> <PageDown>
nmap <silent> <unique> <S-Space> <PageUp>
nmap <silent> <unique> <C-S-Left> <C-o>
nmap <silent> <unique> <C-S-Right> <C-i>
cnoremap %% <C-R>=expand('%:h').'/'<cr>
nmap <unique> <leader>ew :e %%
nmap <unique> <leader>es :sp %%
nmap <unique> <leader>ev :vsp %%
nmap <unique> <leader>et :tabe %%
nnoremap <unique> <C-h> <C-w>h
nnoremap <unique> <C-j> <C-w>j
nnoremap <unique> <C-k> <C-w>k
nnoremap <unique> <C-l> <C-w>l
nnoremap <unique> <C-Tab> <C-w>w
nnoremap <unique> <C-S-Tab> <C-w>W
nnoremap <unique> <S-Tab> <C-o>
inoremap <c-cr> <esc>A<cr>
nnoremap <unique> Y y$
" Help
autocmd FileType help :nnoremap <buffer> <silent> q :q<cr>
" Emacs style ctrl-a & ctrl-e in insert mode
inoremap <c-e> <c-r>=InsCtrlE()<cr>
function! InsCtrlE()
try
norm! i
return "\<c-o>A"
catch
return "\<c-e>"
endtry
endfunction
imap <C-a> <C-o>I
" Tabs ************************************************************************
"set sta " a <Tab> in an indent inserts 'shiftwidth' spaces
" Files, backups and undo******************************************************
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile
"Persistent undo
try
if MySys() == "windows"
set undodir=C:\Windows\Temp
else
set undodir=~expand('$HOME/.vim/tmp')
endif
set undofile
catch
endtry
" Highlight VCS conflict markers
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
" Easy buffer navigation
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
nnoremap <C-u> gUiw
inoremap <C-u> <esc>gUiwea
" Split line (sister to [J]oin lines)
" The normal use of S is covered by cc, so don't worry about shadowing it.
nnoremap S i<cr><esc><right>
" Better Completion
set completeopt=menu,longest,preview
" Toggle paste
set pastetoggle=<F8>
function! Tabstyle_tabs()
" Using 4 column tabs
set softtabstop=4
set shiftwidth=4
set tabstop=4
set noexpandtab
autocmd User Rails set softtabstop=4
autocmd User Rails set shiftwidth=4
autocmd User Rails set tabstop=4
autocmd User Rails set noexpandtab
endfunction
function! Tabstyle_spaces()
" Use 2 spaces
set softtabstop=2
set shiftwidth=2
set tabstop=2
set expandtab
endfunction
if hostname() == "Laptop.local"
call Tabstyle_tabs()
else
call Tabstyle_spaces()
endif
" Indenting *******************************************************************
set autoindent " Automatically set the indent of a new line (local to buffer)
set smartindent " smartindent (local to buffer)
" Scrollbars ******************************************************************
set sidescrolloff=2
set numberwidth=4
" Spaces while joining ********************************************************
set nojoinspaces
" Windows *********************************************************************
set equalalways " Multiple windows, when created, are equal in size
set splitbelow splitright
"Vertical split then hop to new buffer
noremap <leader>v :vsp<CR>
noremap <leader>h :split<CR>
" Cursor highlights ***********************************************************
au WinLeave * set nocursorline nocursorcolumn
au WinEnter,BufEnter * set cursorline cursorcolumn
set cursorline cursorcolumn
set colorcolumn=120
" Searching *******************************************************************
set hlsearch " highlight search
nmap <silent><unique> <leader>? :nohlsearch<CR>
set incsearch " incremental search, search as you type
set ignorecase " Ignore case when searching
set smartcase " Ignore case when searching lowercase
" Colors **********************************************************************
"set t_Co=256 " 256 colors
syntax on " syntax highlighting
colorscheme camouflage
if !has('gui_running')
let g:airline_theme="solarized"
endif
" Status Line *****************************************************************
set showcmd
set ruler " Show ruler
"set ch=2 " Make command line two lines high
set statusline=%<%F%h%m%r%h%w%y\ %{&ff}\ %{strftime(\"%d/%m/%Y-%H:%M\")}\ %{exists('g:loaded_rvm')?rvm#statusline():''}%=\ %l:%c%V\ %L\ %P
set laststatus=2
" Line Wrapping ***************************************************************
set nowrap
set linebreak " Wrap at word
set showbreak=…
" Per-directory .vimrc files
set exrc
set secure
" Mappings ********************************************************************
" Professor VIM says '87% of users prefer jj over esc', jj abrams strongly disagrees
imap jj <Esc>
imap uu _
imap hh =>
imap -- ->
imap aa @
" Directories *****************************************************************
" Setup backup location and enable
"set backupdir=~/backup/vim
"set backup
" Set Swap directory
"set directory=~/backup/vim/swap
" Sets path to directory buffer was loaded from
"autocmd BufEnter * lcd %:p:h
" File Stuff ******************************************************************
filetype plugin indent on
" To show current filetype use: set filetype
" Remember last location in file
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
endif
autocmd FileType html set filetype=xhtml " we couldn't care less about html
" Inser New Line **************************************************************
map <S-Enter> O<ESC>
map <Enter> o<ESC>
set fo-=r " do not insert a comment leader after an enter, (no work, fix!!)
" Sessions ********************************************************************
" Sets what is saved when you save a session
set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
" Misc ************************************************************************
set backspace=indent,eol,start
set number " Show line numbers
set matchpairs+=<:>
set vb t_vb= " Turn off the bell, this could be more annoying, but I'm not sure how
" Set list Chars - for showing characters that are not
" normally displayed i.e. whitespace, tabs, EOL
nmap <unique><silent><leader>l :set list!<CR>
set listchars=tab:▸\ ,eol:¬
" Mouse ***********************************************************************
"set mouse=a " Enable the mouse
"behave xterm
"set selectmode=mouse
" " Cursor Movement *************************************************************
" " Make cursor move by visual lines instead of file lines (when wrapping)
map <up> gk
map k gk
" imap <up> <C-o>gk # uncomment at your own risk. it interferes with Fuf.
map <down> gj
map j gj
" imap <down> <C-o>gj # same warning as the imap above.
" map E ge
" Ruby stuff ******************************************************************
compiler ruby " Enable compiler support for ruby
map <F5> :!ruby %<CR>
" Omni Completion *************************************************************
if has('autocmd')
autocmd FileType html :set omnifunc=htmlcomplete#CompleteTags
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete " may require ruby compiled in
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
endif
" -----------------------------------------------------------------------------
" | Plugins |
" -----------------------------------------------------------------------------
" Airline *********************************************************************
let g:airline_powerline_fonts = 1
" NERDTree ********************************************************************
nmap <silent> <unique> <leader>n :NERDTreeToggle<CR>
nmap <silent> <unique> <leader>/ :NERDTreeFind<CR>
" User instead of Netrw when doing an edit /foobar
let NERDTreeHijackNetrw=1
" Single click for everything
let NERDTreeMouseMode=1
" Ignoring java class files
let NERDTreeIgnore=['.class$', '\~$', '^cscope', 'tags', 'node_modules', '.tmp']
" Rails.vim shortcuts *********************************************************
nmap <silent> <unique> <leader>s :.Rake<CR>
nmap <silent> <unique> <leader>S :Rake<CR>
nmap <silent> <unique> <leader>- :Rake -<CR>
" Fugitive ********************************************************************
autocmd BufReadPost fugitive://* set bufhidden=delete
autocmd BufReadPost *.fugitiveblame set bufhidden=delete
autocmd BufReadPost .git/* set bufhidden=delete
autocmd BufReadPost GoToFile set bufhidden=delete
nnoremap <silent> <leader>gd :Gdiff<cr>
nnoremap <silent> <leader>gs :Gstatus<cr>
nnoremap <silent> <leader>gw :Gwrite<cr>
nnoremap <silent> <leader>gb :Gblame<cr>
nnoremap <silent> <leader>gci :Gcommit<cr>
nnoremap <silent> <leader>gm :Gmove<cr>
nnoremap <silent> <leader>gr :Gremove<cr>
nnoremap <silent> <leader>gl :Glog<cr>
augroup ft_fugitive
au!
au BufNewFile,BufRead .git/index setlocal nolist
augroup END
" yankring*********************************************************************
let g:yankring_history_dir = expand('$HOME/.vim/tmp')
nnoremap <silent> <F6> :YRShow<cr>
" Ctrl-P **********************************************************************
let g:ctrlp_dont_split = 'NERD_tree_2'
let g:ctrlp_jump_to_buffer = 0
let g:ctrlp_working_path_mode = 0
let g:ctrlp_match_window_reversed = 1
let g:ctrlp_split_window = 0
let g:ctrlp_max_height = 20
let g:ctrlp_extensions = ['tag']
if filereadable("/usr/local/bin/fzf") && !has('gui_running')
set rtp+=/usr/local/opt/fzf
nnoremap <leader>f :FZF<CR>
else
let g:ctrlp_map = '<leader>f'
end
let g:ctrlp_prompt_mappings = {
\ 'PrtSelectMove("j")': ['<c-j>', '<down>', '<s-tab>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<up>', '<tab>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'],
\ 'ToggleFocus()': ['<c-tab>'],
\ }
let ctrlp_filter_greps = "".
\ "egrep -iv '\\.(" .
\ "swp|swo|log|so|o|pyc|jpe?g|png|gif|mo|po|class|jar|DS_Store" .
\ ")$' | " .
\ "egrep -v '^(\\./)?(" .
\ "libs/|deploy/vendor/|.git/|.hg/|.svn/|tmp/|.tmp/|.idea/|node_modules/|.sass-cache/|bower_components/|_vendor/vendor/" .
\ ")'"
let my_ctrlp_user_command = "" .
\ "find %s '(' -type f -or -type l ')' -maxdepth 15 -not -path '*/\\.*/*' | " .
\ ctrlp_filter_greps
let my_ctrlp_git_command = "" .
\ "cd %s && git ls-files && git ls-files -o | " .
\ ctrlp_filter_greps
let g:ctrlp_user_command = ['.git/', my_ctrlp_git_command, my_ctrlp_user_command]
nnoremap <leader>t :CtrlPTag<cr>
nnoremap <leader>b :CtrlPBuffer<cr>
" Mundo ***********************************************************************
nmap <silent> <unique> <leader>u :MundoToggle<CR>
"autocmd BufReadPost __Mundo_* set bufhidden=delete
" Tagbar **********************************************************************
nmap <silent> <unique> <leader>c :TagbarToggle<CR>
" Ack *************************************************************************
if has('linux')
let g:ackprg="ack-grep -H --nocolor --nogroup --column"
endif
map <leader>a :Ack!
" Turbux **********************************************************************
let g:no_turbux_mappings = 1
" Git Gutter ******************************************************************
if has('autocmd')
augroup gitgutter_cmds
au!
autocmd BufReadPost ?* GitGutterAll
autocmd FocusLost ?* GitGutterAll
augroup END
endif
let g:gitgutter_realtime = 0
let g:gitgutter_eager = 0
" Syntastic *******************************************************************
let g:syntastic_coffee_checkers = ['coffeelint']
let g:syntastic_coffee_coffeelint_args = "--reporter csv --file ~/.coffeelint.json"
" autocomplpop ****************************************************************
" complete option
"set complete=.,w,b,u,t,k
"let g:AutoComplPop_CompleteOption = '.,w,b,u,t,k'
"set complete=.
let g:AutoComplPop_IgnoreCaseOption = 0
let g:AutoComplPop_BehaviorKeywordLength = 2
let g:EasyMotion_smartcase = 1
" Unimpaired configuration ****************************************************
" Bubble single lines
nmap <C-Up> [e==
nmap <C-k> [e==
nmap <C-Down> ]e==
nmap <C-j> ]e==
" Bubble multiple lines
vmap <C-Up> [egv=gv
vmap <C-k> [egv=gv
vmap <C-Down> ]egv=gv
vmap <C-j> ]egv=gv
" UltiSnips *******************************************************************
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
" Vimux ***********************************************************************
nmap <leader>vpc :wa<CR>:VimuxPromptCommand<CR>
nmap <leader>vrlc :wa<CR>:VimuxRunLastCommand<CR>
nmap <leader>r :wa<CR>:VimuxRunLastCommand<CR>
" Vim.go **********************************************************************
let g:syntastic_go_checkers = ['goimports', 'golint', 'govet', 'errcheck']
let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
let g:go_fmt_command = 'goimports'
" -----------------------------------------------------------------------------
" | OS Specific |
" | (GUI stuff goes in gvimrc) |
" -----------------------------------------------------------------------------
" Mac *************************************************************************
if has("mac")
endif
" Windows *********************************************************************
"if has("gui_win32")
""
"endif
" -----------------------------------------------------------------------------
" | Startup |
" -----------------------------------------------------------------------------
" Open NERDTree on start
"autocmd VimEnter * exe 'NERDTree' | wincmd l
" Add recently accessed projects menu (project plugin)
filetype on " Automatically detect file types.
" Minibuffer Explorer Settings
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
set hid
" alt+n or alt+p to navigate between entries in QuickFix
map <silent><m-p> :cp <CR>
map <silent><m-n> :cn <CR>
" Change which file opens after executing :Rails command
let g:rails_default_file='config/database.yml'
syntax enable
filetype plugin on
set ofu=syntaxcomplete#Complete
" Last but not least, allow for local overrides
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif