-
Notifications
You must be signed in to change notification settings - Fork 6
/
vimrc
463 lines (396 loc) · 16.3 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
" .vimrc
" Author: Philipe Fatio <[email protected]>
" Preamble {{{
" Use vim settings, rather then vi settings (much better!)
" This must be first, because it changes other options as a side effect.
set nocompatible
filetype off
set encoding=utf-8
" }}}
" Plugins {{{
call plug#begin('~/.vim/plugged')
Plug 'AndrewRadev/splitjoin.vim' "{{{
let g:splitjoin_ruby_hanging_args=0
let g:splitjoin_ruby_curly_braces=0
"}}}
Plug 'bruno-/vim-vertical-move'
Plug 'chriskempson/base16-vim'
Plug 'cohama/lexima.vim'
Plug 'godlygeek/tabular' "{{{
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs/l0r1<CR>
vmap <Leader>a: :Tabularize /:\zs/l0r1<CR>
nmap <Leader>a, :Tabularize /,\zs/l0r1<CR>
vmap <Leader>a, :Tabularize /,\zs/l0r1<CR>
nmap <Leader>a<Bar> :Tabularize /<Bar><CR>
vmap <Leader>a<Bar> :Tabularize /<Bar><CR>
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if 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
"}}}
Plug 'janko-m/vim-test' "{{{
let test#strategy = "dispatch"
nmap <silent> <leader>tn :silent! noautocmd wa \| TestNearest<CR>
nmap <silent> <leader>tf :silent! noautocmd wa \| TestFile<CR>
nmap <silent> <leader>ta :silent! noautocmd wa \| TestSuite<CR>
nmap <silent> <leader>tl :silent! noautocmd wa \| TestLast<CR>
nmap <silent> <leader>tg :silent! noautocmd wa \| TestVisit<CR>
"}}}
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim' "{{{
set rtp+=$HOMEBREW_PREFIX/opt/fzf
let g:fzf_layout = { 'down': '40%' }
let g:fzf_preview_window = []
let g:fzf_command_prefix = 'Fzf'
nmap <C-P><C-F> :<C-U>FzfFiles<CR>
nmap <C-P><C-B> :<C-U>FzfBuffers<CR>
nmap <C-P><C-T> :<C-U>FzfTags<CR>
let $FZF_DEFAULT_COMMAND = 'rg --files'
let g:fzf_history_dir = '~/.local/share/fzf-history'
"}}}
Plug 'junegunn/goyo.vim'
Plug 'kana/vim-textobj-user'
Plug 'ludovicchabant/vim-gutentags'
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'mhinz/vim-signify' "{{{
let g:signify_vcs_list = ['git']
let g:signify_update_on_focusgained = 1
"}}}
Plug 'nelstrom/vim-markdown-folding'
Plug 'nelstrom/vim-textobj-rubyblock'
Plug 'romainl/vim-qlist'
Plug 'sheerun/vim-polyglot'
Plug 'simnalamburt/vim-mundo' "{{{
let g:mundo_right = 1
map <S-Right> <ESC>:MundoToggle<CR>
"}}}
Plug 'SirVer/ultisnips' "{{{
let g:UltiSnipsListSnippets="<S-Tab>"
let g:UltiSnipsExpandTrigger="<Tab>"
let g:UltiSnipsJumpForwardTrigger="<C-J>"
let g:UltiSnipsJumpBackwardTrigger="<C-K>"
let g:UltiSnipsSnippetsDir="~/.vim/snips"
let g:UltiSnipsSnippetDirectories=["snips"]
let g:UltiSnipsEditSplit='context'
let g:UltiSnipsEnableSnipMate=0
set rtp+=~/.vim
au BufNewFile,BufRead *_spec.rb UltiSnipsAddFiletypes rspec
map <leader>es :UltiSnipsEdit<CR>:lcd %:p:h<CR>
"}}}
Plug 'sjl/vitality.vim'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-dispatch' "{{{
let g:dispatch_tmux_height=15
map <silent> <leader>d :silent! noautocmd wa \| Dispatch<CR>
"}}}
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-fugitive' "{{{
map <leader>gs :Git<CR>
map <leader>gS :Gtabedit :<CR>
map <leader>gd :Gdiff<CR>
map <leader>gc :Gcommit<CR>
map <leader>gw :Gwrite<CR>
map <leader>gr :Gread<CR>
map <leader>gb :Git blame<CR>
" When diffing two files, save and close the index file, go to the git status
" split below and jump to the next file:
map <leader>gn :x<CR><C-w>j<C-n>D
"}}}
Plug 'tpope/vim-git'
Plug 'tpope/vim-obsession'
Plug 'tpope/vim-projectionist'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-rake'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-rsi'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'vim-scripts/matchit.zip'
Plug 'vim-scripts/ruby-matchit'
Plug 'vim-scripts/transpose-words' "{{{
exec "set <M-t>=\<Esc>t"
"}}}
call plug#end()
" }}}
" Editing Behavior {{{
set regexpengine=1 " newer engine is slow with vim-ruby
set showmode " always show what mode we're currently editing in
set tabstop=2 " a tab is two spaces
set softtabstop=2 " when hitting <BS>, pretend like a tab is removed, even if spaces
set shiftwidth=2 " number of spaces to use for autoindenting
set expandtab " use spaces
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set autoindent " always set autoindenting on
set copyindent " copy the previous indentation on autoindenting
set number " use absolute line numbers
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase,
" case-sensitive otherwise
set splitright " open vertical splits to the right
set splitbelow " open splits to the bottom
set smarttab " insert tabs on the start of a line according to
" shiftwidth, not tabstop
set scrolloff=2 " keep x lines off the edges of the screen when scrolling vertically
set sidescrolloff=5 " keep x columns off the edges of the screen when scrolling horizontally
set incsearch " show search matches as you type
set gdefault " search/replace "globally" (on a line) by default
set listchars=tab:▸\ ,trail:·,extends:…,precedes:…,nbsp:·
set list " show above special chars
set linebreak " don't wrap lines in the middle of words
let &showbreak='↪ '
set display+=lastline
set pastetoggle=<F2> " when in insert mode, press <F2> to go to
" paste mode, where you can paste mass data
" that won't be autoindented
" Make Vim recognize XTerm escape sequences for Page and Arrow
" keys combined with modifiers such as Shift, Control, and Alt.
" See http://www.reddit.com/r/vim/comments/1a29vk/_/c8tze8p
if &term =~ '^tmux'
" Page keys http://sourceforge.net/p/tmux/tmux-code/ci/master/tree/FAQ
execute "set t_kP=\e[5;*~"
execute "set t_kN=\e[6;*~"
" Arrow keys http://unix.stackexchange.com/a/34723
execute "set <xUp>=\e[1;*A"
execute "set <xDown>=\e[1;*B"
execute "set <xRight>=\e[1;*C"
execute "set <xLeft>=\e[1;*D"
endif
" suppress all bells
set novisualbell
set noerrorbells
set vb
set mouse=a " enable using the mouse if terminal emulator
" supports it (xterm does)
if !has('nvim')
set ttymouse=sgr " make mouse work past the 220th column
endif
set fileformats="unix,dos,mac"
set formatoptions=1cnqroj
set comments=b:*,b:-,b:>
set synmaxcol=200 " only do syntax highlighting within first 200 columns
set hidden " hide buffers instead of closing them this
" means that the current buffer can be put
" to background without being written; and
" that marks and undo history are preserved
set switchbuf=useopen " reveal already opened files from the
" quickfix window instead of opening new
" buffers
set history=1000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
if v:version >= 730
set undofile " keep a persistent backup file
set undodir=~/.vim/.undo,~/tmp,/tmp
endif
set nobackup " do not keep backup files, it's 70's style cluttering
set noswapfile " do not write annoying intermediate swap files,
" who did ever restore from swap files anyway?
set directory=~/.vim/.tmp,~/tmp,/tmp
" store swap files in one of these directories
" (in case swapfile is ever turned on)
set viminfo='20,\"80 " read/write a .viminfo file, don't store more
" than 80 lines of registers
set title " change the terminal's title
set showcmd " show (partial) command in the last line of the screen
" this also shows visual selection info
set nomodeline " disable mode lines (security measure)
set ruler " show cursor position
set colorcolumn=81 " highlight 81st column
" Tab completion
set wildmode=list:longest,list:full
set wildmenu
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*,doc/**,coverage/**
set laststatus=2 " Always display the statusline in all windows
set noshowmode " Hide the default mode text (e.g. -- INSERT -- below the statusline)
set spell
set spelllang=en_us
" LaTeX settings
set cole=2
let g:tex_conceal='adgm'
hi Conceal guibg=bg guifg=#66d9ef
" Save whenever switching windows or leaving vim.
au FocusLost * :silent! wa
" Trigger autoread when coming back to vim.
au FocusGained * :silent! !
" }}}
" Key Mappings {{{
" The current directory for the active file
cnoremap %% <C-R>=expand('%:h').'/'<CR>
" Remap partial history search
cnoremap <C-P> <Up>
cnoremap <C-N> <Down>
" make j and k always move to next visual line (useful for wrapped lines).
nnoremap j gj
nnoremap k gk
" clean whitespace in file
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Keep search matches in the middle of the window and open the fold.
nnoremap * *zvzz
nnoremap # #zvzz
nnoremap n nzvzz
nnoremap N Nzvzz
" Same behavior as C
nnoremap D d$
nnoremap Y y$
" toggle fold
nnoremap <Space> za
vnoremap <Space> za
" "Refocus" folds
nnoremap <leader>z zMzvzczOzz
" Yank/paste to the OS clipboard with ,y and ,p
nmap <leader>y "*y
nmap <leader>d "*d
nmap <leader>Y "*y$
nmap <leader>p "*p
nmap <leader>P "*P
vmap <leader>y "*y
vmap <leader>d "*d
vmap <leader>p "*p
" Make Arrow Keys Useful Again
map <down> <ESC>:ccl<CR>
map <up> <ESC>:cope<CR>
" Unimpaired configuration
" Bubble multiple lines
vmap <M-Up> [egv
vmap <M-Down> ]egv
" highlight lines longer than 80 chars
nnoremap <leader>ll /\%>80v.\+<CR>
" Quickly open certain files for editing
map <leader>ev :tabe ~/dotfiles/vimrc<CR>:lcd %:p:h<CR>
" }}}
" Folding Rules {{{
set nofoldenable
set foldcolumn=0
set foldmethod=syntax
set foldlevelstart=99
set foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo
" which commands trigger auto-unfold
function! MyFoldText()
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let start_line = substitute(getline(v:foldstart), '\t', onetab, 'g')
let delta = 0 " unicode char correction
if len(start_line) > 72
let start_line = substitute(start_line, '^\(.\{72\}\).*$', '\1…', 'g')
let delta = 2
endif
let end_line = substitute(getline(v:foldend), '\s', '', 'g')
let nucolwidth = &foldcolumn + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart + 1
let line = start_line.' '
let dash_fill_count = windowwidth - 80
let space_fill_count = 80 - len(line) - len(foldedlinecount) - 1 + delta
return line.repeat(' ', space_fill_count).foldedlinecount.' '.repeat('—', dash_fill_count)
endfunction
set foldtext=MyFoldText()
function! NextClosedFold(dir)
let cmd = 'norm!z' . a:dir
let view = winsaveview()
let [l0, l, open] = [0, view.lnum, 1]
while l != l0 && open
exe cmd
let [l0, l] = [l, line('.')]
let open = foldclosed(l) < 0
endwhile
if open
call winrestview(view)
endif
endfunction
nmap <silent> zj :call NextClosedFold('j')<cr><leader>z
nmap <silent> zk :call NextClosedFold('k')<cr><leader>z
" Fold for languages that use indentation. The indent fold method uses the first
" line of an indentation level as the fold. This will use the previous line as
" the fold.
" http://learnvimscriptthehardway.stevelosh.com/chapters/49.html
function! GetIndentationFold(lnum)
if getline(a:lnum) =~? '\v^\s*$'
return '-1'
endif
let this_indent = IndentLevel(a:lnum)
let next_indent = IndentLevel(NextNonBlankLine(a:lnum))
if next_indent == this_indent
return this_indent
elseif next_indent < this_indent
return this_indent
elseif next_indent > this_indent
return '>' . next_indent
endif
endfunction
function! IndentLevel(lnum)
return indent(a:lnum) / &shiftwidth
endfunction
function! NextNonBlankLine(lnum)
let numlines = line('$')
let current = a:lnum + 1
while current <= numlines
if getline(current) =~? '\v\S'
return current
endif
let current += 1
endwhile
return -2
endfunction
set foldexpr=GetIndentationFold(v:lnum)
" }}}
" Editor Behavior {{{
set autoread " Remember last location in file
set timeoutlen=600 " timeout for leader maps
set diffopt=vertical,filler,hiddenoff
if executable('rg')
set grepprg=rg\ --vimgrep
endif
if filereadable(expand('~/.vimrc_background'))
" Fix highlighting for spell checks in terminal
function! s:base16_customize() abort
" Colors: https://github.com/chriskempson/base16/blob/master/styling.md
" Arguments: group, guifg, guibg, ctermfg, ctermbg, attr, guisp
call Base16hi("SpellBad", "", "", g:base16_cterm08, g:base16_cterm00, "", "")
call Base16hi("SpellCap", "", "", g:base16_cterm0A, g:base16_cterm00, "", "")
call Base16hi("SpellLocal", "", "", g:base16_cterm0D, g:base16_cterm00, "", "")
call Base16hi("SpellRare", "", "", g:base16_cterm0B, g:base16_cterm00, "", "")
endfunction
augroup on_change_colorschema
autocmd!
autocmd ColorScheme * call s:base16_customize()
augroup end
let base16colorspace=256
source ~/.vimrc_background
endif
" }}}
" File Type Configurations {{{
au FileType javascript,css,less,scss,objc,c,vim setlocal foldmethod=marker
au FileType javascript,css,less,scss,objc,c setlocal foldmarker={,}
au FileType coffee,slim,yaml,python setlocal foldmethod=expr
au FileType scss setlocal iskeyword+=@-@,$,-,%,#,.
au FileType css setlocal iskeyword+=-,#,.
au FileType coffee setlocal iskeyword+=$
au FileType make,snippets setlocal noexpandtab
au FileType objc,sql setlocal shiftwidth=4
" Delete certain buffers in order to not cluttering up the buffer list:
au BufReadPost fugitive://* set bufhidden=delete
au BufReadPost ~/.gem/* set bufhidden=delete
au BufReadPost ~/dotfiles/* set bufhidden=delete
au BufNewFile,BufRead {Gem,Pod,Rake,Fast}file,*.{rabl,podspec} set filetype=ruby
au BufNewFile,BufRead *.yml.enc set filetype=yaml
" Don't autowrap lines when writing a pull request as line breaks are preserved
" on GitHub; softwrap instead:
au VimEnter {PULL,MERGE}REQ_EDITMSG setlocal formatoptions-=t wrap
" }}}
" Searches {{{
let SqlCapitalize = '\<\(delete\|create\|insert\|select\|update\|alter\|having\|into\|returning\|set\|from\|where\|and\|or\|on\|join\|not\|null\|in\|is\|using\|case\|when\|else\|if\|elsif\|end\|as\|order\|by\|asc\|desc\|limit\|with\|over\|partition\|group\|like\|left\|right\|outer\|inner\|full\|union\|all\|distinct\|coalesce\|natural\|window\|unique\|index\|drop\|table\|column\|begin\|commit\|abort\|rollback\|rename\|add\|remove\|to\|exists\|primary key\|extension\|explain\|analyze\|filter\)\>\C'
" }}}
" Highlighting {{{
highlight Comment cterm=italic
" }}}