-
Notifications
You must be signed in to change notification settings - Fork 2
/
dot_vimrc
641 lines (532 loc) · 17.7 KB
/
dot_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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
"--- Main Configuration{{{
" =======================================
" Leader
" =======================================
let mapleader = ","
let g:mapleader = ","
" Display
set linespace=3
set title
set cmdheight=1
set showtabline=2
set winwidth=100
set winheight=10
set nowrap
set path=**
set cursorline
"--- Something else
set shortmess=a
set cmdheight=2
set wildignore+=*tmp/**
set wildignore+=*coverage
" Disable output and VCS files
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem
" Ignore images and log files
set wildignore+=*.gif,*.jpg,*.png,*.log
" Disable archive files
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
" Ignore bundler and sass cache
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/*
" Ignore custom folders
set wildignore+=*/resources/*
set wildignore+=*/tmp/*
" Ignore node modules
set wildignore+=node_modules/*
" Disable temp and backup files
set wildignore+=*.swp,*~,._*
" Disable osx index files
set wildignore+=.DS_Store
" =======================================
" Vim's :! system bash
" =======================================
set shellcmdflag=-c
" =======================================
" Per Project .vimrc
" =======================================
set exrc " Load .vimrc in project directory
set secure " Disable unsafe commands in local .vimrc files
" =======================================
" Tabbing
" =======================================
set tabstop=2 " Number of spaces in 'soft' tabs
set softtabstop=2 " Number of spaces in 'soft' tabs
set shiftwidth=2 " For use with indent plugins and `tabstop` setting
set expandtab " Use 'soft' tabs when using <Tab> character
" =======================================
" Arrow Keys Are Not Allowed
" =======================================
nnoremap <Left> <Nop>
nnoremap <Right> <Nop>
nnoremap <Up> <Nop>
nnoremap <Down> <Nop>
" =======================================
" Since <Esc> is elusive with touchbar
" =======================================
inoremap jj <esc>
inoremap jk <esc>
" =======================================
" Files
" =======================================
"
" Don't backup. Already using other forms of verion control.
set nobackup " Do not make backup before over-writing file
set nowb " Do not backup file before writing
set noswapfile " Do not save swapfiles for unsaved buffers
set shortmess=aWtI
" =======================================
" Movement
" =======================================
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
nnoremap <c-n> :bp<CR>
nnoremap <c-p> :bn<CR>
" nnoremap <c-s-h> :tabnext<CR>
" nnoremap <c-s-l> :tabprev<CR>
set belloff=all
set history=3000 " History Length
set backspace=indent,eol,start " Allow backspecing over everything in insert mode
set autoread " Automatically read files from disk when detected
set smarttab " Smart tabbing
set autoindent " Use indent level from current line for next line
set ruler
filetype plugin indent on " Filetype detection
" =======================================
" Statusline Setup
" =======================================
set laststatus=2
set noshowmode
" =======================================
" Searching
" =======================================
highlight Search guibg=yellow guifg=black gui=underline
highlight Search ctermbg=yellow ctermfg=black cterm=underline
set showcmd
set incsearch
set hlsearch " Don't highlight results
" set ignorecase " Don't search by case
" =======================================
" Various
" =======================================
set go=-T " Hide GUI toolbar
set mousehide " Hide the mouse
set mouse=n " Allow 'mouse' navigation in Normal (n) mode
set splitbelow " When splitting, set new file on the bottom
set hidden " Hide hidden files
set numberwidth=1 " Line number width
" =======================================
" Relative Line Numbers
" =======================================
set number relativenumber
"}}}
" --- Plugins{{{
call plug#begin('~/.vim/plugged')
" General Environment
" -----------------------------------------
Plug 'morhetz/gruvbox' " theme
Plug 'direnv/direnv.vim' " direnv for environment
Plug 'editorconfig/editorconfig-vim' " editorconfig
Plug 'itchyny/lightline.vim' " slightly better line information
Plug 'jeffkreeftmeijer/vim-numbertoggle' " Toggle number lines
Plug 'airblade/vim-gitgutter' " Display git status in files
Plug 'nathanaelkane/vim-indent-guides'
Plug 'preservim/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeFind', 'NERDTreeFocus', 'NERDTree'] }
Plug 'godlygeek/tabular'
" Tim Pope
" -----------------------------------------
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-rake'
Plug 'tpope/vim-endwise', { 'for': ['ruby', 'eruby'] }
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rails', { 'for': ['ruby', 'eruby'] }
" Plug 'tpope/vim-dispatch'
" Plug 'jgdavey/tslime.vim'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'cespare/vim-toml'
Plug 'chrismccord/bclose.vim'
Plug 'jiangmiao/auto-pairs'
Plug 'honza/vim-snippets'
Plug 'mattn/emmet-vim'
" Plug 'posva/vim-vue'
" Searching/Navigation
" -----------------------------------------
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
Plug 'w0rp/ale'
" CoC.nvim
" -----------------------------------------
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
Plug 'rodrigore/coc-tailwind-intellisense', {'do': 'npm install'}
" Ruby
" -----------------------------------------
Plug 'slim-template/vim-slim', { 'for': ['slim'] }
Plug 'kana/vim-textobj-user', { 'for': 'ruby' } " vim-textobj-rubyblock dependeny
Plug 'nelstrom/vim-textobj-rubyblock', { 'for': 'ruby' }
Plug 'sunaku/vim-ruby-minitest', { 'for': 'ruby' }
Plug 'vim-ruby/vim-ruby', { 'for': 'ruby', 'rev': 'vim8.2' }
Plug 'thoughtbot/vim-rspec', { 'for': 'ruby' }
Plug 'jgdavey/tslime.vim', { 'for': 'ruby' }
" -----------------------------------------
" HTML, CSS, and JS
Plug 'othree/html5.vim', { 'for': ['html', 'eruby'] }
Plug 'pangloss/vim-javascript'
Plug 'ap/vim-css-color', { 'for': 'css' }
Plug 'hail2u/vim-css3-syntax', { 'for': 'css' }
Plug 'mxw/vim-jsx'
Plug 'mustache/vim-mustache-handlebars'
call plug#end()
" }}}
" Theme
syntax on
set background=dark
colorscheme gruvbox
"
" Neovim!
if has('nvim')
" Make escape work in the Neovim terminal.
tnoremap <Esc> <C-\><C-n>
" Make navigation into and out of Neovim terminal splits nicer.
tnoremap <C-h> <C-\><C-N><C-w>h
tnoremap <C-j> <C-\><C-N><C-w>j
tnoremap <C-k> <C-\><C-N><C-w>k
tnoremap <C-l> <C-\><C-N><C-w>l
" I like relative numbering when in normal mode.
autocmd TermOpen * setlocal conceallevel=0 colorcolumn=0 norelativenumber nonumber
" Prefer Neovim terminal insert mode to normal mode.
autocmd BufEnter term://* startinsert
set inccommand=nosplit
set notagbsearch
else
" When classic Vim is in use
endif
"
" Custom Functions
" ----------
" Restore cursor position, window position, and last search after running a
" command.
function! Preserve(command)
" Save the last search.
let search = @/
" Save the current cursor position.
let cursor_position = getpos('.')
" Save the current window position.
normal! H
let window_position = getpos('.')
call setpos('.', cursor_position)
" Execute the command.
execute a:command
" Restore the last search.
let @/ = search
" Restore the previous window position.
call setpos('.', window_position)
normal! zt
" Restore the previous cursor position.
call setpos('.', cursor_position)
endfunction
" Re-indent the whole buffer.
function! Indent()
call Preserve('normal gg=G')
endfunction
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! Bdi :call DeleteInactiveBufs()
function! DeleteAllBufs()
"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")
"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! Bda :call DeleteAllBufs()
"
" Plugin Configuration
" -- NERDTree
" ---------------------------------------
nmap <C-t> :NERDTreeToggle<CR>
nmap <C-f> :NERDTreeFind<CR>
nmap <leader><C-f> :NERDTreeFocus<CR>
let g:NERDTreeWinSize = 45
" ---------------------------------------
" -- ultisnips
let g:UltiSnipsExpandTrigger="<tab>"
" list all snippets for current filetype
let g:UltiSnipsListSnippets="<leader>usl"
" ---------------------------------------
" -- lightline configj
" ---------------------------------------
let g:lightline = {
\ 'colorscheme': 'one',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'fugitive#head'
\ }
\ }
" ---------------------------------------
" -- CSS Support
" ---------------------------------------
" Plug 'hail2u/vim-css3-syntax'
" ---------------------------------------
" -- vim-jsx
" ---------------------------------------
let g:jsx_ext_required = 0
" ---------------------------------------
" -- Emmet
" ---------------------------------------
let g:user_emmet_expandabbr_key = '<c-e>'
" ---------------------------------------
" -- Indent Guides
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_auto_colors = 0
let g:indent_guides_guide_size = 2
let g:indent_guides_start_level = 2
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=black ctermbg=232
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=darkgrey ctermbg=233
autocmd BufWritePost ~/.dotfiles/* ! chezmoi apply --source-path %
" ---------------------------------------
" -- CoC
" call minpac#add('neoclide/coc.nvim', { 'branch': 'release' })
" nmap <silent> gd <Plug>(coc-definition)
" nmap <silent> gy <Plug>(coc-type-definition)
" nmap <silent> gi <Plug>(coc-implementation)
" nmap <silent> gr <Plug>(coc-references)
" ---------------------------------------
" -- Ale
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? 'OK' : printf(
\ '%dW %dE',
\ all_non_errors,
\ all_errors
\)
endfunction
let g:ale_linters = {
\ 'ruby': ['rubocop', 'ruby'],
\ 'javascript': ['eslint'],
\ 'scss': ['stylelint'],
\ 'css': ['stylelint']
\}
" 'javascript': ['eslint', 'remove_trailing_lines', 'trim_whitespace'],
let g:ale_fixers = {
\ 'javascript': ['eslint'],
\ 'json': ['prettier'],
\ 'ruby': ['rubocop'],
\ 'html': ['remove_trailing_lines', 'trim_whitespace'],
\ 'vue': ['prettier', 'remove_trailing_lines', 'trim_whitespace'],
\ 'scss': ['stylelint', 'remove_trailing_lines', 'trim_whitespace'],
\ 'css': ['stylelint', 'remove_trailing_lines', 'trim_whitespace']
\}
let g:ale_fixer_aliases = { 'erb': 'html' }
let g:ale_fix_on_save = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_enter = 0
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_offset = 50000
nnoremap <leader>lf :ALEFix<CR>
" ---------------------------------------
" -- vim-ruby
let g:ruby_indent_access_modifier_style = 'indent'
let g:rubycomplete_buffer_loading = 1
" Regex used for words, that, at the start of a line, remove a level of indent
setlocal indentkeys+==module_function
let g:indent_access_modifier_regex = '\C^\s*\%(module_function\|protected\|private\)\s*\%(#.*\)\=$''))'
let s:ruby_indent_keywords =
\ '^\s*\zs\<\%(module\||module_function\|class\|if\|for' .
\ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue' .
\ '\|\%(module_function\|public\|protected\|private\)\=\s*def\):\@!\>' .
\ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' .
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>'
" ---------------------------------------
" -- vim-fugitive
" ---------------------------------------
map <leader>gd :Gvdiff<CR>
map <leader>gs :Git<CR>
" Remove fugitive buffers completely when done
autocmd BufReadPost fugitive://* set bufhidden=delete
" ---------------------------------------
" -- vim-rspec
" ---------------------------------------
map <leader>c :call RunCurrentSpecFile()<CR>
map <leader>n :call RunNearestSpec()<CR>
map <leader>l :call RunLastSpec()<CR>
map <leader>a :call RunAllSpecs()<CR>
let g:rspec_command = 'call Send_to_Tmux("be rspec {spec}\n")'
let g:tslime_always_current_session = 1
let g:tslime_always_current_window = 1
" ---------------------------------------
" -- vim-go
" ---------------------------------------
" call minpac#add('fatih/vim-go', { 'type': 'opt' })
let g:go_fmt_command = "goimports"
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_interfaces = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
augroup GoFile
autocmd!
autocmd filetype go nnoremap <leader>rg :! go run %<cr>
augroup END
" ---------------------------------------
" -- Tabularize
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && 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
" ---------------------------------------
" -- fzf
nmap <leader>t :Files<CR>
nmap <leader>b :Buffers<CR>
nmap <leader><S-T> :BTags<CR>
let g:fzf_layout = { 'window': 'enew' }
"
" Highlighting
au BufNewFile,BufRead *.svg set filetype=html
au BufNewFile,BufRead *.sh.tmpl set filetype=gotexttmpl
au BufNewFile,BufRead *.thor set filetype=ruby
au BufNewFile,BufRead *.cap set filetype=ruby
au BufNewFile,BufRead *.erb set filetype=eruby
au BufNewFile,BufRead *.slim setlocal filetype=slim
au BufNewFile,BufRead Gemfile set filetype=ruby
au BufNewFile,BufRead Guardfile set filetype=ruby
au BufNewFile,BufRead Capfile set filetype=ruby
au BufNewFile,BufRead .pryrc set filetype=ruby
au BufNewFile,BufRead pryrc set filetype=ruby
au BufNewFile,BufRead *.{md,markdown,mdown,mkd,mkdn,txt} set filetype=markdown
au BufNewFile,BufRead *.dump set filetype=sql
au BufNewFile,BufRead *.ctp set filetype=php
au BufNewFile,BufRead .stylelintrc set filetype=json
au FileType GO setlocal shiftwidth=2 tabstop=2 noexpandtab
au FileType java setlocal shiftwidth=4
augroup VimCSS3Syntax
autocmd!
autocmd FileType css setlocal iskeyword+=-
augroup END
let &colorcolumn="100"
highlight ColorColumn ctermbg=234 guibg=#2c2d27
"
" System Clipboard
if $TMUX == ''
set clipboard+=unnamed
endif
set pastetoggle=<F2>
"
"
" Mappings
" Resize windows within terminal and tmux
autocmd VimResized * :wincmd =
" ***************************************
" Global Shortcts
" ***************************************
nmap <space> :
nmap <space>w :w!<CR>
nmap ; :
nmap :noh :noh<CR>
nmap :Noh :noh<CR>
" ***************************************
" Text Replacement
" =======================================
" See http://vim.wikia.com/wiki/Replace_a_word_with_yanked_text
" for more information
" ***************************************
nnoremap S "_diwP
vnoremap S "_dP
" Buffer navigation
nmap :bs :buffers<CR>
nmap <leader>w :Bclose<CR>
nmap <leader>W :close<CR>
nmap <leader>q :bwipeout!<CR>
nmap <leader>cb :ene<CR>:bw #<CR>
nmap <leader>lc :lclose<CR>
nmap <leader>lo :lopen<CR>
nmap :clear :Bda<CR>
"
" ***************************************
" File shortcuts
" ***************************************
" -- Reload the current buffer from file on disk
nmap <leader>r :edit!<CR>
" -- Create a horizontal split
nmap <leader>s :sp<CR>
" -- Create a vertical split
nmap <leader>v :vsplit<CR>
nmap <leader><c-s> :exe ':Ag ' . expand('<cword>')<CR>
" Mistyped Commands
" ***************************************
nmap :W :w
nmap :W! :w!
nmap :Q :q
nmap :Q! :q!
nmap :Wq! :wq!
nmap :WQ! :wq!
"
" ***************************************
" A few convenient shortcuts
" ***************************************
" --- Replace all 'hard' tabs with 'soft' tabs
nmap <leader>rt :retab!<Return>
" Managing .vimrc
" ***************************************
nmap <leader>m :source $MYVIMRC<CR>
nmap <leader>ev :e $MYVIMRC<CR>
"
" Sessions
nmap <F2> :source ./session.vim<CR>
nmap <F3> :mks! session.vim<CR>
"
" Local Overrides
if filereadable(expand('~/.vimrc.local'))
source ~/.vimrc.local
endif
if !has('gui_running')
set t_Co=256
endif
" vim: ft=vim fdm=marker