-
Notifications
You must be signed in to change notification settings - Fork 8
/
vimrc
1864 lines (1572 loc) · 65.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
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
"
" Author: Larry Lv <larrybayarea@gmail.com>
"
" ╭────────────────────────────────────────────────────────────────────╮
" │ Plugins │
" ╰────────────────────────────────────────────────────────────────────╯
filetype off
call plug#begin('~/.vim/bundle')
" colorscheme & statusline & tabline
Plug 'lifepillar/vim-solarized8'
Plug 'itchyny/lightline.vim'
Plug 'larrylv/lightline-solarized'
Plug 'maximbaz/lightline-ale'
" find & search & tjump
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'ivalkeen/vim-ctrlp-tjump'
Plug 'FelikZ/ctrlp-py-matcher'
Plug 'mileszs/ack.vim'
" lsp & linter & formatter & completion & copilot
Plug 'larrylv/coc.nvim', {'branch': 'release'} " my own fork that suppress error messages
Plug 'antoinemadec/coc-fzf' " fzf <> coc.nvim
Plug 'dense-analysis/ale' " linting
Plug 'stevearc/conform.nvim' " lightweight yet powerful formatter
Plug 'larrylv/vim-tagimposter' " populate the tagstack when using coc to jump to definitions
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'github/copilot.vim'
" cursor
" Plug 'yetone/avante.nvim', { 'branch': 'main', 'do': 'make' }
" Plug 'stevearc/dressing.nvim'
" Plug 'nvim-lua/plenary.nvim'
" Plug 'MunifTanjim/nui.nvim'
" Plug 'nvim-tree/nvim-web-devicons'
" Plug 'MeanderingProgrammer/render-markdown.nvim', { 'for': ['Avante'] }
" treesitter
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-treesitter/playground' " :TSPlaygroundToggle, :TSHighlightCapturesUnderCursor
Plug 'nvim-treesitter/nvim-treesitter-context' " show code context
Plug 'nvim-treesitter/nvim-treesitter-textobjects' " Syntax aware text-objects, select, move, swap, and peek support.
" explorer
Plug 'larrylv/defx.nvim', { 'do': ':UpdateRemotePlugins' } " my own fork to not open chosen file in the existing bufnr
" editing
Plug 'Yggdroot/indentLine', { 'for': ['ruby', 'python', 'go', 'yaml'] } " display the indention levels with thin vertical lines. <leader>cm or <leader>vv to toggle.
Plug 'liuchengxu/vista.vim' " Viewer & Finder for LSP symbols and tags
Plug 'tpope/vim-obsession' " record a session with :Obsession
Plug 'tpope/vim-projectionist' " alternate files with :AV/:AS
Plug 'tpope/vim-surround' " cs`' to change `` to '', etc
Plug 'tpope/vim-abolish' " MixedCase (crm), camelCase (crc), snake_case (crs), UPPER_CASE (cru) and dash-case (cr-).
Plug 'tpope/vim-repeat' " enable repeating supported plugin maps with `.`
Plug 'tpope/vim-unimpaired' " [<Space> and ]<Space> to add newlines. [q and ]q for :cprevious and :cnext
Plug 'tpope/vim-eunuch' " shell commands like :Delete, :SudoWrite, etc
Plug 'tpope/vim-speeddating' " enhance CTRL-A and CTRL-X
Plug 'tpope/vim-sensible' " a universal set of defaults defined by tpope
Plug 'tpope/vim-endwise' " add `end` or similar keywords automatically
Plug 'tpope/vim-rsi' " readline mapping for insert/command mode like <C-a> to beginning of line.
Plug 'kshenoy/vim-signature' " show marks in the gutter
Plug 'AndrewRadev/splitjoin.vim' " split/join single line/multiline
Plug 'tomtom/tcomment_vim' " comment with `gcc`
Plug 'larrylv/vim-trailing-whitespace' " show trailing whitespace
Plug 'tyru/open-browser.vim' " gx to open browser
Plug 'junegunn/vim-easy-align' " align multiple lines
Plug 'junegunn/rainbow_parentheses.vim' " rainbow parentheses
Plug 'kana/vim-textobj-user' " create text objects, depended by vim-textobj-rubyblock
Plug 'nelstrom/vim-textobj-rubyblock' " ar selects all of a ruby block, ir selects the inner portion of a rubyblock
Plug 'Raimondi/delimitMate' " auto-completion for quotes, parens, brackets, etc.
Plug 'mhinz/vim-startify' " fancy start screen
Plug 'Einenlum/yaml-revealer' " A vim plugin to easily navigate through Yaml files
Plug 'tyru/current-func-info.vim' " Get current function name
Plug 'powerman/vim-plugin-AnsiEsc' " ansi escape sequences concealed, but highlighted as specified
Plug 'kristijanhusak/vim-carbon-now-sh' " open selected text in https://carbon.now.sh
" Plug 'majutsushi/tagbar' " show tagbar with F2
" Plug 'mg979/vim-visual-multi' " Multiple cursors plugin
" Plug 'puremourning/vimspector' " A multi-language debugging system for Vim
" Plug 'folke/which-key.nvim' " displays a popup with possible keybindings of the command you started typing
" git
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb' " Gbrowse
Plug 'airblade/vim-gitgutter' " shows git diff markers in the sign column
Plug 'rhysd/git-messenger.vim' " <leader>gm to reveal the commit messages under the cursor
" test
Plug 'vim-test/vim-test' " TestNearest, TestFile, TestLast, TestVisit
Plug 'benmills/vimux' " easily interact with tmux from vim
" ruby
Plug 'larrylv/vim-vroom', { 'for': 'ruby' } " run ruby tests using vimux
" go
Plug 'visualfc/gocode', { 'for': ['go', 'vim'], 'rtp': 'vim', 'do': '~/.vim/bundle/gocode/vim/symlink.sh' }
Plug 'benmills/vimux-golang', { 'for': 'go' } " run go tests using vimux
" elixir & erlang
Plug 'elixir-lang/vim-elixir', { 'for': ['elixir', 'eelixir'] }
Plug 'slashmili/alchemist.vim', { 'for': ['elixir', 'eelixir'] }
Plug 'vim-erlang/vim-erlang-runtime', { 'for': 'erlang' }
Plug 'vim-erlang/vim-erlang-compiler', { 'for': 'erlang' }
Plug 'vim-erlang/vim-erlang-omnicomplete', { 'for': 'erlang' }
Plug 'vim-erlang/vim-erlang-tags', { 'for': 'erlang' }
Plug 'ten0s/syntaxerl', { 'for': 'erlang' }
" rust
Plug 'rust-lang/rust.vim', { 'for': 'rust' }
" scala
Plug 'derekwyatt/vim-scala', { 'for': 'scala' }
" clojure
Plug 'guns/vim-clojure-static', { 'for': 'clojure' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
Plug 'tpope/vim-classpath', { 'for': 'clojure' }
Plug 'tpope/vim-salve', { 'for': 'clojure' }
Plug 'guns/vim-sexp', { 'for': 'clojure' }
Plug 'vim-scripts/paredit.vim', { 'for': 'clojure' }
Plug 'clojure-vim/async-clj-omni', { 'for': 'clojure' }
" markdown
Plug 'iamcco/markdown-preview.nvim', { 'for': 'markdown', 'do': 'cd app && yarn install' } " <leader>pp to preview markdown
Plug 'godlygeek/tabular', { 'for': 'markdown' }
Plug 'preservim/vim-markdown', { 'for': 'markdown' }
" frontend
Plug 'pangloss/vim-javascript', { 'for': 'javascript' }
" Plug 'othree/html5.vim', { 'for': ['html', 'eruby'] }
" Plug 'mustache/vim-mustache-handlebars', { 'for': ['html.mustache', 'html.handlebars'] }
" Plug 'hail2u/vim-css3-syntax', { 'for': ['css', 'sass', 'scss'] }
" Plug 'ap/vim-css-color', { 'for': ['css', 'sass', 'scss'] }
" Plug 'groenewege/vim-less', { 'for': 'less' }
" Plug 'tpope/vim-haml', { 'for': 'haml' }
" Plug 'cakebaker/scss-syntax.vim', { 'for': 'scss' }
" Plug 'tudorprodan/html_annoyance.vim', { 'for': ['html', 'eruby'] }
Plug 'tpope/vim-ragtag', " A set of mappings for HTML, XML, etc.
" elm
Plug 'elmcast/elm-vim', { 'for': 'elm' }
" puppet
Plug 'rodjek/vim-puppet'
" function to source a file if it exists
function! SourceIfExists(file)
if filereadable(expand(a:file))
exe 'source' a:file
endif
endfunction
" load private overlay packages
call SourceIfExists('~/.config/nvim/layers/private/packages.vim')
" Add plugins to &runtimepath
call plug#end()
filetype plugin indent on
" ================================= GENERAL CONFIG =============================
runtime! plugin/sensible.vim
let mapleader=","
" Make vim more useful
if !has('nvim')
set nocompatible
endif
" Syntax highlighting
set t_Co=256
syntax on
" lifepillar/vim-solarized8
let g:solarized_use16 = 1
let g:solarized_visibility = "high"
let g:solarized_termtrans = 1
let g:solarized_extra_hi_groups = 0
set background=dark
colorscheme solarized8_flat
" dirty patch for CursorLine
hi! CursorLine cterm=NONE gui=NONE ctermfg=NONE guifg=NONE ctermbg=237 guibg=#3c3d3a
hi! CursorLineNr cterm=NONE gui=NONE ctermfg=NONE guifg=NONE ctermbg=NONE guibg=NONE
" folding
hi! Folded cterm=NONE gui=NONE ctermfg=NONE guifg=NONE ctermbg=0 guibg=#3c3d3a
" use treesitter for folding https://www.jmaguire.tech/posts/treesitter_folding/
set foldlevelstart=99 " Open all folds by default
set foldenable " Enable folding
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set foldcolumn=0 " Column to show folds
" Opening and closing folds
" https://vim.fandom.com/wiki/Folding#Opening_and_closing_folds
"
" `za` / `zc` / `zo` operate on one level of folding, at the cursor:
" * za -- toggle a fold
" * zc -- close a fold
" * zo -- open a fold
"
" `zA` / `zC` / `zO` are similar, but operate on all folding levels (for
" example, the cursor line may be in an open fold, which is inside another
" open fold; typing `zC` would close all folds at the cursor).
"
" `zr` -- reduces folding by opening one more level of folds throughout the
" whole buffer
" `zR` -- open all folds
" `zm` -- gives more folding by closing one more level of folds throughout the
" whole buffer
" `zM` -- close all folds
" set ambiwidth=double
set autoindent " Copy indent from last line when starting new line
set autoread " Reload files changed outside automatically
set backspace=indent,eol,start " Allow backspacing over everything in insert mode
set cindent
set complete=.,w,b,u,t,i
set completeopt=noinsert,noselect,menuone
set colorcolumn="" " Disable colorcolumn by default
" set cursorcolumn " Highlight current column
" set cursorline " Highlight current line
set diffopt+=iwhite " Ignore whitespaces with vimdiff
set diffopt=filler " Add vertical spaces to keep right and left aligned
if !has('nvim')
set encoding=utf-8 nobomb " BOM often causes trouble
endif
set expandtab " Expand tabs to spaces
set fileencoding=utf-8
set fileencodings=utf-8,ucs-bom,chinese
set fillchars+=vert:\ " Styling vertical split borders
set history=1000 " Increase history from 20 default to 1000
set hlsearch " Highlight searches
set incsearch " Highlight dynamically as pattern is typed
" :set indentkeys? - get full list of trigger keys.
" set indentkeys= " DO NOT INTENT FOR ANY CHARACTERS
set laststatus=2 " Always show status line
set lazyredraw " Don't redraw when we don't have to
set magic " Enable extended regexes
set modeline
set nobackup
set noerrorbells " Disable error bells
set noignorecase " Don't ignore case of searches
set nojoinspaces " Only insert single space after a '.', '?' and '!' with a join command
set noshowmode " Don't show the current mode (lightline.vim takes care of us)
set nostartofline " Don't reset cursor to start of line when moving around
set notitle
set noswapfile
set notermguicolors " fix nvim 0.10.0 color rendering
set nu " Enable line numbers
set omnifunc=syntaxcomplete#Complete " Set omni-completion method
set redrawtime=10000
set relativenumber
set noruler " Don't show the line and column number of the cursor position. lightline has it already.
set scrolloff=3 " Start scrolling three lines before horizontal border of window
set shiftwidth=2 " The # of spaces for indenting
set shortmess=atI " Don't show the intro message when starting vim
set shortmess+=c " This prevents the display of "Pattern not found" & similar messages during completion.
set shortmess+=F " Don't give the file info when editing a file, like :silent as used for the command
set showtabline=2 " Show tab bar all the time
" set showcmd " display incomplete commands
set smartcase " Ignore 'ignorecase' if search patter contains uppercase characters
set smarttab " At start of line, <Tab> inserts shiftwidth spaces, <Bs> deletes shiftwidth spaces
set softtabstop=2 " Tab key results in 2 spaces
set splitbelow " New window goes below
set splitright " New windows goes right
" set synmaxcol=256 " Syntax coloring lines that are too long just slows down the world
set tabstop=2
set tags=./tags;
set timeout timeoutlen=1000 ttimeoutlen=0 " No delay for entering normal mode
if !has('nvim')
set ttyfast " Send more characters at a given time
set ttyscroll=3
endif
set undodir=~/.vim/.undo
set undofile " Persistent Undo
set undolevels=1000
set undoreload=10000
set wildchar=<Tab> " Character for CLI expansion (TAB-completion)
set wildmenu " Hitting TAB in command mode will show possible completions above command line
set wildmode=list:longest " Complete only until point of ambiguity
set wrap " Wrap lines that are too long
set wrapscan " Searches wrap around end of file
set wildignore+=**/*.jpg,*.jpeg,*.gif,**/*.png,*.gif,*.psd,*.o,*.obj,*.min.js
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.sass-cache/*
if !has('nvim')
function! SetRegexpEngine()
let filetype = &ft
if (filetype == 'ruby')
setlocal regexpengine=1 " https://github.com/vim-ruby/vim-ruby/issues/243
else
setlocal regexpengine=0 " https://jameschambers.co.uk/vim-typescript-slow
endif
endfunction
augroup regexpEngine
autocmd!
autocmd WinEnter,VimEnter,GUIEnter,BufEnter,TabEnter * call SetRegexpEngine()
augroup END
else
set regexpengine=0
endif
if has('nvim')
" Get cmd+c work
set mouse=
" Switch cursor shape when using NeoVim
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 ""
" Bring back ctrl-h
nmap <BS> <C-W>h
endif
augroup general_config
autocmd!
" Adjust window height
au FileType qf call AdjustWindowHeight(3, 10)
function! AdjustWindowHeight(minheight, maxheight)
exe max([min([line("$"), a:maxheight]), a:minheight]) . "wincmd _"
endfunction
" Insert the current time (InsertTime)
command! InsertTime :normal a<c-r>=strftime('%F %H:%M:%S')<cr>
" Change SpecialKey color for Tagbar + Golang
highlight SpecialKey term=bold cterm=bold ctermfg=9 guifg=Cyan
" Remember last location when open a file
" http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session
function! ResCur()
let filetype = &ft
if (line("'\"") <= line("$") && filetype != 'gitcommit' && filetype != 'gitrebase')
silent! normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
autocmd BufWinEnter * call ResCur()
augroup END
autocmd FileType ruby,eruby setlocal indentkeys=0{,0},0),0],!^F,o,O,e,=end,=else,=elsif,=when,=ensure,=rescue,==begin,==end,=private,=protected,=public
" Set local omnifunc
autocmd FileType ruby,eruby setlocal omnifunc=rubycomplete#Complete
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown,mkd setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
let g:omni_sql_no_default_maps = 1
" dirty patch for hiding markdown error highlighting
autocmd FileType markdown,mkd syn match markdownError "\w\@<=\w\@="
" don't cindent for markdown files
autocmd FileType markdown,mkd setlocal nocindent
" Only use cursorline in all windows and not when being in insert mode
autocmd WinEnter,VimEnter,GUIEnter,BufEnter,TabEnter * set cursorline
autocmd InsertEnter * set nocursorline
autocmd InsertLeave * set cursorline
" Disable auto comment insertion
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
augroup HiglightTODO
autocmd!
autocmd WinEnter,VimEnter,GUIEnter,BufEnter,TabEnter * :silent! call matchadd('Todo', 'TODO', -1)
autocmd WinEnter,VimEnter,GUIEnter,BufEnter,TabEnter * :silent! call matchadd('Todo', 'FIXME', -1)
augroup END
" Cursor Mode Settings https://vim.fandom.com/wiki/Change_cursor_shape_in_different_modes
" SI = INSERT mode
" SR = REPLACE mode
" EI = NORMAL mode (ELSE)
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_SR = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=2\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
highlight Pmenu ctermfg=lightgray ctermbg=black cterm=NONE
highlight PmenuSbar ctermfg=darkcyan ctermbg=lightgray cterm=NONE
highlight PmenuThumb ctermfg=lightgray ctermbg=darkcyan cterm=NONE
" Neovim allows customizing `syn sync minlines` with this variable.
" vim-markdown has a weird save & restore behavior for other filetypes, so
" sometimes `:syntax sync fromstart` has to be called to fix it -- it is also
" mapped to <F10>.
let g:markdown_minlines=10000
" Filetype detection
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter Thorfile set filetype=ruby syntax=ruby
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.thor set filetype=ruby syntax=ruby
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.god set filetype=ruby syntax=ruby
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.rbi set filetype=ruby syntax=ruby
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.less set filetype=css
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.mkd set ai formatoptions=tcroqn2 comments=n:>
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.coffee set filetype=coffee
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.es6 set filetype=javascript
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.tfvars set filetype=terraform
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.go,*.rust,*.elm setlocal noexpandtab ts=4 sw=4 sts=4
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.c,*.cpp setlocal noexpandtab ts=2 sw=2 sts=2
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.ci set filetype=cpp syntax=cpp
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.md setlocal textwidth=80
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter Gemfile set filetype=ruby syntax=ruby
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter Capfile set filetype=ruby syntax=ruby
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter pryrc set filetype=ruby syntax=ruby
autocmd BufNewFile,BufRead,BufEnter,TabEnter,WinEnter,VimEnter,GUIEnter *.json set conceallevel=0
autocmd Filetype gitcommit,gitrebase setlocal textwidth=78
autocmd Filetype gitcommit,gitrebase setlocal colorcolumn=81
autocmd Filetype json setlocal conceallevel=0
augroup END
let g:python3_host_prog=$HOME.'/.pyenv/shims/python'
" ================================= GENERAL MAPPINGS ===========================
" leader Shortcuts
nnoremap <leader><leader> <c-^>
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" Better split switching (Ctrl-j, Ctrl-k, Ctrl-h, Ctrl-l, Ctrl-p)
map <C-k> <C-W>k
map <C-j> <C-W>j
map <C-l> <C-W>l
map <C-h> <C-W>h
map <C-\> <C-W>p
" Go to previous (last accessed) window.
map <C-w>\ <C-w><C-p>
map <C-w><C-\> <C-w><C-p>
" Clear last search (Ctrl-n, ,h)
map <silent> <C-n> <Esc>:nohlsearch<cr>
" Close preview window when completion is done.
autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif
" Paste toggle (<F3>)
nnoremap <F3> :set invpaste paste?<cr>
set pastetoggle=<F3>
" Open selected text in https://carbon.now.sh
vnoremap <F5> :CarbonNowSh<cr>
" clean up most syntax highlighting problems (<F10>)
noremap <F10> <Esc>:syntax sync fromstart<CR>
inoremap <F10> <C-o>:syntax sync fromstart<CR>
" Yank from cursor to end of line
nnoremap Y y$
imap <c-c> <ESC>l
" Remap increase number (Ctrl-p)
" <c-a> is prefix for tmux
" I used to use <c-i>, but that's useful for jumps.
map <c-p> <c-a>
" Quick move under insert mode (Ctrl-f, Ctrl-b)
imap <c-f> <c-o>w
imap <c-b> <c-o>b
" Use Alt + number to swtich tabs
nnoremap <M-1> 1gt
nnoremap <M-2> 2gt
nnoremap <M-3> 3gt
nnoremap <M-4> 4gt
nnoremap <M-5> 5gt
nnoremap <M-6> 6gt
nnoremap <M-7> 7gt
nnoremap <M-8> 8gt
nnoremap <M-9> 9gt
function! FlipBindingPry()
if getline('.') =~? '^.*binding\.pry.*$'
normal dd
else
normal orequire 'pry'; binding.pry
endif
write
endfunction
nnoremap <leader>bp :call FlipBindingPry()<cr>
map <leader>cc :ccl <bar> lcl<cr>
map <leader>cn :cn<cr>
map <leader>cp :cp<cr>
" toggle colorcolumn=81
nnoremap <silent><leader>co :execute "set colorcolumn=" . (&colorcolumn == "" ? "81" : "")<cr>
" strip tailing white spaces
nnoremap <leader>dd :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<cr>
" increase window horizontal size
map <leader>ni <C-W>>
map <leader>n+ <C-W>>
map <leader>+ <C-W>>
map <leader>= <C-W>>
" decrease window horizontal size
map <leader>nd <C-W><
map <leader>n- <C-W><
map <leader>_ <C-W><
map <leader>- <C-W><
" increase a window to its maximum height
map <leader>nh <C-W>_
" increase a window to its maximum width
map <leader>nw <C-W>\|
nnoremap <leader>p :let @* = expand("%")<cr>:echo @%<cr>
" only show marks / bookmarks I care about
nmap <leader>sm :marks abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<cr>
map <leader>so :source $MYVIMRC<cr>:e<cr>:RainbowParentheses<cr>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
nmap <leader>sp :call <SID>SynStack()<cr>
" close all other tabs
nnoremap <leader>to :tabonly<cr>
nnoremap <leader>tq :tabonly<cr>
" open a buffer in a new tab
nnoremap <leader>tt :tabe<cr>
map <leader>vr :tabe ~/.vimrc<cr>
" n,w to qucikly switch vim window
map <leader>w <C-W><C-W>
" delete all upcase marks / bookmarks
nmap <leader>xm :delmarks ABCDEFGHIJKLMNOPQRSTUVWXYZ<cr>:wviminfo!<cr>
" system yank: will copy into the system clipboard on OS X
" vim has to be compiled with +clipboard to support this
vmap <leader>y "*y
" close all hidden buffers
function! DeleteHiddenBuffers()
let tpbl=[]
let closed = 0
call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))')
for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1')
if getbufvar(buf, '&mod') == 0
silent execute 'bwipeout' buf
let closed += 1
endif
endfor
echo "Closed ".closed." hidden buffers"
endfunction
nnoremap <leader>qd :call DeleteHiddenBuffers()<cr>
" close all buffers except for the current one
" command! BufOnly silent! execute "%bd!|e#|bd#"
" nmap <leader>qo :BufOnly<cr>
" close all other splits except the current one
nnoremap <leader>qo <C-w>o<cr>
" keep selected text selected when fixing indentation
vnoremap < <gv
vnoremap > >gv
" no Ex mode
map Q <Nop>
" search and replace word under cursor (,*)
nnoremap <leader>* :%s/\<<C-r><C-w>\>//<Left>
vnoremap <leader>* "hy:%s/\V<C-r>h//<left>
" ================================= ack ========================================
let g:ack_use_dispatch=0
let g:ackhighlight=1
cnoreabbrev Ack Ack!
nnoremap <leader>ac :Ack!<Space>
nnoremap <silent> <leader>ak :Ack! <C-R><C-W><cr>
xnoremap <silent> <leader>ak y:Ack! <C-R>"<cr>
if executable("rg")
let g:ackprg="rg --vimgrep --color=never"
elseif executable("ag")
let g:ackprg="ag --nocolor --nogroup --column"
elseif executable("ack")
let g:ackprg="ack -H --nocolor --nogroup --column --no-smart-case"
endif
" ================================= ale ========================================
augroup AutoALE
autocmd!
autocmd User ALELint call lightline#update()
augroup END
let g:ale_disable_lsp = 1
let g:ale_lint_on_text_changed = 'never' " lint only on save
let g:ale_lint_on_insert_leave = 0 " don't lint when leaving insert mode
let g:ale_lint_on_enter = 0 " don't lint on enter
let g:ale_hover_cursor = 0 " disable ALEHover (ALEPreviewWindow)
let g:ale_set_balloons = 1 " By showing balloons for your mouse cursor
let g:ale_virtualtext_cursor = 2 " enable ALE virtual text
let g:ale_sign_column_always = 1
let g:ale_sign_error = '✗'
let g:ale_sign_warning = '⚠ '
let g:ale_statusline_format = ['✗ %d', '⚠ %d', '']
let g:ale_echo_msg_format = '[%linter%] %s'
let g:ale_set_highlights = 0
let g:ale_sign_priority = 100
let g:ale_linters = {
\ 'cpp': [],
\ 'coffee': [],
\ 'eruby': [],
\ 'go': ['golangci-lint'],
\ 'rust': ['analyzer'],
\ 'html': ['htmlhint'],
\ 'javascript': ['eslint'],
\ 'javascript.jsx': ['eslint'],
\ 'javascriptreact': ['eslint'],
\ 'ruby': ['rubocop'],
\ 'markdown': [],
\ 'python': ['ruff'],
\ 'sh': [],
\ 'typescriptreact': ['eslint'],
\ 'typescript': ['eslint'],
\ 'vim': [],
\ 'yaml': [],
\}
" use conform.nvim for formatter
let g:ale_fixers = {}
let g:ale_fix_on_save = 0
let g:ale_go_golangci_lint_package = 1
let g:ale_go_golangci_lint_options = ''
" disable linting for all minified JS files
let g:ale_pattern_options = {
\ '\.min.js$': {'ale_enabled': 0},
\}
nmap <silent> <leader>lp <Plug>(ale_previous_wrap)
nmap <silent> <leader>ln <Plug>(ale_next_wrap)
" ================================= coc-fzf ====================================
" make CocFzf look the same as other fzf commands
let g:coc_fzf_preview = ''
let g:coc_fzf_opts = []
" ================================= coc.nvim ===================================
noremap <F12> <Esc>:CocCommand document.toggleInlayHint<CR>
inoremap <F12> <C-o>:CocCommand document.toggleInlayHint<CR>
let g:coc_snippet_next = '<tab>'
" Disable transparent cursor when CocList is activated.
let g:coc_disable_transparent_cursor = 1
inoremap <silent><expr> <C-n>
\ coc#pum#visible() ? coc#pum#next(1) : "\<C-n>"
inoremap <silent><expr> <C-p>
\ coc#pum#visible() ? coc#pum#prev(1) : "\<C-p>"
inoremap <silent><expr> <CR>
\ coc#pum#visible() ?
\ coc#pum#info()['index'] >= 0 ? coc#pum#confirm() : "\<C-r>=coc#pum#cancel()\<CR>\<CR>" :
\ "\<CR>"
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ pumvisible() ? "\<C-n>" :
\ "\<tab>"
inoremap <silent><expr> <S-TAB>
\ coc#pum#visible() ? coc#pum#prev(1) :
\ pumvisible() ? "\<C-p>" :
\ "\<s-tab>"
inoremap <silent><expr> <C-space>
\ coc#refresh()
function! SetupSwitchSourceHeaderForClangd()
" switch between source/header files
nnoremap <leader>ch :CocCommand clangd.switchSourceHeader<cr>
endfunction
autocmd FileType c,cpp,objc,objcpp call SetupSwitchSourceHeaderForClangd()
" NOTE: clangd requires a `compile_commands.json` in the codebase root directory.
" For example, here is how to generate that file for mongo codebase:
" $ pip3 install scons==3.1.1; scons-3.1.1 compiledb
let g:coc_global_extensions = [
\ 'coc-clangd',
\ 'coc-omni',
\ 'coc-pyright',
\ 'coc-rust-analyzer',
\ 'coc-tag',
\ 'coc-ultisnips'
\ ]
" this is commented out because vim-go already does this
" autocmd BufWritePre *.go :silent call CocAction('runCommand', 'editor.action.organizeImport')
" function! ToggleOutline() abort
" let winid = coc#window#find('cocViewId', 'OUTLINE')
" if winid == -1
" call CocActionAsync('showOutline')
" else
" call coc#window#close(winid)
" endif
" endfunction
" autocmd FileType go nnoremap <F2> :call ToggleOutline()<cr>
function! g:CocShowDocumentation()
" supports jumping to vim documentation as well using built-ins.
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocActionAsync('doHover')
endif
endfunction
nnoremap <leader>ci :CocInfo<cr>
nnoremap <leader>cr :CocRestart<cr>
" jump to definition(s) of current symbol
nnoremap <silent> <c-]> :<C-u> TagImposterAnticipateJump <Bar> call CocAction('jumpDefinition', v:false)<cr>
nnoremap <silent> <leader>ld :<C-u> TagImposterAnticipateJump <Bar> call CocAction('jumpDefinition')<cr>
nnoremap <silent> <leader>lv :<C-u> TagImposterAnticipateJump <Bar> call CocAction('jumpDefinition', 'vsplit')<cr>
nnoremap <silent> <leader>ls :<C-u> TagImposterAnticipateJump <Bar> call CocAction('jumpDefinition', 'split')<cr>
nnoremap <silent> <leader>lt :<C-u> TagImposterAnticipateJump <Bar> call CocAction('jumpDefinition', 'tabe')<cr>
" jump to references of current symbol
nmap <silent> <leader>lf <Plug>(coc-references)
" jump to declaration(s) of current symbol
nmap <silent> <leader>lc <Plug>(coc-declaration)
" jump to type definition(s) of current symbol
nmap <silent> <leader>ly <Plug>(coc-type-definition)
" jump to implementation(s) of current symbol
nmap <silent> <leader>li <Plug>(coc-implementation)
" rename symbol under cursor
nmap <silent> <leader>lr <Plug>(coc-rename)
" show documentation of current symbol
nnoremap <silent> K :call CocShowDocumentation()<cr>
" disable coc in git commit message and gitconfig
autocmd Filetype gitcommit,gitrebase,gitconfig let b:coc_enabled=0
" redraw the status line when coc#status changes
augroup AutoCocStatus
autocmd!
autocmd User CocStatusChange call lightline#update()
augroup END
" ================================= ctrlp ======================================
" silent! nnoremap <unique> <silent> <leader>cl :CtrlPClearCache<cr>
" silent! nnoremap <unique> <silent> <leader>tt :CtrlPTag<cr>
" silent! nnoremap <unique> <silent> <leader>d :CtrlP<cr>
let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_by_filename = 0
let g:ctrlp_match_window = 'bottom,order:ttb,min:1,max:20,results:20'
let g:ctrlp_map = '<C-q>'
let g:ctrlp_max_files = 0
let g:ctrlp_max_history = 0
let g:ctrlp_working_path_mode = 0
let g:ctrlp_extensions = [ 'ctrlp-filetpe' ]
let g:ctrlp_follow_symlinks = 1
let g:ctrlp_switch_buffer = 0
let g:ctrlp_mruf_max = 0
let g:ctrlp_mruf_relative = 1
let g:ctrlp_prompt_mappings = {
\ 'AcceptSelection("h")': ['<c-d>', '<c-cr>', '<c-e>', '<c-s>'],
\ 'ToggleByFname()': ['<c-f>'],
\ 'PrtHistory(-1)': [],
\ 'PrtHistory(1)': [],
\ 'PrtSelectMove("j")': ['<c-j>', '<c-n>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<c-p>', '<up>'],
\}
let g:ctrlp_custom_ignore = {
\ 'dir': '\v(_build|build|bower_components|deps|dist|node_modules|public|tmp|vendor\/bundle|elm-stuff)$',
\ }
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git', 'cd %s && git ls-files . -co --exclude-standard'],
\ 2: ['.hg', 'hg --cwd %s locate -I .'],
\ },
\ 'fallback': 'find %s -type f'
\ }
" let g:ctrlp_tjump_only_silent = 1
" disable c-] mapping with ctrlp-tjump
" prefer using c-] with coc and lsp
" nnoremap <c-]> :CtrlPtjump<cr>
" vnoremap <c-]> :CtrlPtjumpVisual<cr>
nnoremap <leader>cj :CtrlPtjump<cr>
vnoremap <leader>cj :CtrlPtjumpVisual<cr>
" ================================= current-func-info.vim ======================
nnoremap <C-g>f :echo cfi#format("%s", "")<CR>
function! CopyCurrentFuncInfoToClipboard()
let text_to_copy = cfi#format("%s", "")
execute 'let @+="' . text_to_copy . '"'
echom('Copied to clipboard: ' . string(text_to_copy))
endfunction
augroup CopyCurrentFuncMapping
autocmd!
autocmd FileType * nnoremap <silent> <leader>ry :call CopyCurrentFuncInfoToClipboard()<CR>
autocmd FileType ruby nnoremap <silent> <leader>ry :FZFCopyRubyToken<Return>
augroup END
" ================================= defx =======================================
autocmd FileType defx call MyDefxSettings()
function! MyDefxSettings() abort
setlocal nonu
setlocal norelativenumber
highlight! default link Defx_filename_root Statement
highlight! default link Defx_filename_root_marker Statement
highlight! default link Defx_icon_root_icon Statement
highlight! default link Defx_filename_directory Directory
highlight! default link Defx_icon_directory_icon Directory
highlight! default link Defx_icon_opened_icon Directory
" Define mappings
nnoremap <silent><buffer><expr> o
\ defx#is_directory() ?
\ defx#do_action('open_tree', 'toggle') :
\ defx#do_action('drop')
nnoremap <silent><buffer><expr> <cr>
\ defx#is_directory() ?
\ defx#do_action('open_tree', 'toggle') :
\ defx#do_action('drop')
nnoremap <silent><buffer><expr> c
\ defx#do_action('copy')
nnoremap <silent><buffer><expr> C
\ defx#do_action('close_tree')
nnoremap <silent><buffer><expr> P
\ defx#do_action('search', fnamemodify(defx#get_candidate().action__path, ':h'))
nnoremap <silent><buffer><expr> m
\ defx#do_action('move')
nnoremap <silent><buffer><expr> p
\ defx#do_action('paste')
nnoremap <silent><buffer><expr> s
\ defx#do_action('multi', [['drop', 'split']])
nnoremap <silent><buffer><expr> v
\ defx#do_action('open', 'vsplit')
nnoremap <silent><buffer><expr> K
\ defx#do_action('new_directory')
nnoremap <silent><buffer><expr> N
\ defx#do_action('new_file')
nnoremap <silent><buffer><expr> M
\ defx#do_action('new_multiple_files')
nnoremap <silent><buffer><expr> d
\ defx#do_action('remove')
nnoremap <silent><buffer><expr> r
\ defx#do_action('rename')
nnoremap <silent><buffer><expr> yy
\ defx#do_action('yank_path')
nnoremap <silent><buffer><expr> q
\ defx#do_action('quit')
" nnoremap <silent><buffer><expr> <Space>
" \ defx#do_action('toggle_select') . 'j'
" nnoremap <silent><buffer><expr> *
" \ defx#do_action('toggle_select_all')
nnoremap <silent><buffer><expr> j
\ line('.') == line('$') ? 'gg' : 'j'
nnoremap <silent><buffer><expr> k
\ line('.') == 1 ? 'G' : 'k'
nnoremap <silent><buffer><expr> R
\ defx#do_action('redraw')
nnoremap <silent><buffer><expr> > '10<C-W>>'
nnoremap <silent><buffer><expr> < '10<C-W><'
nnoremap <silent><buffer><expr> <leader>p
\ defx#do_action('print')
nnoremap <silent><buffer><expr> P
\ defx#do_action('search', fnamemodify(defx#get_candidate().action__path, ':h'))
endfunction
call defx#custom#option('_', {
\ 'root_marker': '',
\ 'columns': 'indent:icon:filename',
\ 'winwidth': 50,
\ 'split': 'vertical',
\ 'direction': 'topleft',
\ })
call defx#custom#column('icon', {
\ 'directory_icon': '▸ ',
\ 'file_icon': ' ',
\ 'opened_icon': '▾ ',
\ 'root_icon': ' ',
\ })
call defx#custom#column('indent', {
\ 'indent': ' ',
\ })
call defx#custom#column('filename', {
\ 'min_width': 80,
\ 'max_width': 120,
\ })
nnoremap <silent><F1> :Defx `getcwd()` -search_recursive=`expand('%:p')` -toggle -buffer-name=` tabpagenr()`<cr>
" Move the cursor to the already-open Defx, and then switch back to the file
nnoremap <silent><leader>dn :Defx `getcwd()` -search_recursive=`expand('%:p')` -no-focus -buffer-name=` tabpagenr()`<cr>
" ================================= delimitMate ================================
" remove ` and * from the quotes
let delimitMate_quotes = "\" '"
" remove <> from match pairs
let delimitMate_matchpairs = "(:),[:],{:}"
" ================================= easy-align =================================
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap <leader>ta <Plug>(EasyAlign)
" Start interactive EasyAlign in visual and select mode (e.g. gaip)
vmap <leader>ta <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap <leader>ta <Plug>(EasyAlign)
xmap <leader>t= <Plug>(EasyAlign) =
vmap <leader>t= <Plug>(EasyAlign) =
nmap <leader>t= <Plug>(EasyAlign) =
xmap <leader>t: <Plug>(EasyAlign) :
vmap <leader>t: <Plug>(EasyAlign) :
nmap <leader>t: <Plug>(EasyAlign) :
xmap <leader>t" <Plug>(EasyAlign) "
vmap <leader>t" <Plug>(EasyAlign) "
nmap <leader>t" <Plug>(EasyAlign) "
" ================================= elm ========================================
let g:elm_setup_keybindings = 0
let g:elm_format_autosave = 1
" ================================= fugitive & rhubarb =========================
fun! SetupCommandAlias(from, to)
exec 'cnoreabbrev <expr> '.a:from
\ .' ((getcmdtype() is# ":" && getcmdline() is# "'.a:from.'")'
\ .'? ("'.a:to.'") : ("'.a:from.'"))'
endfun
call SetupCommandAlias("GBlame", "Git blame")
call SetupCommandAlias("Gblame", "Git blame")
call SetupCommandAlias("Gbrowse", "GBrowse")
call SetupCommandAlias("Gbrowse!", "GBrowse!")
let g:github_enterprise_urls = ['https://git.corp.stripe.com']
map <leader>gb :Git blame<cr>
" copy github / ghe link
map <leader>gl :GBrowse!<cr>
map <leader>gr :GBrowse!<cr>
vmap <leader>gl :GBrowse!<cr>
vmap <leader>gr :GBrowse!<cr>
" open github / ghe link
nmap <leader>go :GBrowse<cr>
vmap <leader>go :GBrowse<cr>
" ================================= fzf ========================================
set rtp+=/usr/local/opt/fzf " fzf is installed using Homebrew
" - Popup window (center of the screen)
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
" hidden by default, ctrl-\ to toggle
" let g:fzf_preview_window = ['right:hidden', 'ctrl-\']
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-x': 'split',
\ 'ctrl-d': 'split',
\ 'ctrl-e': 'split',