-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
1510 lines (1350 loc) · 47.6 KB
/
.vimrc
File metadata and controls
1510 lines (1350 loc) · 47.6 KB
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
" set verbose=15
" set verbosefile=filename.txt
" 1.if hidden is not set, TextEdit might fail.
set hidden
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup
" Better display for messages. I will set back to 1 for now
set cmdheight=1
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=200
" don't give |ins-completion-menu| messages.
set shortmess+=c
" gutter space for lsp info on left
set signcolumn=auto:2
set cedit=<C-e>
"" 2.Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
if executable("rg")
set grepprg=rg\ --engine\ auto\ --vimgrep\ --smart-case\ --hidden
set grepformat=%f:%l:%c:%m
endif
" ************** MAC SENSITIVE **************%%%1
if !exists("g:os")
if has("win64") || has("win32") || has("win16")
let g:os = "Windows"
else
let g:os = substitute(system('uname'), '\n', '', '')
endif
endif
if g:os == "Linux"
let home_dir = "/home/benson"
set runtimepath+=~/Dropbox/Code/Projects/my_plugin
let g:vsnip_snippet_dir = expand('~/Dropbox/Code/dotfiles/my-snippets')
set runtimepath+=~/Dropbox/Code/dotfiles/my-snippets
"Remember to call :UpdateRemotePlugins manually
else
let home_dir = "/Users/benson"
set runtimepath+=~/Documents/Code/Projects/my_plugin
set runtimepath+=~/dotfiles/my-snippets
let g:vsnip_snippet_dir = expand('~/dotfiles/my-snippets')
endif
" ************** OPTIONS **************%%%1
" Always put regexes in function rather than as expr
" -> vim will do weird escapes otherwise
" 1. First let me fold line comments
function! CheckSingleLineComment()
let thisline = getline(v:lnum)
return thisline =~# '\v^\s{-}\/\/'
endfunction
let g:in_multiline_comment = 0
" function! MatchComment()
" if (g:in_multiline_comment)
" if (end_of_multiline(v:lnum))
" let g:in_multiline_comment = 0
" return 1
" else
" return 1
" endif
" else
" if (start_of_multiline(v:lnum))
" let g:in_multiline_comment = 1
" return 1
" else
" return CheckSingleLineComment(v:lnum)
" endif
" endif
" endfunction
" set foldmethod=expr
set foldexpr=CheckSingleLineComment()
autocmd FileType *.cpp,*.c,*.h,*.java syn region myCComment start="/\*" end="\*/" fold keepend transparent
" set foldexpr=getline(v:lnum)=~'^\\s*'.&commentstring[0]
" set fdo-=search "only search in unfolded text
set foldmethod=marker
" set foldmarker=%%%,^^^
autocmd FileType cpp setlocal foldmethod=expr
"set foldtext="MyFoldText()"
"function MyFoldText()
"let line = getline(v:foldstart)
"See help for full
"return v:folddashes . sub
"endfunction
"Since vim will run some bash commands on startup, so make sure shell is POSIX
"compatible.Mac has this but not /usr/bin/bash
set shell=/bin/bash
" set iskeyword+=- "Since arrow operator begins with this
set iskeyword+=_
syntax enable
" Temp for creating plugin
"set verbosefile=verbose.txt
set ignorecase
set smartcase "default case insensitive search. WIll change if captial letter in search
set linebreak "will not wrap in middle of word
set breakindent "wrapped lines will start at same indentation level
set breakindentopt=sbr
" I use a unicode curly array with a <backslash><space>
set showbreak=↪>\
set timeoutlen=600 "Any smaller and copy to global register will be too slow
set nocompatible
set hidden
set number relativenumber
set showcmd "To show keys pressed in normal mode; useful for completing Vim sentences
filetype on
filetype plugin on
"set cindent
set hlsearch
set incsearch
set lazyredraw
set laststatus=2
set t_Co=256
set foldenable
set foldlevel=0
"set list lcs =tab:\|\
"set list
"set listchars=tab:\|\
set ruler
set splitright
"set splitbelow
" set number ""relativenumber
set title
set cursorline
set autoread "doesn't work in terminal atm
set gdefault "/g is used in command mode substitution by default
"autocomplete with spellcheck
set complete+=kspell
"set clipboard=unamedplus
set wrap
set mouse=a
set tabstop=4
set expandtab "Tabs are now spaces, whatever that means
set wildmenu "This is default in Neovim
set showmatch "Will highlight matching parantheses, brackets, etc"
set shiftwidth=4
set autoindent
set undofile
"set undodir=~/.undodir/
set colorcolumn=80
" ************** PLUGINS **************%%%1
call plug#begin('~/.vim/plugged')
"Plug 'ThePrimeagen/vim-be-good'
" Plug 'bbli/filter-jump.nvim', {'do': ':UpdateRemotePlugins'}
" Plug '~/Dropbox/Code/Projects/my_plugin', {'do': ':UpdateRemotePlugins'}
"Plug 'ripxorip/aerojump.nvim', { 'do': ':UpdateRemotePlugins' }
"Vim Testing Frameworks
"---
" Plug 'dhruvasagar/vim-testify' "Vimscript unit testing
" Plug 'junegunn/vader.vim' "Vimscript integration testing
" Plug 'tpope/vim-scriptease' "Vimscript error messages can be jumped to in the quickfix list
" Plug 'LucHermitte/lh-vim-lib' "For the logging library + C++ algorithms in Vimscript -> loggin to quickfix kills space though?
"Visual
"---
" Plug 'vim-airline/vim-airline'
" Plug 'bbli/vim-airline'
" Plug 'vim-airline/vim-airline-themes'
" Plug 'edkolev/tmuxline.vim'
Plug 'edkolev/promptline.vim'
Plug 'mhinz/vim-startify'
Plug 'gruvbox-community/gruvbox'
"Plug 'sainnhe/sonokai'
Plug 'bbli/edge'
"Plug 'drewtempelmeyer/palenight.vim'
Plug 'rakr/vim-one'
"Conveniences
"---
" For renaming tabs
" Plug 'gcmt/taboo.vim'
Plug 'dbakker/vim-projectroot'
Plug 'roxma/vim-tmux-clipboard'
" Plug 'google/vim-searchindex' "Apparantly causes issues with GitRipGrep atm
" Below Plugin not that useful since I can use tabs for that purpose
"Plug 'troydm/zoomwintab.vim'
" Plug 'osyo-manga/vim-over'
"Plug 'MattesGroeger/vim-bookmarks'
" Plug 'gelguy/wilder.nvim', { 'do': ':UpdateRemotePlugins' }
"Plug 'unblevable/quick-scope'
"Plug 'jiangmiao/auto-pairs'
" Plug 'scrooloose/nerdcommenter'
Plug 'AndrewRadev/bufferize.vim' "To show messages in a real buffer
Plug 'tpope/vim-commentary'
Plug 'bronson/vim-visual-star-search'
Plug 'andymass/vim-matchup'
" Plug 'Yggdroot/indentLine'
"Plug 'tpope/vim-surround'
" Plug 'dohsimpson/vim-macroeditor'
" using this fork so that MACROS can be repeated too. Not working though?
" Plug 'svermeulen/vim-macrobatics'
Plug 'svermeulen/vim-repeat'
Plug 'machakann/vim-sandwich'
Plug 'embear/vim-foldsearch'
"So <C-j> works properly -> Actually still doesn't work
"Plug '~/.vim/plugged/bash-support'
" Plug 'justinmk/vim-sneak' -> my plugin is better
"Plug 'goldfeld/vim-seek'
"Plug 'jayflo/vim-skip'
" Plug 'rhysd/clever-f.vim' "Actually this prevents iterative f hopping
" Plug 'https://gitlab.com/yorickpeterse/nvim-window.git', { 'branch': 'main'} "I rather use motions to move rather than labels
" Plug 'https://gitlab.com/yorickpeterse/nvim-pqf.git', { 'branch': 'main'}
"Special Windows
"---
Plug 'scrooloose/nerdtree'
"Plug 'tpope/vim-vinegar'
"Plug 'milkypostman/vim-togglelist'
"Plug 'jceb/vim-editqf'
Plug 'romainl/vim-qf'
Plug 'AndrewRadev/qftools.vim', { 'branch': 'main' }
" Plug 'mileszs/ack.vim'
"Plug 'jremmen/vim-ripgrep', {'frozen': 1}
Plug 'bbli/vim-ripgrep'
" Plug 'mhinz/vim-grepper'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all','frozen':1}
"Plug 'junegunn/fzf.vim', {'frozen': 1}
Plug 'bbli/fzf.vim'
Plug 'mbbill/undotree'
"Plug 'vimlab/split-term.vim'
Plug 'voldikss/vim-floaterm'
Plug 'bbli/vim-logreview'
"Plug 'vim-voom/VOoM'
"Language Server
Plug 'tpope/vim-projectionist' "This plugin also helps in setting file local variables, like `makerpg`
"---
"Plug 'majutsushi/tagbar'
Plug 'bbli/tagbar' "for changing tagbar highlight to IncSearch
" Plug 'liuchengxu/vista.vim' "Doesn't work on mac?
Plug 'ludovicchabant/vim-gutentags' "Vista auto does this
"Plug 'm-pilia/vim-ccls'
"Plug 'roxma/nvim-yarp'
"Plug 'ncm2/ncm2'
"Plug 'ncm2/ncm2-ultisnips'
"Plug 'ncm2/ncm2-bufword'
"Plug 'ncm2/ncm2-path'
"Plug 'fgrsnau/ncm2-otherbuf', { 'branch': 'ncm2' }
" Plug 'neoclide/coc.nvim', {'branch': 'release'}
"Plug 'antoinemadec/coc-fzf', {'branch': 'release'}
"Plug 'jackguo380/vim-lsp-cxx-highlight'
"Plug 'wellle/tmux-complete.vim'
"Plug 'cespare/vim-toml'
"Plug 'dag/vim-fish'
"Plug 'pboettch/vim-cmake-syntax'
"Plug 'rhysd/vim-llvm'
Plug 'Raku/vim-raku'
Plug 'elixir-editors/vim-elixir'
"Terminal Interactions
"---
" Plug 'vim-test/vim-test'
Plug 'bbli/vim-test', {'branch': 'benson-catch'}
" Plug 'rcarriga/vim-ultest', { 'do': ':UpdateRemotePlugins' } "Not working atm(and probably only works with correct errorformat. ALSO NOTE I ADDING LOGGING TO THE PLUGIN ITSELF
"Plug 'alepez/vim-gtest' "Hardcodes certain things
"If I want to explicitly choose the window for vim test
" Plug 'esamattis/slimux'
" For asynchronous make builds + supposedly help vim-test out regardless
" if chosen as strategy
Plug 'tpope/vim-dispatch'
" Plug 'neomake/neomake'
Plug 'mattboehm/vim-unstack'
" Plug 'benmills/vimux'
" Plug 'jpalardy/vim-slime', { 'branch': 'main'} "useful for creating specific state in script for profiling
" used by vim-test. NOTE YOU HAVE TO LET IT CREATE THE INITAL WINDOW
"Plug 'christoomey/vim-tmux-runner'
" Plug 'skywind3000/asynctasks.vim'
" Plug 'skywind3000/asyncrun.vim'
"Git
"---
"For Gvsplit and co
Plug 'tpope/vim-fugitive'
Plug 'jreybert/vimagit'
Plug 'f-person/git-blame.nvim'
" Plug 'airblade/vim-gitgutter'
" This plugin cannot stage hunks
"Plug 'mhinz/vim-signify'
"For diffing code that is not between branches
"Plug 'AndrewRadev/linediff.vim'
" When I work on a large codebase and need to see past logs that modified a certain line
"Plug 'rhysd/git-messenger.vim'
"Snippets
"---
" Plug 'SirVer/ultisnips', {'for': ['rust', 'cpp', 'vim', 'lua','python','sh','cmake','go','fish','perl', 'haskell']}
" Plug 'hrsh7th/vim-vsnip'
" Plug 'hrsh7th/vim-vsnip-integ'
" Plug 'honza/vim-snippets'
" Plug 'quangnguyen30192/cmp-nvim-ultisnips', {'branch': 'main'}
" Plug 'dawikur/algorithm-mnemonics.vim'
"Latex
"---
"Plug 'lervag/vimtex', { 'tag': 'v1.0' }
"Plug 'brennier/quicktex'
"Text Objects
"---
"Plug 'coderifous/textobj-word-column.vim'
"Plug 'glts/vim-textobj-indblock'
"Plug 'kana/vim-textobj-user'
Plug 'wellle/targets.vim'
Plug 'michaeljsmith/vim-indent-object'
"Plug 'wellle/context.vim'
" For camelCase word deletion
"Plug 'Julian/vim-textobj-variable-segment'
call plug#end()
source ~/.vim/plugged/vim-sandwich/macros/sandwich/keymap/surround.vim
if !has('nvim')
set ttymouse=xterm2
endif
"Making ALt usable on Linux
for i in range(97,122)
let c = nr2char(i)
exec "map \e".c." <M-".c.">"
exec "map! \e".c." <M-".c.">"
endfor
"augroup markdown
"au!
"au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown
"augroup END
"""Leader maps must be defined after this command.
let mapleader=" "
let maplocalleader="-"
" ************** LEADER MAPS **************%%%1
" ---Misc--- %%%2
"nnoremap <leader><leader>t :MerlinTypeOf<CR>
"nnoremap <leader><leader>i :call <SID>show_documentation()<CR>
" nnoremap <leader>l 40l
" Override marks for now
nnoremap <leader><leader>z :nohlsearch<CR>
" nnoremap <C-t> <C-z>
" <C-^> switches between two files
nnoremap <leader>el :UnstackFromTmux<CR>
nnoremap <leader>ec :sign unplace<CR>
"let g:qf_auto_open_quickfix = 0
"let g:qf_auto_open_loclist = 0
"let g:qf_shorten_path = 0
let g:toggle_qf = 0
function! ToggleQuickfixList()
if g:toggle_qf == 0
let g:toggle_qf = 1
execute "copen"
else
let g:toggle_qf = 1
execute "cclose"
endif
endfunction
nmap <leader>tq :call ToggleQuickfixList()<CR>
nmap <leader>qn <Plug>(qf_newer)
let g:qf_mapping_ack_style = 1
let g:qf_nowrap=0
nmap <leader>qN <Plug>(qf_older)
nmap <leader>qq <Plug>(qf_qf_switch)
" Don't apply g when substituting
nnoremap <leader>qr :cdo s/
" nnoremap <leader>qr :cdo s/
" coc's version is more useful as it will generate based on file path, not current
" directory
nnoremap <F9> :!ctags -R --sort=yes .<CR>
" ---Buffer Related---{{2
command! BufOnly silent! :%bd|e#|bd#<CR>
nnoremap <leader>bD :BufOnly<CR>
nnoremap <leader>ba :A<CR>
nnoremap <leader>bs <C-^>
nnoremap <silent> <leader>bk :bwipeout<CR>
nnoremap <leader>bf :ZenMode<CR>
nnoremap <leader>bz :ZenMode<CR>
nnoremap <leader>bb <cmd>Telescope buffers<cr>
nnoremap <leader>br :%s/\<<C-r><C-w>\>/
" nnoremap <leader>br :%s/\<<C-r><C-w>\>/
nnoremap <leader>bm :g/\<<C-r><C-w>\>/norm! @m<CR>
" ---Edit Related--- %%%2
" stuff
" nmap gc <Plug>NERDCommenterToggle
" vmap gc <Plug>NERDCommenterToggle
vmap <unique> <leader>c <Plug>Commentary
vmap <unique> <leader><leader>c <Plug>Commentary
omap <unique> <leader>c <Plug>Commentary
nmap <unique> <leader>cc <Plug>CommentaryLine
nmap <unique> <leader><leader>c <Plug>CommentaryLine
nnoremap <leader><leader>p "+p
nnoremap <leader><leader>P "+P
vnoremap <leader><leader>y "+y
nnoremap <leader><leader>y "+yy
vnoremap <leader><leader>d "+d
nnoremap <leader><leader>d "+dd
nnoremap <unique> <leader><leader>t :ISwapWith<CR>
vnoremap mm :'<,'>norm @m<CR>
vnoremap lc :'<,'>norm 0i--<CR>
vnoremap lC :'<,'>norm 0xx<CR>
vnoremap : :'<,'>norm
nnoremap <leader>me :MacroEdit m<CR>
" nnoremap <leader>mm @m
nnoremap <leader><leader>m @m
nnoremap <leader>ma :%normal @m<CR>
vnoremap <leader><leader>m :'<,'>normal @m<CR>
nmap <leader>mr <plug>(Mac_NameCurrentMacro)
nmap <leader>mf <plug>(Mac_SearchForNamedMacroAndPlay)
nmap <leader>md <plug>(Mac_SearchForNamedMacroAndDelete)
nmap <leader>mo <plug>(Mac_SearchForNamedMacroAndOverwrite)
" ---Workspace Related--- %%%2
nnoremap <leader>ws :mks ~/.vim/sessions/default.vim<CR>
nnoremap <leader>wl :source ~/.vim/sessions/default.vim<CR>
nnoremap <leader>wn :tabnext<CR>
nnoremap <leader>wp :tabprevious<CR>
" TODO: change to w to be aligned with emac's workspace?
" Also, my hands moving to w feels much better than moving to t,
" As I can still use my pointer finger after clicking w
" Last of all, t can be back to being "Toggle" keymaps
nnoremap <leader>wo :tab split<CR>
nnoremap <leader>wO <C-w>T
nnoremap <leader>wk :tabc<CR>
" nnoremap <leader>wr :TabooRename
"nnoremap <leader>ws :TabooReset<CR>
" ---Git Related--- %%%2
autocmd FileType magit nnoremap <buffer> <leader>gy "gyy
autocmd FileType magit nnoremap <buffer> <leader>gp "gp
" nmap <leader>gp <Plug>(GitGutterPreviewHunk)
" nmap gs <Plug>(GitGutterStageHunk)
" vmap gs <Plug>(GitGutterStageHunk)
" nmap <leader>gu <Plug>(GitGutterUndoHunk)
" nmap <leader>gn <Plug>(GitGutterNextHunk)
" nmap <leader>gN <Plug>(GitGutterPrevHunk)
nnoremap <leader>gm :Magit<CR>
" nmap <leader>gf :GitGutterFold<CR>
" nmap <leader>go <Plug>(git-messenger)
nmap <leader>gl :Gclog -10000<CR>
nnoremap <unique> <leader>gc :Gclog -10000 --grep=
" nnoremap <unique> <leader>gc :Gclog --grep=
nnoremap <unique> <leader>gs :Gclog -10000 -S
" nnoremap <unique> <leader>gs :Gclog -S
nnoremap <unique> <leader>gf :Gclog -10000 -- %<CR>
" Above is better b/c if commit on another branch -> will have a name
"nmap <leader>gl :VTerm<CR>git tree<CR>
nmap <leader>gg :G<CR>
nnoremap <leader>gd :Gvdiff
nnoremap <leader>gb :Git blame<CR>
" ---Terminal Related --- %%%2
" <root> option only works with FloattermToggle
let g:shell_count = 0
function! ToggleShell()
if g:shell_count == 0
let g:shell_count = 1
execute "FloatermNew --cwd=<root> --name=shell"
execute "bn"
execute "normal \<C-o>"
else
execute "FloatermToggle shell"
endif
endfunction
let g:test_shell_count = 0
function! ToggleTestShell()
if g:test_shell_count == 0
let g:test_shell_count = 1
execute "FloatermNew --cwd=<root> --name=test"
execute "bn"
execute "normal \<C-o>"
else
execute "FloatermToggle test"
endif
endfunction
let g:vifm_count = 0
function! ToggleVifm()
if g:vifm_count == 0
let g:vifm_count = 1
" execute "FloatermKill vifm"
echo "vifm_count = " .. g:vifm_count
execute "FloatermNew --name=vifm --cwd=<buffer> vifm"
else
let g:vifm_count = 0
echo "vifm_count = " .. g:vifm_count
let output = execute("FloatermKill vifm")
" echo output
" Means we need to open instead
if output != ""
execute "FloatermNew --name=vifm --cwd=<buffer> vifm"
endif
" 1.Open Vifm
" 2. Click Enter
" 3. Vifm is now closed, but vifm_count still 1
" 4. Try to call ToggleVifm again, will call "FloatermKill" instead of
" open
endif
endfunction
nnoremap <leader>ts :call ToggleShell()<CR>
nnoremap <leader>os :call ToggleShell()<CR>
nnoremap <leader>ot :call ToggleTestShell()<CR>
nnoremap <leader>tn :call ToggleVifm()<CR>
nnoremap <leader>ov :call ToggleVifm()
function s:open_in_normal_window() abort
let f = findfile(expand('<cfile>'))
if !empty(f) && has_key(nvim_win_get_config(win_getid()), 'anchor')
FloatermHide
execute 'e ' . f
endif
endfunction
autocmd FileType floaterm nnoremap <silent><buffer> gf :call <SID>open_in_normal_window()<CR>
let g:floaterm_opener="edit"
let g:floaterm_autoclose=0
let g:floaterm_width = 0.8
let g:floaterm_height = 0.95
nnoremap <leader>sn <cmd>FloatermNext
nnoremap <leader>sN <cmd>FloatermPrev
" Rerun last command
command -nargs=+ ShellSend :call v:lua.require'benson-term'.benson_floaterm_send(<q-args>)
nnoremap <leader>ss <cmd>lua require('benson-term').send_last_string_to_term()<CR>
" Run a specific command
nnoremap <leader>sl :ShellSend
nnoremap <leader>sh <cmd>lua require('benson-term').send_string_from_history()<CR>
" ---Open + Find Related--- %%%2
" fzf and ripgrep settings
let g:rg_highlight = 1
command! -bang -nargs=? -complete=dir HFiles
"\ call fzf#vim#files(<q-args>, {'source': 'rg --hidden --ignore .git -g ""'}, <bang>0)
"\ call fzf#vim#files(<q-args>, fzf#wrap({'source': 'rg --hidden --ignore --hidden .git'}), <bang>0)
\ call fzf#vim#files(<q-args>, fzf#wrap({'source': 'rg --files --hidden'}), <bang>0)
"command! -bang -nargs=? -complete=dir Files
"\ call fzf#vim#files(<q-args>, {'source': 'rg --ignore .git -g ""'}, <bang>0)
"fix this
"2
command! -bang OP call fzf#run(fzf#wrap({'source':'rg --files --hidden','sink':'' 'dir':"~/"}))<CR>
"1
"command! -bang OP call fzf#vim#complete#path('rg --files',{'dir':home_dir})
"nnoremap <leader>op :call fzf#vim#complete#path('rg --files',{'dir':home_dir})<CR>
"nnoremap <leader>op :OP<CR>
nnoremap <leader>oo :GFiles<CR>
"nnoremap <leader>oa :FZF<CR>
nnoremap <leader>oa :HFiles<CR>
"nnoremap <leader>ob :CocList buffers<CR>
nnoremap <leader>od :BD<CR>
" TODO: Replace with meta-;??
nnoremap <leader>oc :Commands<CR>
"nnoremap <leader>os :History/<CR>
"nnoremap / :History/<CR>
"nnoremap : :Commands<CR>
"nnoremap <leader>: :
" nnoremap <leader>oi :HFiles<CR>
" nnoremap <leader>ob :Files ../<CR>
nnoremap <leader>oh :History<CR>
nnoremap <leader>or :Registers<CR>
nnoremap <leader>oy :Registers<CR>
" nnoremap <leader>op :CocList mru<CR>
"nnoremap <leader><leader>oh :FZF ~<CR>
nmap <leader>oq <Plug>(qf_qf_toggle)
"My wrapper so that I don't need to modify the plugin itself
"fun
let g:rg_command = 'rg --vimgrep --hidden -g "!.git"'
"command! -bang -nargs=* GRg
"\ call fzf#vim#grep('rg --hidden -g "!.git" '.shellescape(<q-args>), 0,
"\ {'dir': systemlist('git rev-parse --show-toplevel')[0]}, <bang>0)
"This way doesn't work for some reason
"\ call fzf#vim#grep(<q-args>, 0, {'source': 'rg --hidden ', 'dir': systemlist('git rev-parse --show-toplevel')[0]}, <bang>0)
command! -bang -nargs=* GGrep
\ call fzf#vim#grep(
\ 'git grep --line-number -- '.shellescape(<q-args>), 0,
\ {'dir': systemlist('git rev-parse --show-toplevel')[0]}, <bang>0)
nnoremap <leader>ff :Telescope live_grep<CR>
" nnoremap <leader>ff :GitRipGrep
" Search in git repo
function! s:find_git_root()
return system('git rev-parse --show-toplevel 2> /dev/null')[:-2]
endfunction
function! RipGrepProjectHelper(pattern)
" we cannot use shell escape b/c it will SINGLE QUOTE the pattern ->
" which prevents passing ADDITIONAL ARGUMENTS
execute "grep " .. a:pattern .. " " .. s:find_git_root()
endfunction
command! -nargs=1 RipGrepProject call RipGrepProjectHelper(<q-args>)
nnoremap <leader>fp :RipGrepProject
nnoremap <leader>fa :grep
nnoremap <leader>fw :Ggrep \b<C-r><C-w>\b<CR>
nnoremap <leader>fs :Telescope lsp_dynamic_workspace_symbols<CR>
" Doesn't really work
" nnoremap <leader>fs :tabnew %<CR>:Fw<CR>
" nnoremap <leader>fw :Ggrep <C-r><C-w><CR>
autocmd FileType logreview nnoremap <leader>fl :RemoveAllButClass
autocmd FileType logreview nnoremap <leader>fe :RemoveAllButClass BENSON_DEBUG<CR>
autocmd FileType log nnoremap <leader>fl :RemoveAllButClass
autocmd FileType log nnoremap <leader>fe :RemoveAllButClass BENSON_DEBUG<CR>
let g:eventignore_toggle = 0
function! SetEventIgnore()
if g:eventignore_toggle == 0
let g:eventignore_toggle = 1
setlocal eventignore=all
else
let g:eventignore_toggle = 0
setlocal eventignore=
endif
endfunction
nnoremap <leader>te :call SetEventIgnore()<CR>
" :'<,'>norm! @a to apply the macro only to a visual selection
" (hit : in visual mode to switch to command mode)
function! JumpToBookMark()
execute('BookmarkShowAll')
call feedkeys("\<CR>")
endfunction
" ---Compling/Running/Project Related--- %%%2
"TODO: change prefix to 'r' or 'p' for run/project?
"nnoremap <leader>sp :SlimuxREPLConfigure<CR>
"nnoremap <leader>ss :SlimuxShellRun
nnoremap <leader>pe <cmd>TroubleToggle lsp_workspace_diagnostics<CR>
" For some reason need to do two escapes
" nnoremap <leader>pt :GitRipGrep TODO\\|NOTE<CR>
nnoremap <leader>pt :GitRipGrep TODO<CR>
nnoremap <leader>jt :call JumpToBookMark()<CR>
" mm to toggle a bookmark
" nnoremap <leader>se <cmd>TroubleToggle lsp_workspace_diagnostics<CR>
" nnoremap <leader>ss :ProjectRootExe TestNearest<CR>
" nnoremap <leader>sl :ProjectRootExe TestLast<CR>
" nnoremap <leader>sf :ProjectRootExe TestFile<CR>
" nnoremap <leader>sp :ProjectRootExe TestSuite<CR>
nmap <leader><leader>t <Plug>PlenaryTestFile
nmap <leader><leader>r <Plug>LuaRun
" nnoremap <leader>sm :Messages<CR>
" vim test also integrates with projectionist plugin
let g:VimuxUseNearest=1
" nnoremap <leader>sp :VimuxOpenRunner<CR>
"nnoremap <leader>sl :VimuxPromptCommand<CR>
"nnoremap <leader>ss :VimuxRunLastCommand<CR>
"nnoremap <leader>si :VimuxInspectRunner<CR>
"nnoremap <localleader>vs :VimuxInterruptRunner<CR>
"
"nnoremap <leader>sl :VtrSendLinesToRunner<CR>
"vnoremap <leader>sl :VtrSendLinesToRunner<CR>
"nnoremap <leader>sp :VtrAttachToPane<CR>
"nnoremap <leader>ss :VtrSendCommand<CR>
"nnoremap <leader>sf :VtrFlushCommand<CR>
" Vimux's version is better
"nnoremap <leader>sz :VtrFocusRunner<CR>
" These didn't work that well
"nnoremap <leader>sd :VtrDetachRunner<CR>
"nnoremap <leader>sa :VtrReattachRunner<CR>
"
"nnoremap <leader>sd :VtrSendCtrlD<CR>
"nnoremap <leader>ss %
" ---Toggles--- %%%2
"nnoremap <leader>to :VoomToggle markdown<CR>
nnoremap <leader>tw :AirlineToggleWhitespace<CR>
function! ToggleFoldSearch()
if &foldopen =~ "search"
set foldopen-=search
else
set foldopen+=search
endif
endf
nnoremap <leader>tf :call ToggleFoldSearch()<CR>
nnoremap <leader>tg :GitBlameToggle<CR>
nnoremap <leader>tc :TSContextToggle<CR>
nnoremap <leader>tu :UndotreeToggle<CR>
nnoremap <leader>tt :TagbarToggle<CR>
"nnoremap <leader>ts :set spell!<CR>
" nnoremap <leader>ts :FloatermToggle<CR>
let s:nerdtree_open = 0
function! ToggleNerdTree()
" NOTE: an aside, but notice that we have the choice here of setting
" before activating or vice versa -> from RLE
if s:nerdtree_open
let s:nerdtree_open = 0
echom "close"
execute "NERDTreeToggle"
else
let s:nerdtree_open = 1
echom "open"
execute "NERDTreeFind"
endif
endf
" nnoremap <leader>tn :call ToggleNerdTree()<CR>
"nnoremap <leader>tp :set paste!<CR>
"nnoremap <leader>ti :IndentGuidesToggle<CR>
"nmap <leader>tq :copen<CR>
"nmap <leader>tl :lopen<CR>
"nmap <leader>tq :call ToggleQuickfixList()<CR>
"nmap <leader>tl :call ToggleLocationList()<CR>
nmap <leader>tl <Plug>(qf_loc_toggle)
" nmap <leader>jt <Plug>(coc-refactor)
" nmap <leader>ji <Plug>(coc-funcobj-i)
" nmap <leader>jj <Plug>(coc-funcobj-a)
" ---Jump Related--- %%%2
" nmap <leader>jf <Plug>(coc-float-jump)
" nnoremap <leader>jb <C-t>
nnoremap <leader>jc g;
nnoremap <leader>jC g,
"TODO: rarely used and will soon be replaced by harpoon
" nnoremap <leader>jm `M
" nnoremap <leader>mm mM
" ---Diff View Related--- %%%2
nnoremap <leader>dn ]c
nnoremap <leader>dN [c
"nnoremap <leader>dl :.diffput<CR>
"Grab from left side
nmap <leader>dh :diffget //2<CR>
"Grab from right side
nmap <leader>dl :diffget //3<CR>
nnoremap <leader>dp dp
"autocmd BufEnter *.py nnoremap <buffer> <leader>c I#<esc>
"autocmd BufEnter *.m nnoremap <buffer> <leader>c I%<esc>
" ************** LOCAL LEADER MAPS **************%%%1
nnoremap <localleader>v :e ~/.vimrc<CR>
nnoremap <localleader>b :e ~/.bash_aliases<CR>
nnoremap <localleader>t :e ~/.tmux.conf<CR>
nnoremap <localleader>g :e ~/.gitconfig<CR>
nnoremap <localleader>n :e ~/.config/nvim/init.vim<CR>
nnoremap <localleader>k :e ~/.config/kitty/kitty.conf<CR>
nnoremap <localleader>f :e ~/.config/fish/config.fish<CR>
nnoremap <localleader>x :e ~/.config/xmonad/xmonad.hs<CR>
nnoremap <localleader>l :e ~/.init.lua<CR>
" nnoremap <localleader>s :e ~/.config/starship.toml<CR>
" nnoremap <localleader>s :VsnipOpen!<CR>
" nnoremap <localleader>c :CocConfig<CR>
"nnoremap <localleader>ww :MarkdownPreview<CR>
"nnoremap <localleader>wc :MarkdownPreviewStop<CR>
"nnoremap <localleader>e :!python % <CR>
"nmap <localleader>e <Plug>(processing-run)
"nnoremap <localleader>t <C-W>T
" ************** META MAPS **************%%%1
"To move lines intuitively
"Alt and Shift combos won't work with K
"But Ctrl will mess up window specific mappings
nnoremap <M-k> :m .-2<CR>==
nnoremap <M-j> :m .+1<CR>==
vnoremap <M-j> :m '>+1<CR>gv=gv
vnoremap <M-k> :m '<-2<CR>gv=gv
nnoremap <C-w><Space> <C-w>=
" nnoremap <C-w><C-w> <C-w>p
nnoremap <C-w>; <C-w>p
"nnoremap <C-h> <C-w><C-h>
"nnoremap <C-j> <C-w><C-j>
"nnoremap <C-k> <C-w><C-k>
"nnoremap <C-l> <C-w><C-l>
map <M-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
" ************ FN MAPS ************%%%1
"nnoremap <F2> :TagbarToggle<CR>
"nnoremap <F3> :AirlineToggleWhitespace<CR>
"nnoremap <F4> :setlocal spell spelllang=en_us<CR>
"nnoremap <F5> :set nospell<CR>
"nnoremap <silent> <F8> :NERDTreeToggle<CR>
"nnoremap <F10> :set nopaste
" ************** SEMI COLON MAPS **************%%%1
inoremap ;c <C-c>
vnoremap ;c <C-c>
inoremap ;; ;
vnoremap ;w <C-c>:w<CR>
inoremap ;w <C-c>:w<CR>
" nnoremap ;q <C-z>
nnoremap ;q :q<CR>
nnoremap ;z :q!<CR>
nnoremap ;w <C-c>:w<CR>
nnoremap ;n :bn<CR>
nnoremap ;N :bp<CR>
nnoremap <silent> ;d :bwipeout<CR>
nnoremap ;D :bwipeout!<CR>
"inoremap <C-m> <C-C>la
inoremap <C-l> <C-c>la
function! s:list_buffers()
redir => list
silent ls
redir END
return split(list, "\n")
endfunction
function! s:delete_buffers(lines)
execute 'bwipeout' join(map(a:lines, {_, line -> split(line)[0]}))
endfunction
command! BD call fzf#run(fzf#wrap({'source': s:list_buffers(),
\ 'sink*': { lines -> s:delete_buffers(lines) },
\ 'options': '--multi --reverse --bind ctrl-a:select-all+accept'}))
nnoremap <leader>; ,
nnoremap ;t :MtaJumpToOtherTag<CR>
nnoremap ;o <C-^>
nnoremap ;r @:
" ************** NORMAL MODE MAPS **************%%%1
" nnoremap <unique> k gk
" nnoremap <unique> j gj
nnoremap <unique> gk k
nnoremap <unique> gj j
"nnoremap EE @
nnoremap <unique> C c$
nnoremap <unique> D d$
nnoremap Y y$
nnoremap <unique> E $
nnoremap <unique> gE g$
"nnoremap <unique> W 0w
" to jump between brackets/parantheses
nnoremap S %
"nnoremap w W
"nnoremap W w
"nnoremap b B
"nnoremap B b
" nnoremap n nzz
" nnoremap N Nzz
nnoremap <unique> <expr> k v:count > 1 ? "m'" . v:count . "k" : "gk"
nnoremap <unique> <expr> j v:count > 1 ? "m'" . v:count . "j" : "gj"
nnoremap <unique> gb gi
"Training vim skip
nnoremap <unique> h <Nop>
nnoremap <unique> l <Nop>
nnoremap <unique> <C-g> <cmd>close<CR>
vnoremap <unique> <C-g> <ESC>
vnoremap > >gv
vnoremap < <gv
" ************** COMMAND MODE MAPS **************%%%1
cnoremap sE %s
" nnoremap / /\<
nnoremap <leader>/ /
"For grep
"cnoremap cf cfirst
" cnoremap SB set scrollbind
" cnoremap NSB set noscrollbind
"cnoremap tc tabc
"cnoremap tn tabnext
"cnoremap tN tabprevious
"cnoremap tC tabc<CR>
" cnoremap vsb vertical sb
" nnoremap <leader><leader>t :tabn<CR>
" ************** OPERATOR MODE MAPS **************%%%1
"onoremap w W
"onoremap W w
"onoremap b B
"onoremap B b
"onoremap ) i)
"onoremap ] i]
" onoremap s i]
" onoremap S a]
onoremap p i)
onoremap P a)
onoremap ll $
" Cannot since this will override cc
onoremap <expr> c v:operator ==# 'c' ? 'c' : 'i}'
onoremap C a}
" So instead
" onoremap b i}
" onoremap B i}
" ************** INSERT MODE MAPS **************%%%1
" To be honest, I don't think this is nesscary. Those keys are not awkward,
" and I only mapped it because I was fixated on insert normal mode
"inoremap ]] <C-c>A
"make cause some issues, such as dummy -> but will be amortized zero cost with
"autocomplete
inoremap , ,<c-g>u
inoremap . .<c-g>u
inoremap { {<c-g>u
inoremap [ [<c-g>u
imap <C-f> <plug>(fzf-complete-path)
" imap <C-l> <C-x><C-l> "move one character over is used more and has same
" mapping
"inoremap " ""<left>
"inoremap ' ''<left>
"inoremap ( ()<left>
"inoremap [ []<left>
"inoremap { {}<left>
" ************** CONTROL/SPECIAL KEY(TAB,etc) MAPS **************%%%1
"This may be dangerous as vim has a lot of built in control key maps
"Only do to overide
"nnoremap <C-]> :vs<CR><C-]>
"nnoremap <C-[> <C-t>
"nnoremap <C-j> :vs<CR><C-]>
"nnoremap <C-n> <C-^>
xmap <C-e><C-e> <Plug>SlimeRegionSend
nmap <C-e><C-e> <Plug>SlimeLineSend
nmap <C-d> <C-b>
let g:fold_flag = 0
function! ToggleFoldAll()
if g:fold_flag
let g:fold_flag = 0
normal! zM
else
let g:fold_flag = 1
normal! zR
endif
endfunction
" Note this will override <C-i>
" nmap <TAB> za
nnoremap go za
nnoremap <S-TAB> :call ToggleFoldAll()<CR>
" Actually, this will override default "outline" command
" nnoremap gO :call ToggleFoldAll()<CR>
nnoremap <Space> <Nop>
" nnoremap <Up> <Nop>
" nnoremap <Down> <Nop>
" nnoremap <Left> <Nop>
" nnoremap <Right> <Nop>
" ************** COLORS **************%%%1
"makes vim colorscheme the same as the terminal
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
"Credit joshdick
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
if (empty($TMUX))
if (has("nvim"))
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
if (has("termguicolors"))
set termguicolors
endif
endif
" let g:taboo_tabline = 0