-
Notifications
You must be signed in to change notification settings - Fork 7
/
.vimrc
1417 lines (1136 loc) · 39.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
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" VIM-PLUG
" automatic installation of vim-plug if it's not installed
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
" plugins
call plug#begin('~/.vim/plugged')
" file finder
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" file navigation/management
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-vinegar'
Plug 'pbrisbin/vim-mkdir'
" git related
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-git'
" colors (parenthesis, css colors, etc.)
Plug 'luochen1990/rainbow'
Plug 'chrisbra/Colorizer'
" Ruby related
Plug 'ecomba/vim-ruby-refactoring'
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-rake'
" text objects
Plug 'kana/vim-textobj-user'
Plug 'nelstrom/vim-textobj-rubyblock'
Plug 'bootleq/vim-textobj-rubysymbol'
Plug 'michaeljsmith/vim-indent-object'
Plug 'wellle/targets.vim'
if has("nvim")
Plug 'neovim/nvim-lspconfig'
" code completion (nvim only)
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
" code formatting
Plug 'stevearc/conform.nvim'
" AI code completion
Plug 'zbirenbaum/copilot.lua'
Plug 'nvim-lua/plenary.nvim'
Plug 'CopilotC-Nvim/CopilotChat.nvim', { 'branch': 'canary' }
" Syntax highlighting
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" text editing improvements
Plug 'gbprod/substitute.nvim'
Plug 'JoosepAlviste/nvim-ts-context-commentstring'
else
" Regular VIM
" code completion (vim only)
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
" AI code completion
Plug 'github/copilot.vim'
endif
" syntax highlighting (vim/nvim)
Plug 'vim-ruby/vim-ruby'
Plug 'keith/rspec.vim'
Plug 'pangloss/vim-javascript'
Plug 'AndrewRadev/vim-jsx-pretty'
Plug 'styled-components/vim-styled-components', { 'branch': 'main' }
" grepping files from vim
Plug 'mileszs/ack.vim'
" text editing improvements
Plug 'AndrewRadev/splitjoin.vim'
Plug 'godlygeek/tabular'
Plug 'terryma/vim-multiple-cursors'
Plug 'suy/vim-context-commentstring'
Plug 'tpope/vim-commentary'
Plug 'itspriddle/vim-stripper'
" general vim improvements
Plug 'andymass/vim-matchup'
Plug 'sickill/vim-pasta'
Plug 'mbbill/undotree'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-endwise'
Plug 'alvan/vim-closetag'
Plug 'LunarWatcher/auto-pairs'
Plug 'junegunn/vim-peekaboo'
Plug 'tpope/vim-ragtag'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-speeddating'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'justinmk/vim-sneak'
Plug 'lambdalisue/suda.vim'
Plug 'nelstrom/vim-visual-star-search'
Plug 'bogado/file-line'
Plug 'pechorin/any-jump.vim'
" statusline (and related)
Plug 'itchyny/lightline.vim'
Plug 'airblade/vim-gitgutter'
call plug#end()
" BASIC SETTINGS
" no vi compatible mode
set nocompatible
" syntax highlight on
syntax on
" when determining syntax highlighting for the current line, always look at the entire file
augroup ResetSyntaxHighlighting
autocmd!
autocmd BufNewFile,BufRead,BufEnter * syntax sync fromstart
augroup END
" syntax coloring up until column number
set synmaxcol=300
" you can change buffers without saving
set hidden
" do not autoresize windows
set noequalalways
" Resize splits when the window is resized
autocmd VimResized * :wincmd =
" split below/right
set splitbelow
set splitright
" no backup files
set nobackup
set nowritebackup
" show line numbers
set number
set numberwidth=2
" also show relative numbers, besides current line (Vim 7.4+)
set relativenumber
" highlight searches
set hlsearch
" find as you type
set incsearch
" smartcase -- normally ignores case, but when we type uppercase character in search box it will be CASE SENSITIVE
set ignorecase smartcase
" always display current cursor position
set ruler
" make it obvious where the textwidth is
set colorcolumn=+1
" display incomplete commands
set showcmd
" lazy redraw the screen
set lazyredraw
" explicitly set ttyfast
set ttyfast
" 256-color VIM
set t_Co=256
" colorscheme
colorscheme beautiful256
" enable 24-bit colors in the terminal
set termguicolors
" GUI settings (MacVIM/gVim)
if has("gui_running")
" encoding
set encoding=utf-8
" Windows
if has("win32")
" font
set guifont=DejaVu_Sans_Mono:h10:cEASTEUROPE
" simulate alt key behaviour
autocmd GUIEnter * simalt ~s
" use shellslash
set shellslash
" MacOS
elseif has("mac")
" font
set guifont=DejaVu\ Sans\ Mono\ for\ Powerline:h14
" disable scrollbars in MacVim
set guioptions=
" default window size
set columns=248
set lines=87
" special font configuration for neovide
if exists("g:neovide")
set guifont=DejaVu\ Sans\ Mono\ for\ Powerline:h14:#e-subpixelantialias:#h-full
endif
" Unix/Linux
elseif has("unix")
" font
set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 10
" window position / size
winpos 70 40
winsize 140 50
" set English language in Vim's UI
language en_US.utf8
language messages en_US.utf8
endif
endif
" enable filetype detection and filetype-specific plugins and indenting
filetype plugin indent on
" do not wrap lines
set nowrap
" wrap around beginning and end of file when searching
set wrapscan
" autoindent
set autoindent
" by default TABS are standard 8 characters filled with SPACES (expandtab) with softtabstop at 2 (TAB moves 2 characters); indent stays at 2 characters (shiftwidth)
set tabstop=8
set softtabstop=2
set shiftwidth=2
set expandtab
" round indent to multiple of 'shiftwidth' (applies to > and < commands)
set shiftround
" set virtual edit only when in visual block selection mode
set virtualedit=block
" the /g flag on :s substitutions by default
set gdefault
" keep 3 lines (top/bottom) for scope when scrolling
set scrolloff=3
set sidescrolloff=3
" avoid moving cursor to BOL when jumping around
set nostartofline
" briefly jump to a parenthesis once it's balanced (but only for 200ms)
set showmatch
set matchtime=2
" keep longer vim commands history
set history=500
" show available TAB-completions in command line
set wildmenu
" have TAB-completion behave similarly to a shell (i.e. complete the longest part, then cycle through the matches)
set wildmode=longest:full,full
" ignore these files and directories when completing names and in Explorer
set wildignore=*.o,*.out,*.obj,.git,*.rbc,*.class,.svn,*.gem " output & scm files
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz " archive files
set wildignore+=*.jpg,*.jpeg,*.png,*.xpm,*.gif,*.bmp " pictures
set wildignore+=public/* " rails/gatsby public
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/* " bundler and sass
set wildignore+=*/node_modules/* " node modules
set wildignore+=*/log/*,*.log,*/coverage/* " logs and rcov
set wildignore+=*.swp,*~,._* " swp and backup files
set wildignore+=*/.cache/* " gatsby cache
" short messages in command line (so that they don't overflow and require pressing <ENTER>) (h :shortmess)
set shortmess=acoOtI
" disable visual/audible bells
set noerrorbells
set visualbell
set t_vb=
autocmd GUIEnter * set vb t_vb=
" time out on key codes but not on mappings
set notimeout
set ttimeout
set ttimeoutlen=5
" allow backspacing over autoindent, EOL, and BOL
set backspace=2
" never write unless requested
set noautowrite
set noautowriteall
" never automatically re-read files changed outside of vim
set noautoread
" write swap files after some inactivity [ms] (will trigger coc)
" cannot be too low, otherwise eslint messages will be disappearing
set updatetime=500
" global directory for .swp files
set directory=$HOME/.vim/tmp/
" yes/no/cancel prompt if closing with unsaved changes
set confirm
" persistent undo (preserved after restarting vim) (separate between vim/nvim due to incompatibilities)
set undofile
if has("nvim")
set undodir=$HOME/.vim/undo-nvim/
else
set undodir=$HOME/.vim/undo-vim/
endif
" mouse support in xterm
set mouse=a
" inverse space as a vsplit character (instead of |)
set fcs+=vert:\ " the space after the backslash is intentional
" always start on first line when editing git commit message
autocmd FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
" automatically open files in read-only mode if swapfile exists
augroup NoSimultaneousEdits
autocmd!
autocmd SwapExists * let v:swapchoice = 'o'
autocmd SwapExists * echohl ErrorMsg
autocmd SwapExists * echo 'Duplicate edit session (readonly)'
autocmd SwapExists * echohl None
autocmd SwapExists * sleep 1
augroup END
" netrw configuration sort files case insensitive
let g:netrw_sort_options = "i"
" netrw 1 level of dir history (more performance)
let g:netrw_dirhistmax = 1
" fast directory browsing
let g:netrw_fastbrowse = 2
" tree style listing
let g:netrw_liststyle = 3
" add path for tags created by git hooks
set tags+=.git/tags
" cursor shape
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
" explicit window separator
set fillchars+=vert:▊
" set ruby for neovim/goneovim/VimR using chruby
let g:ruby_host_prog = '~/bin/chruby-wrapper'
" set python3 for neovim
if executable('/opt/homebrew/bin/python3')
let g:python3_host_prog = '/opt/homebrew/bin/python3'
endif
" neovide.dev
if exists("g:neovide")
" disable all animations
let g:neovide_position_animation_length = 0
let g:neovide_cursor_animation_length = 0
let g:neovide_scroll_animation_far_lines = 0
let g:neovide_scroll_animation_length = 0
endif
" FILE TYPES
" set fixed columns only for some file types
autocmd FileType * setlocal textwidth=0
autocmd FileType ruby,eruby,javascript,javascript.jsx,javascript.tsx,vue,css,scss setlocal textwidth=80
autocmd FileType gitcommit setlocal textwidth=72
" set various characters to be treated as a part of words
autocmd FileType lisp,clojure,html,xml,xhtml,haml,eruby,css,scss,sass,less,javascript,javascript.jsx,javascript.tsx,coffee,yaml setlocal iskeyword+=-,$,#
autocmd FileType scss,sass,less,ruby,eruby setlocal iskeyword+=@
augroup filetypedetect
" YAML files read as Ruby
autocmd BufNewFile,BufRead {*.yml} setfiletype eruby
" ActiveAdmin views read as Ruby
autocmd BufNewFile,BufRead {*.arb} setfiletype ruby
" 2 spaces for TAB in JS/CSS/HTML files
autocmd BufNewFile,BufRead {*.css,*.scss,*.sass,*.html,*.html.erb,*.js,*.jsx,*.tsx,*.svg} setlocal softtabstop=2 tabstop=2 shiftwidth=2
" explicitly set filetype to Ruby for some well-known files
autocmd BufNewFile,BufRead {Gemfile,Rakefile,Vagrantfile,Thorfile,Procfile,Capfile,Guardfile,.Guardfile,config.ru,importmap,.railsrc,.irbrc,.pryrc} set filetype=ruby
" explicitly set filetype to shell for dotenv's files
autocmd BufRead,BufNewFile {.env.development.local,.env.production,.env.sample,.env.test} set filetype=sh
" explicitly set filetype to slim for slim view files (not sure why it's needed...)
autocmd BufNewFile,BufRead {*.html.slim} set filetype=slim
" explicitly set filetype to JSON for some well-known files
autocmd BufNewFile,BufRead {.prettierrc} set filetype=json
" set filetype for React files
autocmd BufNewFile,BufRead {*.jsx} set filetype=javascript.jsx
" set filetype for Typescript files
autocmd BufNewFile,BufRead {*.tsx} set filetype=javascript.tsx
" [rspec.vim] fix filetype set by rspec.vim
autocmd BufNewFile,BufRead *_spec.rb,*_shared_examples.rb,*_shared_context.rb set filetype=ruby syntax=rspec
augroup END
" ADVANCED SETTINGS
" reposition the cursor in the buffer after reopening vim
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" ABBREVIATIONS
abbreviate apge page
abbreviate glboal global
abbreviate ilke like
abbreviate invitaion invitation
abbreviate invitaiton invitation
abbreviate invitatoin invitation
abbreviate pgae page
abbreviate recieve receive
abbreviate sgined signed
abbreviate taht that
abbreviate teh the
abbreviate tewak tweak
abbreviate upadting updating
abbreviate coudln couldn
" Rails specific
abbreviate bpr binding.pry;
abbreviate brp binding.pry;
" KEY MAPPINGS
" have Y behave analogously to D and C rather than to dd and cc (which is already done by yy)
noremap Y y$
" swap ` with ' (so that ' will jump to line *and* column)
nnoremap ' `
nnoremap ` '
" scroll faster & move cursor too
nnoremap <c-e> 3<c-e>3j
nnoremap <c-y> 3<c-y>3k
vnoremap <c-e> 3<c-e>3j
vnoremap <c-y> 3<c-y>3k
" move faster between windows
nmap <c-h> <c-w>h
nmap <c-j> <c-w>j
nmap <c-k> <c-w>k
nmap <c-l> <c-w>l
" resize window
nmap <C-S-h> <C-w><
nmap <C-S-l> <C-w>>
nmap <C-S-k> <C-w>+
nmap <C-S-j> <C-w>-
" improve movement on wrapped lines
nnoremap j gj
nnoremap k gk
nnoremap $ g$
nnoremap ^ g^
nnoremap 0 g0
vnoremap j gj
vnoremap k gk
vnoremap $ g$
vnoremap ^ g^
vnoremap 0 g0
" go to home/end using capitalized directions
noremap H ^
noremap L $
" make g$/g^/g0 go to 'true' home/end
nnoremap g$ $
nnoremap g^ ^
nnoremap g0 0
vnoremap g$ $
vnoremap g^ ^
vnoremap g0 0
" gw to swap the current word with the one next to it
nmap <silent> gw :s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<cr>'':nohlsearch<cr>
" CTRL+s always saves file
nmap <c-s> :w<cr>
vmap <c-s> <esc><c-s>
imap <c-s> <esc><c-s>
" CTRL+q quits
nmap <c-q> :q<cr>
imap <c-q> <esc><c-q>
" tab/s-tab to move between tabs
nnoremap <silent> <tab> :tabnext<cr>
nnoremap <silent> <s-tab> :tabprevious<cr>
" use sane regexes
nnoremap / /\v
vnoremap / /\v
" don't move on star search (*)
nnoremap * :keepjumps normal! mi*`i<CR>
" 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
" gi already moves to 'last place you exited insert mode', so we'll map gI to something similar: move to last change
nnoremap gI `.
" lists navigation
nnoremap <left> :cprev<cr>zvzz
nnoremap <right> :cnext<cr>zvzz
nnoremap <up> :lprev<cr>zvzz
nnoremap <down> :lnext<cr>zvzz
" quickselect tabs with CMD + #
nnoremap <D-1> :tabn 1<CR>
nnoremap <D-2> :tabn 2<CR>
nnoremap <D-3> :tabn 3<CR>
nnoremap <D-4> :tabn 4<CR>
nnoremap <D-5> :tabn 5<CR>
nnoremap <D-6> :tabn 6<CR>
nnoremap <D-7> :tabn 7<CR>
nnoremap <D-8> :tabn 8<CR>
nnoremap <D-9> :tabn 9<CR>
inoremap <D-1> <C-o>:tabn 1<cr><Esc>
inoremap <D-2> <C-o>:tabn 2<cr><Esc>
inoremap <D-3> <C-o>:tabn 3<cr><Esc>
inoremap <D-4> <C-o>:tabn 4<cr><Esc>
inoremap <D-5> <C-o>:tabn 5<cr><Esc>
inoremap <D-6> <C-o>:tabn 6<cr><Esc>
inoremap <D-7> <C-o>:tabn 7<cr><Esc>
inoremap <D-8> <C-o>:tabn 8<cr><Esc>
inoremap <D-9> <C-o>:tabn 9<cr><Esc>
" pasting
nnoremap <D-v> a<C-r>+<Esc>
inoremap <D-v> <C-r>+
cnoremap <D-v> <C-r>+
" new tab
nnoremap <D-t> :tabnew<cr>
inoremap <D-t> <C-o>:tabnew<cr>
" disable F1 binding for help
nnoremap <F1> <Nop>
inoremap <F1> <Nop>
vnoremap <F1> <Nop>
" F10 to wipe buffer
nnoremap <F10> :bwipeout<cr>
" polish letters (goneovim requires those mappings)
if exists('g:goneovim')
inoremap <M-a> ą
inoremap <M-c> ć
inoremap <M-e> ę
inoremap <M-l> ł
inoremap <M-n> ń
inoremap <M-o> ó
inoremap <M-s> ś
inoremap <M-x> ź
inoremap <M-z> ż
inoremap <M-A> Ą
inoremap <M-C> Ć
inoremap <M-E> Ę
inoremap <M-L> Ł
inoremap <M-N> Ń
inoremap <M-O> Ó
inoremap <M-S> Ś
inoremap <M-X> Ź
inoremap <M-Z> Ż
endif
" INSERT MODE KEY MAPPINGS
" Ruby: convert word into Ruby symbol
imap <C-k> <C-o>b:<Esc>Ea
" basic readline shortcuts
inoremap <c-a> <esc>I
inoremap <c-e> <esc>A
" VISUAL MODE KEY MAPPINGS
" reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
" press Shift+P while in visual mode to replace the selection without overwriting the default register
vmap P p :call setreg('"', getreg('0')) <cr>
" make backspace work sanely in visual mode
vnoremap <bs> x
" select entire buffer
nnoremap vaa ggvGg_
nnoremap Vaa ggVG
" fix linewise visual selection of various text objects
nnoremap VV V
nnoremap Vit vitVkoj
nnoremap Vat vatV
nnoremap Vab vabV
nnoremap VaB vaBV
" COMMAND LINE KEY MAPPINGS
" bash like keys for the command line
cnoremap <c-a> <Home>
cnoremap <c-e> <End>
cnoremap <c-p> <Up>
cnoremap <c-n> <Down>
cnoremap <c-b> <Left>
cnoremap <c-f> <Right>
cnoremap <c-d> <Del>
cnoremap <c-k> <C-\>estrpart(getcmdline(), 0, getcmdpos()-1)<cr>
" swap <Up>/<Down> with <PageUp>/<PageDown>
cnoremap <Up> <S-Up>
cnoremap <PageUp> <Up>
cnoremap <Down> <S-Down>
cnoremap <PageDown> <Down>
" LEADER KEY MAPPINGS
" leader/localleader mappings
let mapleader = "\<space>"
let localmapleader = "\\"
" select all text in current buffer
nmap <leader>A ggVG
" upper/lower word
nmap <leader>u mQviwU'Q
nmap <leader>l mQviwu'Q
" upper/lower first char of word
nmap <leader>U mQgewvU'Q
nmap <leader>L mQgewvu'Q
" fugitive.vim
nmap <leader>gb :Git blame<cr>
nmap <leader>gc :Git commit<cr>
nmap <leader>gd :Gdiff<cr>
nmap <leader>gl :!git l<cr>
nmap <leader>gp :Git push<cr>
nmap <leader>gr :GRemove!<cr>
nmap <leader>gs :Gstatus<cr>
nmap <leader>gw :Gwrite<cr>
" vimdiff conflict resolution for 3-way merge
map <Leader>g1 :diffget LOCAL<CR>
map <Leader>g2 :diffget BASE<CR>
map <Leader>g3 :diffget REMOTE<CR>
" fzf.vim
map <leader>t :Files<cr>
map <leader>b :Buffers<cr>
map <leader>h :History<cr>
" delete current buffer
noremap <leader>c :bdelete<cr>
" quit
nmap <leader>q :q<cr>
" save file / all files
map <leader>w :w<cr>
map <leader>W :wall<cr>
" [vim-rails] Rake
map <leader>rr :.Rake<cr>
" system clipboard interaction
noremap <leader>d "*d
noremap <leader>D "*d$
noremap <leader>y "*y
noremap <leader>Y "*y$
nnoremap <leader>p :set paste<cr>"*p:set nopaste<cr>
nnoremap <leader>P :set paste<cr>"*P:set nopaste<cr>
" select just pasted text
noremap <leader>V V`]
" easier splits
noremap <leader>s <C-w>s
noremap <leader>v <C-w>v
" adjust viewports to the same size
map <leader>= <C-w>=
" make current window max height
noremap <leader>- <C-w>_
" underline the current line
nmap <silent> <leader>1 :t.<CR>Vr-
nmap <silent> <leader>2 :t.<CR>Vr=
" turn line wrap on/off
nmap <leader>4 :set wrap!<cr>
" Undotree
nmap <leader>6 :UndotreeToggle<cr>
" turn off the highlight search & redraw screen, sign column, statusline, colors
nmap <leader>8 :syntax sync fromstart<cr>:nohlsearch<cr>:redrawstatus!<cr>:redraw!<cr>:GitGutter<cr>
" toggle the paste mode (when vim either adds or not spaces in the front of lines)
set pastetoggle=<leader>0
" quick insertion of newline in normal mode
nnoremap <silent> <cr> :-1put=''<cr><down>
" convert file to utf-8 and cleanup whitespace garbage
map <leader>xx :call CleanupFileConvertToUnixUtf8()<cr>
function! CleanupFileConvertToUnixUtf8()
" insert 'tabstop' characters instead of <TAB>s
execute '%retab!'
" UNIX fileformat
set fileformat=unix
" UTF-8 encoding by default
set fileencoding=utf-8
" cleanup trailing whitespace
execute '%s/\s\+$//e'
endfunction
" vim-vinegar/netrw overrides
augroup netrw_mapping
autocmd!
autocmd filetype netrw call NetrwMapping()
augroup END
function! NetrwMapping()
" <C-l> to move right
noremap <buffer> <C-l> <C-w>l
" <C-^> to quit netrw / return to the previous buffer
nnoremap <buffer> <C-^> :Rexplore<cr>
endfunction
" STATUSLINE
" always show the status line
set laststatus=2
" don't show mode text (which vim shows below the statusline)
set noshowmode
" [lightline.vim]
fun! WhitespaceStatus() abort
let elements = []
" empty lines at the EOF
let s:contains_empty_lines = search('\v($\n\s*)+%$', 'nw')
" mixed indentation
if &expandtab
" If spaces are being used and we find a line starting with tab.
let s:contains_mixed_indent = search('\v(^( +)?\t+)', 'nw')
el
" We only check mixed indents (tabs + spaces)
let s:contains_mixed_indent = search('\v(^\t+ +)|(^ +\t+)', 'nw')
en
" trailing whitespace
let s:contains_trailing_whitespaces = search('\v\s+$', 'nw')
if s:contains_empty_lines > 0
let elements = elements + ['empty-lines' . ':' . s:contains_empty_lines]
en
if s:contains_mixed_indent > 0
let elements = elements + ['mixed-indent' . ':' . s:contains_mixed_indent]
en
if s:contains_trailing_whitespaces > 0
let elements = elements + ['trailing' . ':' . s:contains_trailing_whitespaces]
en
return join(elements, ' ')
endf
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [['mode', 'paste'], ['filename', 'readonly', 'modified']],
\ 'right': [['lineinfo'], ['percent'], ['whitespace_status'], ['fileformat', 'fileencoding', 'filetype']]
\ },
\ 'inactive': {
\ 'left': [['filename'], ['modified']],
\ 'right': [['lineinfo'], ['percent']]
\ },
\ 'component_expand': {
\ 'whitespace_status': 'WhitespaceStatus'
\ },
\ 'component_type': {
\ 'whitespace_status': 'warning'
\ }
\ }
" in wombat colorscheme swap normal/insert colors
let s:palette = g:lightline#colorscheme#{g:lightline.colorscheme}#palette
let old_normal_left = s:palette.normal.left
let old_insert_left = s:palette.insert.left
let s:palette.normal.left = old_insert_left
let s:palette.insert.left = old_normal_left
" update on write
autocmd BufWritePost * call lightline#update()
" PLUGINS
" [ack.vim] (using ag aka 'the_silver_searcher')
if executable('ag')
let g:ackprg = 'ag --vimgrep --smart-case'
cnoreabbrev ag Ack
cnoreabbrev aG Ack
cnoreabbrev Ag Ack
cnoreabbrev AG Ack
endif
" [autoclose.vim]
let g:AutoCloseProtectedRegions = ["Comment"]
" [vim-ragtag]
inoremap <M-o> <Esc>o
inoremap <C-j> <Down>
let g:ragtag_global_maps = 1
" [fzf.vim]
let g:fzf_buffers_jump = 0
let g:fzf_layout = { 'down': '10' }
" required for VimR/MacVim (MacOS)
let $FZF_DEFAULT_COMMAND = 'ag --nocolor --ignore-dir=./public --ignore-dir=./node_modules --ignore-dir=./.cache --ignore-dir=./tmp --ignore-dir=./vendor/bundle --ignore-dir=./vendor/plugins --ignore=''*.jpg'' --ignore=''*.png'' --ignore=''*.svg'' -g ""'
" hl (non matched lines, matched letters fg)
" fg+ (first matched line fg)
" bg+ (first matched line bg)
" hl+ (first matched line: matched letters fg)
let g:fzf_colors = {
\ 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'helpNote'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" [fugitive.vim] auto clean fugitive buffers
autocmd BufReadPost fugitive://* set bufhidden=delete
" [vim-multiple-cursors]
let g:multi_cursor_exit_from_insert_mode = 1
" [vim-ruby] compatibility with standardrb
let g:ruby_indent_assignment_style = 'variable'
let g:ruby_indent_hanging_elements = 0
" [vim-rails / rails.vim] custom commands
command! Ecircle edit .circleci/config.yml
command! Edatabase edit config/database.yml
command! Egemfile edit Gemfile
command! Ejroutes Ejinitializer
command! Eprocfile edit Procfile
command! Erailshelper edit spec/rails_helper.rb
command! Ereadme edit README.md
command! Eroutes edit config/routes.rb
command! Esecrets edit config/secrets.yml
command! Eseeds edit db/seeds.rb
command! Espechelper edit spec/spec_helper.rb
command! Estructure edit db/structure.sql
" [vim-rails] Rails projections - typing `:Eservice accept_bid` will open /app/services/accept_bid.rb, etc.
let g:rails_projections = {
\ "app/services/*.rb": {
\ "command": "service",
\ "affinity": "collection",
\ "test": "spec/services/{}_spec.rb",
\ "template": "class {camelcase|capitalize|colons}\nend"
\ },
\ "app/core/*.rb": {
\ "command": "core",
\ "affinity": "collection",
\ "test": "spec/core/{}_spec.rb",
\ "template": "class {camelcase|capitalize|colons}\nend"
\ },
\ "app/gateways/*_gateway.rb": {
\ "command": "gateway",
\ "affinity": "collection",
\ "test": "spec/gateways/{}_spec.rb",
\ "template": "class {camelcase|capitalize|colons}\nend"
\ },
\ "app/finders/*.rb": {
\ "command": "finder",
\ "affinity": "collection",
\ "test": "spec/finders/{}_spec.rb",
\ "template": "class {camelcase|capitalize|colons}\nend"
\ },
\ "app/controllers/api/*_controller.rb": {
\ "command": "apicontroller",
\ "test": "spec/controllers/api/{}_controller_spec.rb",
\ "template": "class Api::{camelcase|capitalize|colons}Controller < Api::ApplicationController\nend"
\ },
\ "spec/requests/*_spec.rb": {
\ "command": "request",
\ "template": "describe '{underscore|capitalize|blank}' do\n\nend"
\ },
\ "spec/support/*.rb": {
\ "command": "support"
\ },
\ "spec/system/*_spec.rb": {
\ "command": "system",
\ "template": "describe '{underscore|capitalize|blank}' do\n\nend"
\ }
\ }