-
Notifications
You must be signed in to change notification settings - Fork 3
/
.vimrc
531 lines (461 loc) · 16.4 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
" Use vim, no vi defaults
set nocompatible
call plug#begin('~/.vim/plugged')
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGINS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Plug 'airblade/vim-gitgutter'
Plug 'ervandew/supertab'
Plug 'junegunn/vim-easy-align', { 'on': ['<Plug>(EasyAlign)', 'EasyAlign'] }
Plug 'kana/vim-textobj-user'
Plug 'nelstrom/vim-textobj-rubyblock'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/syntastic'
Plug 'sheerun/vim-polyglot'
Plug 'thoughtbot/vim-rspec'
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-rake'
Plug 'tpope/vim-rhubarb'
Plug 'tyrannicaltoucan/vim-deep-space'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" EDITOR CONFIGURATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Prevent a security hole
set modelines=0
" Set default encoding to UTF-8
set encoding=utf-8
" This makes RVM work inside Vim. I have no idea why.
set shell=bash
" Prevent Vim from clobbering the scrollback buffer. See
" http://www.shallowsky.com/linux/noaltscreen.html
set t_ti= t_te=
" Send more characters for redraws
set ttyfast
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BASIC EDITING CONFIGURATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Allow unsaved background buffers and remember marks/undo for them
set hidden
" Remember more commands and search history
set history=1000
" Use already open buffer
set switchbuf=useopen
" Write the contents of the file if it has been modified
set autowrite
" Use only one space after period when joining lines
set nojoinspaces
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" INTERFACE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable highlighting for syntax
syntax enable
" Syntax coloring lines that are too long just slows down the world
set synmaxcol=128
" Maximum number of lines to scroll the screen
set ttyscroll=3
" To avoid scrolling problems
set lazyredraw
" Set window title
set title
" Display incomplete commands
set showcmd
" Highlight current line
set cursorline
" Show line numbers
set number
" Minimal window width
set winwidth=79
" Keep more context when scrolling off the end of a buffer (3 lines)
set scrolloff=3
" Height of the command bar
set cmdheight=2
" When on, splitting a window will put the new window below the current one
set splitbelow
" When on, splitting a window will put the new window right of the current one
set splitright
" Show line numbers
set number
" Line number left margin
set numberwidth=5
" Always show the status bar
set laststatus=2
" Fix vim auto-complete slowness in large projects
set foldmethod=manual
" Dashed border
set fillchars=vert:\|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" COLOR
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Background color
set background=dark
" Theme
colorscheme deep-space
" Enable true colors in the terminal
if (has("termguicolors"))
set termguicolors
endif
" More information, e.g. :verbose highlight VertSplit
highlight clear SignColumn
" Git Gutter column with signs
highlight GitGutterAdd ctermfg=2 ctermbg=NONE guibg=NONE
highlight GitGutterChange ctermfg=4 ctermbg=NONE guibg=NONE
highlight GitGutterDelete ctermfg=1 ctermbg=NONE guibg=NONE
highlight GitGutterChangeDelete ctermfg=5 ctermbg=NONE guibg=NONE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SEARCH CONFIGURATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Incremental searching
set incsearch
" Highlight matches
set hlsearch
" Show matching bracket when text indicator is over them
set showmatch
" Make searches case-sensitive only if they contain upper-case characters
set ignorecase smartcase
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BACKUP
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable backups
set backup
" Backups
set backupdir=~/.vim/tmp/backup//
" Swap files
set directory=~/.vim/tmp/swap//
" It's 2012, Vim.
set noswapfile
" Make vim able to edit crontab files again.
set backupskip=/tmp/*,/private/tmp/*"
" Enable undo history
set undofile
" Undo files
set undodir=~/.vim/tmp/undo//
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" INDENTATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Automatic alignment during insertions
set autoindent
" Use spaces, not tabs
set expandtab
" A tab is two spaces
set tabstop=2
" An autoindent (with <<) is two spaces
set shiftwidth=2
" Should be the same value of shiftwidth
set softtabstop=2
" Always round the indent to a multiple of 'shiftwidth'
set shiftround
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" WILDMENU
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Make tab completion for files/buffers act like bash
set wildmenu
" Use emacs-style tab completion when selecting files, etc
set wildmode=longest,list
set wildignore+=.hg,.git,.svn " Version control
set wildignore+=*.orig " Merge resolution files
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.DS_Store " OSX bullshit
set wildignore+=*/cassettes/**/*.yml " Ruby vcr
set wildignore+=*/build " Ruby motion
set wildignore+=*/tmp/**
set wildignore+=*/vendor/bundle " Cached gems
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" LIST
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Show invisible characters
set list
" Reset the listchars
set listchars=""
" A tab should display as " ", trailing whitespace as "."
set listchars=tab:\ \
" Show trailing spaces as middle dots
set listchars+=trail:·
" The character to show in the last column when wrap is off and the line continues beyond the right of the screen
set listchars+=extends:>
" The character to show in the last column when wrap is off and the line continues beyond the right of the screen
set listchars+=precedes:<
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CONVENIENCE MAPPINGS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remapping leader to ,
let mapleader=","
" Aliasing the new leader ',' to the default one '\'
nmap \ ,
" Better ESC
inoremap jk <Esc>
" Use sane regexes.
nnoremap / /\v
vnoremap / /\v
" * Disabled while using Vim Tmux Navigator plugin *
" Move around splits with <c-hjkl>
"nnoremap <c-j> <c-w>j
"nnoremap <c-k> <c-w>k
"nnoremap <c-h> <c-w>h
"nnoremap <c-l> <c-w>l
" Clear the search buffer when hitting return
function! MapCR()
nnoremap <cr> :nohlsearch<cr>
endfunction
call MapCR()
" Clean trailing whitespaces
nnoremap <leader>w mz:%s/\s\+$//<cr>:let @/=''<cr>`z
" System clipboard interaction
if has('clipboard')
vnoremap <leader>Y "*y
nnoremap <leader>Y "*yy
else
nnoremap <leader>Y :.!pbcopy<CR>uk<CR>
vnoremap <leader>Y :!pbcopy<CR>uk<CR>
" http://vimtips.quora.com/How-to-Copy-to-clipboard-on-vim
"map <C-c> y:e ~/clipsongzboard<CR>P:w !pbcopy<CR><CR>:bdelete!<CR>
end
noremap <leader>P :set paste<CR>:r !pbpaste<CR>:set nopaste<CR>
" Select (charwise) the contents of the current line, excluding indentation.
nnoremap vv ^vg_
" Don't lose selection when shifting sidewards
xnoremap < <gv
xnoremap > >gv
" Keep search matches in the middle of the window.
nnoremap n nzzzv
nnoremap N Nzzzv
" Same when jumping around
nnoremap g; g;zz
nnoremap g, g,zz
" It's 2012.
noremap j gj
noremap k gk
noremap gj j
noremap gk k
" Better navigation between windows
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Make Y consistent with C and D.
nnoremap Y y$
" Find merge conflict markers
nmap <silent> <leader>cf <ESC>/\v^[<=>]{7}( .*\|$)<CR>
" Shorcut for setting a pry breakpoint
iabbrev xpry require 'pry'; binding.pry<Esc>F%s<c-o>:call getchar()<CR>
" Convert ruby 1.8 hash into ruby 1.9
nnoremap <leader>h :%s/:\([^ ]*\)\(\s*\)=>/\1:/g<CR>
" Make escape get out of pumenu mode and go back to the uncompleted word
inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" EXTRA
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sudo to write
cnoremap w!! w !sudo tee % >/dev/null
" Open files in directory of current file
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
" Typos
command! -bang E e<bang>
command! -bang Q q<bang>
command! -bang W w<bang>
command! -bang QA qa<bang>
command! -bang Qa qa<bang>
command! -bang Wa wa<bang>
command! -bang WA wa<bang>
command! -bang Wq wq<bang>
command! -bang WQ wq<bang>
" Edit .vimrc file
nnoremap <leader>EV :vsplit $MYVIMRC<cr>
" Reload .vimrc file
nnoremap <leader>RV :source $MYVIMRC<cr>
" Edit fish config file
nnoremap <leader>EF :vsplit ~/.config/fish/config.fish<cr>
" Edit tmux config file
nnoremap <leader>ET :vsplit ~/.tmux.conf<cr>
" Replace grep with ripgrep
if executable("rg")
set grepprg=rg\ --vimgrep
endif
" Auto open the search result
autocmd QuickFixCmdPost *grep* cwindow
" Spell checking and automatic wrapping at the 72 chars to git commit message
autocmd Filetype gitcommit setlocal spell textwidth=72
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ARROW KEYS ARE UNACCEPTABLE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <Left> :echo "Arrow keys are unacceptable"<CR>
map <Right> :echo "Arrow keys are unacceptable"<CR>
map <Up> :echo "Arrow keys are unacceptable"<CR>
map <Down> :echo "Arrow keys are unacceptable"<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RENAME CURRENT FILE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PROMOTE VARIABLE TO RSPEC LET
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! PromoteToLet()
:normal! dd
" :exec '?^\s*it\>'
:normal! P
:.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/
:normal ==
endfunction
:command! PromoteToLet :call PromoteToLet()
:map <leader>p :PromoteToLet<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SWITCH BETWEEN TEST AND PRODUCTION CODE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! OpenTestAlternate()
let new_file = AlternateForCurrentFile()
exec ':e ' . new_file
endfunction
function! AlternateForCurrentFile()
let current_file = expand("%")
let new_file = current_file
let in_spec = match(current_file, '^spec/') != -1
let going_to_spec = !in_spec
let in_app = match(current_file, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<views\>') != -1 || match(current_file, '\<helpers\>') != -1 || match(current_file, '\<resources\>') != -1
if going_to_spec
if in_app
let new_file = substitute(new_file, '^app/', '', '')
end
let new_file = substitute(new_file, '\.rb$', '_spec.rb', '')
let new_file = substitute(new_file, '\.jbuilder$', '.jbuilder_spec.rb', '')
let new_file = 'spec/' . new_file
else
let new_file = substitute(new_file, '_spec\.rb$', '.rb', '')
let new_file = substitute(new_file, '^spec/', '', '')
if in_app
let new_file = 'app/' . new_file
end
endif
return new_file
endfunction
nnoremap <leader>. :call OpenTestAlternate()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM AUTOCMDS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup cursor-position
" Remove ALL autocommands for the current group.
autocmd!
" Jump to last cursor position unless it's invalid or in an event handler
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
augroup highlight
" Remove ALL autocommands for the current group.
autocmd!
" Leave the return key alone when in quickfix windows, since it's used
" to run commands there.
autocmd BufEnter * :if &buftype is# "quickfix" | :unmap <cr>| else | :call MapCR()| endif
" Leave the return key alone when in command line windows, since it's used
" to run commands there.
autocmd CmdwinEnter * :unmap <cr>
autocmd CmdwinLeave * :call MapCR()
" Highlight characters longer than 100 characters
autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#111111
autocmd BufEnter * match OverLength /\%>100v.\+/
augroup END
augroup autosave
" Remove ALL autocommands for the current group.
autocmd!
if has('gui_macvim')
" Autosave file/buffers when losing focus
autocmd FocusLost * :silent! wall
else
" Autosave file/buffers when leaving insert mode
autocmd InsertLeave * if expand('%') != '' | update | endif
end
augroup END
augroup config-github-complete
" Remove ALL autocommands for the current group.
autocmd!
" Github completion on git commit messages
autocmd FileType gitcommit setl omnifunc=rhubarb#omnifunc | call SuperTabChain(&omnifunc, "<c-p>")
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGINS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Matchit
" Enable matchit.vim
runtime macros/matchit.vim
" FZF
set rtp+=/usr/local/opt/fzf
" Act like CtrlP
let g:fzf_action = {
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit'
\ }
" <C-p> or <C-t> to search files
nnoremap <silent> <C-t> :FZF -m<cr>
nnoremap <silent> <C-p> :FZF -m<cr>
" NerdCommenter
" Menu remapping
map <leader>/ <plug>NERDCommenterToggle<CR>
imap <leader>/ <Esc><plug>NERDCommenterToggle<CR>i
" Airline
let g:airline_theme = 'deep_space'
" Enable usage of patched powerline font symbols
let g:airline_powerline_fonts = 1
"Syntastic
let g:syntastic_error_symbol = '✗'
let g:syntastic_warning_symbol = '⚠'
" Jump cursor to the first detected error when saving
let g:syntastic_auto_jump = 1
" Enable rubocop check
"let g:syntastic_ruby_checkers = ['mri', 'rubocop']
" Most issues returned by rubocop are warnings
let g:syntastic_quiet_messages = {'level': 'warnings'}
" Vim-rspec
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
map <Leader>a :call RunAllSpecs()<CR>
function! RunWithoutDispatch(command)
let original_command = g:rspec_command
let g:rspec_command = "Dispatch! spring rspec {spec}"
function! RunSpecs(spec)
execute substitute(g:rspec_command, "{spec}", a:spec, "g")
endfunction
:execute "call " . a:command . "()"
let g:rspec_command = original_command
function! RunSpecs(spec)
execute substitute(g:rspec_command, "{spec}", a:spec, "g")
endfunction
endfunction
map <Leader>T :call RunWithoutDispatch("RunCurrentSpecFile")<CR>
map <Leader>S :call RunWithoutDispatch("RunNearestSpec")<CR>
map <Leader>L :call RunWithoutDispatch("RunLastSpec")<CR>
map <Leader>A :call RunWithoutDispatch("RunAllSpecs")<CR>
let g:rspec_command = "Dispatch spring rspec {spec}"
" Easy Plugin
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" Supertab
" Navigate the completion menu from top to bottom
let g:SuperTabDefaultCompletionType = "<c-n>"