forked from r00k/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
617 lines (512 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
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
set nocompatible "Use Vim's default settings, not Vi's
" comment out to see if it is needed otherwise remove soon™
" filetype off "required by vundle
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/bundle')
Plug 'dstein64/vim-startuptime'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'edkolev/tmuxline.vim'
Plug 'kchmck/vim-coffee-script'
Plug 'tpope/vim-cucumber'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-dispatch'
Plug 'vim-ruby/vim-ruby'
Plug 'koron/nyancat-vim'
Plug 'vim-scripts/ruby-matchit'
Plug 'godlygeek/tabular'
Plug 'AndrewRadev/ack.vim'
Plug 'vim-scripts/ScrollColors'
Plug 'ngmy/vim-rubocop'
Plug 'Lokaltog/vim-easymotion'
Plug 'wavded/vim-stylus'
Plug 'mattn/gist-vim'
Plug 'rust-lang/rust.vim'
Plug 'junegunn/fzf.vim'
Plug 'hashivim/vim-terraform'
Plug 'zhaocai/GoldenView.Vim'
Plug 'will133/vim-dirdiff'
Plug 'fatih/vim-go'
Plug 'xolox/vim-notes'
Plug 'xolox/vim-misc'
Plug 'dense-analysis/ale'
Plug 'slim-template/vim-slim'
" nvim specific plugins, will migrate/refactor slowly to
" split structure
if has('nvim')
Plug 'numToStr/Comment.nvim'
" lsp
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'neovim/nvim-lspconfig'
Plug 'simrat39/rust-tools.nvim'
" Completion
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-nvim-lua'
Plug 'hrsh7th/cmp-nvim-lsp-signature-help'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-calc'
" Snippets
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/cmp-vsnip'
Plug 'rafamadriz/friendly-snippets'
" treesitter
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'JoosepAlviste/nvim-ts-context-commentstring'
"themes
Plug 'tanvirtin/monokai.nvim'
Plug 'morhetz/gruvbox'
Plug 'nvim-tree/nvim-tree.lua'
Plug 'norcalli/nvim-colorizer.lua'
Plug 'lewis6991/gitsigns.nvim'
Plug 'zbirenbaum/copilot.lua'
Plug 'zbirenbaum/copilot-cmp'
Plug 'numToStr/FTerm.nvim'
else
Plug 'tomtom/tcomment_vim'
Plug 'ervandew/supertab'
"snipmate stuff
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'tomtom/tlib_vim'
Plug 'honza/vim-snippets'
Plug 'garbas/vim-snipmate'
Plug 'scrooloose/nerdtree'
endif
call plug#end()
augroup myfiletypes
" Clear old autocmds in group
autocmd!
" autoindent with two spaces, always expand tabs
autocmd FileType ruby,eruby,yaml set ai sw=2 sts=2 et
" autoindent with four spaces, always expand tabs
autocmd FileType php,python set ai sw=4 sts=4 et
" autoindent with tab, never expand tabs
autocmd FileType go set ai sw=8 sts=8
augroup END
" ================
let mapleader = ","
if has('nvim')
lua require('mine.lsp')
lua require('mine.cmp')
lua require('mine.treesitter')
lua require('mine.comment')
lua require('mine.tree')
lua require('mine.colors')
lua require('mine.gitsigns')
lua require('mine.copilot')
lua require('mine.fterm')
endif
vmap <Leader>b :<C-U>!git blame <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p <CR>
map <Leader>bb :!bundle install<cr>
nmap <Leader>bi :source ~/.vimrc<cr>:PlugInstall<cr>
vmap <Leader>be "td?describe<cr>obed<tab><esc>"tpkdd/end<cr>o<esc>:nohl<cr>
map <Leader>cu :Tabularize /\|<CR>
map <Leader>cc :Rjcollection client/
map <Leader>cj :Rjspec client/
map <Leader>cm :Rjmodel client/
map <Leader>ct :Rtemplate client/
map <Leader>cv :Rjview client/
map <Leader>d obyebug<cr>puts 'byebug'<esc>:w<cr>
map <Leader>ec :e ~/play/
map <Leader>gac :Git commit -m -a ""<LEFT>
map <Leader>gc :Git commit -m ""<LEFT>
map <Leader>gr :Ag<SPACE>
map <Leader>gs :Git status<CR>
map <Leader>gd :Gitsigns diffthis<CR>
map <Leader>gb :Gitsigns blame_line<CR>
map <Leader>glb :Gitsigns toggle_current_line_blame<CR>
map <Leader>f :call OpenFactoryFile()<CR>
map <Leader>fix :cnoremap % %<CR>
map <Leader>i mmgg=G`m<CR>
map <Leader>l oconsole.log 'debugging'<esc>:w<cr>
map <Leader>m :Rmodel
map <Leader>o :call RunCurrentLineInTest()<CR>
map <Leader>p :set paste<CR>"*]p:set nopaste<cr>
map <Leader>P :set paste<CR>"*]P:set nopaste<cr>
map <Leader>ra :%s/
map <Leader>rd :!bundle exec rspec % --format documentation<CR>
map <Leader>rs :vsp <C-r>#<cr><C-w>w
map <Leader>rt :retab<CR>
map <Leader>rw :%s/\s\+$//<cr>:w<cr>
map <Leader>sg :sp<cr>:grep
map <Leader>sm :RSmodel
map <Leader>sp yss<p>
map <Leader>sn :e ~/.vim/snippets/ruby.snippets<CR>
map <Leader>so :so %<cr>
map <Leader>sq j<c-v>}klllcs<esc>:wq<cr>
map <Leader>ss ds)i <esc>:w<cr>
map <Leader>st :!ruby -Itest % -n "//"<left><left>
map <Leader>su :RSunittest
map <Leader>sv :RSview
map <Leader>t :w<cr>:call RunCurrentTest()<CR>
map <Leader>y "+y
map <Leader>fy :%y+<cr>
map <Leader>u :Runittest<cr>
map <Leader>vc :RVcontroller<cr>
map <Leader>vf :RVfunctional<cr>
map <Leader>vg :vsp<cr>:grep
map <Leader>vu :RVunittest<CR>
map <Leader>vm :RVmodel<cr>
map <Leader>vv :RVview<cr>
map <Leader>w <C-w>w
map <Leader>x :exec getline(".")<cr>
" Temprorary while migrating stuff over to nvim config file
if has('nvim')
map <Leader>my :sp ~/.vimrc<cr>
map <Leader>ml :sp ~/.vim/lua/mine/vimrc.lua<CR>
else
map <Leader>my :sp $MYVIMRC<cr>
endif
map <Leader>r :call RunCurrentFile()<CR>
map <Leader>rp :w<cr> :!python %<cr>
map <Leader>op :call OpenFileFolder()<CR>
map <Leader>fm :RustFmt<CR>
map <Leader>rb :RuboCop %<CR>
" Edit another file in the same directory as the current file
" uses expression to extract path from current file's path
map <Leader>e :e <C-R>=expand("%:p:h") . '/'<CR>
map <Leader>s :split <C-R>=expand("%:p:h") . '/'<CR>
map <Leader>v :vnew <C-R>=expand("%:p:h") . '/'<CR>
map <C-h> :nohl<cr>
imap <C-l> :<Space>
map <C-s> :w<CR>
imap <C-s> <esc>:w<CR>
map <C-t> <esc>:tabnew<CR>
map <C-x> <C-w>c
noremap <C-n> :cn<CR>
map <C-p> :cp<CR>
imap jk <esc>
map <C-b> <C-u>
" Emacs-like beginning and end of line.
imap <c-e> <c-o>$
imap <c-a> <c-o>^
set nocompatible
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set history=500 " keep 500 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set autoindent
set showmatch
set nowrap
set backupdir=~/.tmp
set directory=~/.tmp " Don't clutter my dirs up with swp and tmp files
set autoread
set wmh=0
set viminfo+=!
set guioptions-=T
set guifont=Source\ Code\ Pro\ for\ Powerline:h23
set et
set sw=2
set smarttab
set incsearch
set ignorecase smartcase
set laststatus=2 " Always show status line.
set relativenumber
set gdefault " assume the /g flag on :s substitutions to replace all matches in a line
set autoindent " always set autoindenting on
set bg=light
" Set the tag file search order
set tags=./tags;
" Use Silver Searcher instead of grep
set grepprg=ag\ --ignore-dir=tags
" Make the omnicomplete text readable
:highlight PmenuSel ctermfg=black
"TODO REMOVE OR MIGRATE TO FZF since fuzzy is not used
"Fuzzy finder: ignore stuff that can't be opened, and generated files
let g:fuzzy_ignore = "*.png;*.PNG;*.JPG;*.jpg;*.GIF;*.gif;vendor/**;coverage/**;tmp/**;rdoc/**"
" Highlight the status line
highlight StatusLine ctermfg=blue ctermbg=yellow
" " Format xml files
" au FileType xml exe ":silent 1,$!xmllint --format --recover - 2>/dev/null"
set shiftround " When at 3 spaces and I hit >>, go to 4, not 5.
set nofoldenable " Say no to code folding...
command! Q q " Bind :Q to :q
command! Qall qall
command! ICantTakeThisAnymore !subl %
" Disable Ex mode
map Q <Nop>
" Disable K looking stuff up
map K <Nop>
" When loading text files, wrap them and don't split up words.
au BufNewFile,BufRead *.txt setlocal wrap
au BufNewFile,BufRead *.txt setlocal lbr
" Better? completion on command line
set wildmenu
" What to do when I press 'wildchar'. Worth tweaking to see what feels right.
set wildmode=list:full
" (Hopefully) removes the delay when hitting esc in insert mode
" Get rid of the delay when hitting esc!
if !has('nvim')
set noesckeys
endif
" set ttimeout
" set ttimeoutlen=1
" Turn on spell-checking in markdown and text.
" au BufRead,BufNewFile *.md,*.txt setlocal spell
" Merge a tab into a split in the previous window
function! MergeTabs()
if tabpagenr() == 1
return
endif
let bufferName = bufname("%")
if tabpagenr("$") == tabpagenr()
close!
else
close!
tabprev
endif
split
execute "buffer " . bufferName
endfunction
nmap <C-W>u :call MergeTabs()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Test-running stuff
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! RunCurrentTest()
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFile()
if match(expand('%'), '\.feature$') != -1
call SetTestRunner("!cucumber")
exec g:bjo_test_runner g:bjo_test_file
elseif match(expand('%'), '_spec\.rb$') != -1
call SetTestRunner("!bundle exec rspec")
exec g:bjo_test_runner g:bjo_test_file
else
call SetTestRunner("!ruby -Itest")
exec g:bjo_test_runner g:bjo_test_file
endif
else
exec g:bjo_test_runner g:bjo_test_file
endif
endfunction
function! SetTestRunner(runner)
let g:bjo_test_runner=a:runner
endfunction
function! RunCurrentLineInTest()
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFileWithLine()
end
exec "!bundle exec rspec" g:bjo_test_file . ":" . g:bjo_test_file_line
endfunction
function! SetTestFile()
let g:bjo_test_file=@%
endfunction
function! SetTestFileWithLine()
let g:bjo_test_file=@%
let g:bjo_test_file_line=line(".")
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has('nvim')
function! OpenNvimTree()
if bufname("%") == ""
execute ":NvimTreeToggle"
else
execute ":NvimTreeFindFileToggle"
end
endfunction
map <Leader>nr :call OpenNvimTree()<CR>
else
function! OpenNerdTree()
if bufname("%") == ""
execute ":NERDTree"
else
execute ":NERDTreeFind"
end
endfunction
map <Leader>nr :call OpenNerdTree()<CR>
endif
function! ToggleDiff()
if &diff
execute ":diffoff!"
else
execute ":windo diffthis"
end
endfunction
map <Leader>df :call ToggleDiff()<CR>
function! RunCurrentFile()
write
if &ft == "ruby"
execute ":!ruby %"
elseif &ft == "python"
execute ":!python %"
elseif &ft == "rust"
execute ":RustRun"
endif
endfunction
function! OpenFileFolder()
let file_folder = expand('%:p:h')
silent exec "!open" file_folder
redraw!
endfunction
inoremap <Tab> <C-P>
" Let's be reasonable, shall we?
nmap k gk
nmap j gj
" Don't add the comment prefix when I hit enter or o/O on a comment line.
set formatoptions-=or
" Don't wait so long for the next keypress (particularly in ambigious Leader
" situations.
set timeoutlen=500
" Don't go past 100 chars on levelup:
autocmd BufNewFile,BufRead /Users/ben/code/levelup/*.rb set colorcolumn=100
" Remove trailing whitespace on save for ruby,sass,haml,coffeescript,yaml files.
au BufWritePre *.rb,*.scss,*.haml,*.coffee,*.sql,*.tf,*.yml :%s/\s\+$//e
" Create a directory if it doesn't exist when writing the file
" https://travisjeffery.com/b/2011/11/saving-files-in-nonexistent-directories-with-vim/
augroup vimrc-auto-mkdir
autocmd!
autocmd BufWritePre * call s:auto_mkdir(expand('<afile>:p:h'), v:cmdbang)
function! s:auto_mkdir(dir, force)
if !isdirectory(a:dir)
\ && (a:force
\ || input("'" . a:dir . "' does not exist. Create? [y/N]") =~? '^y\%[es]$')
call mkdir(iconv(a:dir, &encoding, &termencoding), 'p')
endif
endfunction
augroup END
function! OpenFactoryFile()
if filereadable("test/factories.rb")
execute ":sp test/factories.rb"
else
execute ":sp spec/factories.rb"
end
endfunction
" Set gutter background to black
" highlight SignColumn ctermbg=black
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RENAME CURRENT FILE (thanks Gary Bernhardt)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
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>rn :call RenameFile()<cr>
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" 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
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
endif " has("autocmd")
" Color
set t_Co=256
set background=dark
" Testing it not sure if it will stay
" set termguicolors
let g:NERDTreeDirArrows = 0
if has('nvim')
" colorscheme monokai
let g:gruvbox_contrast_dark = 'hard'
colorscheme gruvbox
else
let g:molokai_original = 1
colorscheme molokai
endif
set cursorline
au WinLeave * set nocursorline
au WinEnter * set cursorline
"fzf
set rtp+=/usr/local/opt/fzf
let g:fzf_layout = { 'up': '~50%' }
" enable per command fzf
" ctrl-n and ctrl-p are rebound to go next/previous in history
let g:fzf_history_dir= '~/.tmp/fzf-history'
map <Leader>h :Files<CR>
command! -bang -nargs=* Find call fzf#vim#grep('/usr/bin/rg --column --line-number --no-heading --fixed-strings --ignore-case -ignore --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>), 1, <bang>0)
"notes
let g:notes_directories = ['~/notes']
"airline
let g:airline_theme = 'powerlineish'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:Powerline_symbols = 'fancy'
let g:airline_exclude_filetypes=['netrw','diff','undotree','gundo','tagbar']
let g:airline_linecolumn_prefix = ' '
let g:airline_section_z='%3p%% '.g:airline_linecolumn_prefix.'%3l:%c'
let g:airline_detect_whitespace=0 " turn off the whitespace extension
"enable/disable showing a summary of changed hunks under source control.
let g:airline#extensions#hunks#enabled = 1
"enable/disable showing only non-zero hunks.
let g:airline#extensions#hunks#non_zero_only = 1
"set hunk count symbols.
let g:airline#extensions#hunks#hunk_symbols = ['+', '~', '-']
let g:airline#extensions#tmuxline#enabled = 0
let g:vimrubocop_config = '~/.rubocop.yml'
let g:rustfmt_autosave = 1
nnoremap <Leader>H :call<SID>LongLineHLToggle()<cr>
hi OverLength ctermbg=none cterm=none
match OverLength /\%>80v/
fun! s:LongLineHLToggle()
if !exists('w:longlinehl')
let w:longlinehl = matchadd('ErrorMsg', '.\%>80v', 0)
echo "Long lines highlighted"
else
call matchdelete(w:longlinehl)
unl w:longlinehl
echo "Long lines unhighlighted"
endif
endfunction
" Run goimports along gofmt on each save
let g:go_fmt_command = "goimports"
" Automatically get signature/type info for object under cursor
let g:go_auto_type_info = 1
" Conflicting with <C-n>/<C-p> mappings already set
let g:goldenview__enable_default_mapping = 0
nmap <silent> <C-L> <Plug>GoldenViewSplit
if !has('nvim')
" Use the new snipmate parser to get rid of deprecation warning
let g:snipMate = { 'snippet_version' : 1 }
endif
" ale linting config
let g:ale_linters = {
\ 'ruby': ['rubocop', 'ruby'],
\ 'python': ['flake8'],
\ 'javascript': ['eslint', 'prettier']
\}
let g:ale_fixers = {
\ 'ruby': ['rubocop'],
\}
let g:ale_lint_on_text_changed = 0
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_enter = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_set_balloons = 1