-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.vimrc
executable file
·511 lines (423 loc) · 13.6 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
if !empty(matchstr($MY_RUBY_HOME, 'jruby'))
" let g:ruby_path = '/usr/bin/ruby'
" let g:ruby_path = $HOME . '/.rvm/rubies/ruby-2.5.1/bin/ruby' " Probably deprecated
" Trying rbenv ruby instead:
let g:ruby_path = $HOME . '/Users/ston1x/.rbenv/shims/ruby'
endif
" GENERAL VIM SETTINGS
set number
set noswapfile
set undofile
set norelativenumber
" relativenumber for NERDTree
" let NERDTreeShowLineNumbers=1
" autocmd FileType nerdtree setlocal relativenumber
" Colemak to QWERTY for hjkl
" noremap n j
" noremap e k
" noremap i l
" Clipboard
set clipboard=unnamed
if has('unnamedplus')
set clipboard=unnamed,unnamedplus
endif
set mouse=a
" set laststatus=2
" set laststatus=0
" set ruler rulerformat=%40(%=%<%F%m\ \
" \›\ %{getfsize(@%)}B\ \
" \›\ %l/%L:%v%)
set updatetime=100
" Set leader key
let mapleader = "\<Space>"
" Highlight search results
set incsearch
set hlsearch
" set nowrapscan
" Ignore case when searching
set ignorecase
set smartcase
" Indentation
set tabstop=2
set shiftwidth=2
set expandtab
set encoding=UTF-8
syntax on
set nocompatible " We're running Vim, not Vi!
set backspace=2
filetype on " Enable filetype detection
filetype indent on " Enable filetype-specific indenting
filetype plugin on " Enable filetype-specific plugins
autocmd FileType ruby compiler ruby
" PLUGINS
call plug#begin('~/.vim/plugged')
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
" This renders random symbols for some reason.
" let g:NERDTreeGitStatusIndicatorMapCustom = {
" \ 'Modified' :'📝',
" \ 'Staged' :'+',
" \ 'Untracked' :'❓',
" \ 'Renamed' :'➜',
" \ 'Unmerged' :'═',
" \ 'Deleted' :'❌',
" \ 'Dirty' :'🛠',
" \ 'Ignored' :'☒',
" \ 'Clean' :'✔︎',
" \ 'Unknown' :'⁉️',
" \ }
Plug 'mbbill/undotree'
Plug 'christoomey/vim-tmux-navigator'
Plug 'yggdroot/indentline'
Plug 'tpope/vim-rails'
Plug 'ngmy/vim-rubocop'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-commentary'
Plug 'airblade/vim-gitgutter'
Plug 'k0kubun/vim-open-github'
let g:gitgutter_map_keys = 0
Plug 'vim-scripts/matchit.zip'
runtime macros/matchit.vim
Plug 'mileszs/ack.vim'
Plug 'foosoft/vim-argwrap'
Plug 'godlygeek/tabular'
Plug 'rrethy/vim-illuminate'
Plug 'ap/vim-css-color'
Plug 'mkitt/tabline.vim'
Plug 'w0rp/ale'
" Plug 'vim-airline/vim-airline'
" Plug 'vim-airline/vim-airline-themes'
Plug 'tmm1/ripper-tags'
" Extended visual mode commands
Plug 'vim-scripts/vis'
" Global replace
Plug 'skwp/greplace.vim'
Plug 'ervandew/supertab'
" let g:loaded_ruby_provider = 1
let g:SuperTabDefaultCompletionType = 'context'
let g:SuperTabContextDefaultCompletionType = '<c-n>'
" Highlight
Plug 'vim-ruby/vim-ruby'
Plug 'plasticboy/vim-markdown'
Plug 'slim-template/vim-slim'
" Themes
Plug 'altercation/vim-colors-solarized'
Plug 'morhetz/gruvbox'
Plug 'joshdick/onedark.vim'
Plug 'squarefrog/tomorrow-night.vim'
Plug 'nightsense/seabird'
Plug 'sonph/onehalf'
Plug 'KeitaNakamura/neodark.vim'
Plug 'jeffkreeftmeijer/vim-dim'
Plug 'trevorrjohn/vim-obsidian'
Plug 'kaicataldo/material.vim'
" Ruby blocks selection
Plug 'kana/vim-textobj-user'
Plug 'nelstrom/vim-textobj-rubyblock'
" Comfortable typing
Plug 'junegunn/goyo.vim'
Plug 'reedes/vim-pencil'
" Plug 'vim-latex/vim-latex'
nnoremap <leader>, :Goyo<CR>
nnoremap <leader>u :UndotreeToggle<CR>
augroup pencil
autocmd!
autocmd FileType markdown,mkd,md,yaml :SoftPencil
autocmd FileType text :SoftPencil
augroup END
" javascript
" Plug 'mxw/vim-jsx'
" Plug 'carlitux/deoplete-ternjs', { 'do': 'npm install -g tern' }
" Plug 'pangloss/vim-javascript'
" Rust
Plug 'rust-lang/rust.vim'
Plug 'joukevandermaas/vim-ember-hbs'
" deoplete
if has('nvim')
Plug 'Shougo/deoplete.nvim'
Plug 'fishbullet/deoplete-ruby', { 'for': 'ruby' }
else
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
" let g:deoplete#enable_at_startup = 1
let g:deoplete#max_list = 1
call plug#end()
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown
let g:ackprg = 'ag --nogroup --nocolor --column'
"using rg for find in project
" Search Ruby method under cursor
let g:rg_command = '
\ rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --color "always"
\ -g "*.{coffee,haml,hamlc,js,json,rs,go,rb,py,swift,scss}"
\ -g "!{.git,node_modules,vendor,log,swp,tmp,venv,__pychache__}/*" '
command! -bang -nargs=* F
\ call fzf#vim#grep(g:rg_command .shellescape(<q-args>), 1,
\ fzf#vim#with_preview({'options': '--bind ctrl-a:select-all,ctrl-d:deselect-all'}, 'right:50%', '?'),
\ <bang>0)
nnoremap <leader>f :Rg<CR>
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --ignore-case '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview({'options': '--bind ctrl-a:select-all,ctrl-d:deselect-all --delimiter : --nth 4..'}, 'right:50%:hidden', '?'),
\ <bang>0)
" --delimiter : --nth 4..
command! -bang -nargs=* CustomRg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --ignore-case '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview({'options': '--bind ctrl-a:select-all,ctrl-d:deselect-all'}, 'right:50%:hidden', '?'),
\ <bang>0)
nnoremap <leader>cf :CustomRg<CR>
vnoremap <leader>rg y:Rg <C-R>"<CR>
function! SearchRubyMethodUnderCursor()
let method_name = @"
let concatenated = "def " . method_name
execute ":Rg ". concatenated
endfunction
function! SearchRubyClassUnderCursor()
let class_name = @"
let concatenated = "class " . class_name
execute ":Rg ". concatenated
endfunction
" Find the word under cursor
nnoremap <leader>sw yiw:Rg <C-R>"<CR>
" Find the method under cursor
" nnoremap <leader>sm "def".yiw:Rg <C-R>"<CR>
nnoremap <leader>sm yiw:call SearchRubyMethodUnderCursor()<CR>
" Find the class under cursor
" nnoremap <leader>sc "class".yiw:Rg <C-R>"<CR>
nnoremap <leader>sc yiw:call SearchRubyClassUnderCursor()<CR>
"Mappings
nnoremap ,f :tabnew<CR>
nnoremap ,v :vsplit %<CR>
nnoremap <Leader>q :wq<CR>
nnoremap <Leader>x :q!<CR>
nnoremap <Leader>w :w<CR>
" nnoremap <leader>o :only<CR>
" git
nnoremap <leader>g :Git<CR>
nnoremap <leader>d :Gdiffsplit<CR>
nnoremap <leader>l :Git blame<CR>
nnoremap <leader>co :Commits<CR>
nnoremap <leader>b :Buffers<CR>
nnoremap <leader>h :History<CR>
" Gdiff split always vertical
set diffopt+=vertical
nnoremap <silent> <leader>a :ArgWrap<CR>
nnoremap <leader>t :BTags<CR>
nnoremap <leader>e :edit!<CR>
nnoremap <leader>od :!open '%:p:h'<CR>
nnoremap <F4> :tabedit ~/.vimrc<CR>
nnoremap <F5> :so $MYVIMRC<CR>
nnoremap <F6> :PlugInstall<CR>
nmap <F3> i<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
imap <F3> <C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR>
" Switch between tabs
nnoremap <Leader>1 1gt<CR>
nnoremap <Leader>2 2gt<CR>
nnoremap <Leader>3 3gt<CR>
nnoremap <Leader>4 4gt<CR>
nnoremap <Leader>5 5gt<CR>
nnoremap <Leader>6 6gt<CR>
nnoremap <Leader>7 7gt<CR>
nnoremap <Leader>8 8gt<CR>
nnoremap <Leader>9 9gt<CR>
nnoremap <Leader><Left> gT<CR>
nnoremap <Leader><Right> gt<CR>
" Resizing splits
noremap <up> <C-W>+
noremap <down> <C-W>-
noremap <left> 3<C-W><
noremap <right> 3<C-W>>
" Hide those annoying search highlihghts
nnoremap cc :let @/ = ""<cr>
" binding.pry
function! InsertBindingPry()
execute ':normal! o' . "binding.pry"
endfunction
function! InsertBindingRemotePry()
execute ':normal! o' . "binding.remote_pry"
endfunction
nnoremap ,bp :call InsertBindingPry() <CR>
nnoremap ,br :call InsertBindingRemotePry() <CR>
" NERDTree
function! MyNerdToggle()
if &filetype == 'nerdtree' || &filetype == ''
:NERDTreeToggle
else
:NERDTreeFind
endif
endfunction
nnoremap \ :call MyNerdToggle()<CR>
let NERDTreeShowHidden=1
" Run ruby files
" autocmd FileType ruby nmap <leader>r :!ruby %<cr>
" Linting with ale
let g:ale_linters = {'ruby': ['rubocop']}
let g:ale_sign_column_always = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_insert_leave = 1
let g:ale_pattern_options = {'.*\.gem.*\.rb$|.*\.rubies.*\.rb$': {'ale_enabled': 1}}
let g:ale_set_highlights = 0
" Remove trailing spaces on save
autocmd BufWritePre * :%s/\s\+$//e
" fzf
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit'
\}
nnoremap <C-p> :FZF -m<CR>
" Fold
set foldenable
set foldlevelstart=99
set foldmethod=indent " foldmethod=syntax is slow
nnoremap <leader>z zMzv
" Markdown
" Table Of Contents (TOC)
nnoremap <leader>v :Toch<CR>
function! MarkdownConcealToggle()
if(&conceallevel == 2)
set conceallevel=0
else
set conceallevel=2
endif
endfunction
nnoremap <leader>c :call MarkdownConcealToggle()<CR>
" disable by default
let g:vim_markdown_conceal = 0
let g:vim_markdown_conceal_code_blocks = 0
"Tags
noremap <leader>rt :silent !ripper-tags -R --exclude=log
set shell=zsh
set tags+=.git/tags,.git/rubytags,.git/bundlertags
set tagcase=match
noremap ,gt :!gentags<CR>
" Convert slashes to backslashes for Windows.
if has('win32')
nmap <Leader>cs :let @+=substitute(expand("%"), "/", "\\", "g")<CR>
nmap <Leader>cl :let @+=substitute(expand("%:p"), "/", "\\", "g")<CR>
" This will copy the path in 8.3 short format, for DOS and Windows 9x
nmap <Leader>c8 :let @+=substitute(expand("%:p:8"), "/", "\\", "g")<CR>
else
nmap <Leader>cs :let @+=expand("%")<CR>
nmap <Leader>cl :let @+=expand("%:p")<CR>
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SWITCH BETWEEN TEST AND PRODUCTION CODE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! OpenTestAlternate()
let new_file = AlternateForCurrentFile()
exec ':e ' . new_file
endfunction
function! OpenTestAlternateSplit()
let new_file = AlternateForCurrentFile()
exec ':vsp ' . 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, '\<lib\>') != -1 || match(current_file, '\<workers\>') != -1 || match(current_file, '\<views\>') != -1 || match(current_file, '\<helpers\>') != -1 || match(current_file, '\<services\>') != -1 || match(current_file, '\<lib\>') != -1 || match(current_file, '\<finders\>') != -1
if going_to_spec
if in_app
let new_file = substitute(new_file, '^app/', '', '')
end
let new_file = substitute(new_file, '\.e\?rb$', '_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>s :call OpenTestAlternate()<cr>
nnoremap <leader>s. :call OpenTestAlternateSplit()<cr>
" Theming
function! ColorToggle()
if(&background == "dark")
set background=light
else
set background=dark
endif
endfunction
map <Leader>m :call ColorToggle()<CR>
" Set theme
let g:solarized_bold=1
set cursorline
" set termguicolors
colo gruvbox
set bg=dark
" Make left gutter bar not grey
autocmd ColorScheme * highlight! link SignColumn LineNr
" let g:neodark#terminal_transparent = 1
" let g:airline_theme='zenburn'
let g:gruvbox_contrast_dark='medium'
let g:gruvbox_bold=1
syntax enable
"Commands
command! Symbolicate :%s/"\([a-z_]\+\)"/:\1/gc
command! Stringify :%s/:\([a-z_]\+\)/"\1"/gc
command! SpecFormatFix :%s/:\([a-z_]\+\)=>/\1: /gc
command! NewHash :%s/"\([^=,'"]*\)"\s\+=> /\1: /gc
command! OldHash :%s/\(\w*\): \(\w*\)/"\1" => \2/gc
" Taking notes
command! Scratch :tabedit ~/tmp/note.md
command! Notes :tabedit ~/tmp/notes.md
command! ParseFix :s/\\u0001/\r/g
command! ParseFix2 :s/\A^/\r/g
" Notepad
command! Notepad :vsplit ~/tmp/notepad.md
nnoremap <Leader>n :Notepad<CR>
" Tabular
vmap ,: :Tabularize /:\zs/l0l1<CR>
vmap ,": :Tabularize /":\zs/l0l1<CR>
vmap ,= :Tabularize /=<CR>
vmap ,=> :Tabularize /=/l1l1<CR>
" Runinng tests
command! -nargs=* VT vsplit | terminal <args>
command! -nargs=* ST split | terminal <args>
nnoremap <leader>. :call OpenTestAlternate()<cr>
nnoremap <leader>s. :call OpenTestAlternateSplit()<cr>
function! RunTests(filename)
" Write the file and run tests for the given filename
:w
:silent !echo;echo;echo;echo;echo
exec ":ST time bundle exec rspec " . a:filename
endfunction
function! SetTestFile()
" Set the spec file that tests will be run for.
let t:grb_test_file=@%
endfunction
function! RunTestFile(...)
if a:0
let command_suffix = a:1
else
let command_suffix = ""
endif
" Run the tests for the previously-marked file.
let in_spec_file = match(expand("%"), '_spec.rb$') != -1
if in_spec_file
call SetTestFile()
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file . command_suffix)
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number)
endfunction
" Run this file
map ,m :call RunTestFile()<cr>
" Run only the example under the cursor
map ,. :call RunNearestTest()<cr>
" Run all test files
map ,a :call RunTests('spec')<cr>