-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
1708 lines (1361 loc) · 51.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
" Constants {{{1
let $CODE='$HOME/git'
" Fold marker string used through vimrc file without messing up folding
let g:fold_marker_string = '{'. '{'. '{'
" By default, don't close term after <leader>rr
" This can be toggled
let g:term_close = ''
" Enable/disable prepending jira issue in git commit message
let g:vira_commit_text_enable = ''
" Vim home directory
if has("unix")
let vimHomeDir = $HOME . '/.vim'
else
let vimHomeDir = $HOME . '/vimfiles'
endif
if has('mac')
let g:python3_host_prog='/usr/bin/python3'
else
let g:python3_host_prog='/usr/bin/python'
endif
" Functions {{{1
" FoldText {{{2
function! GetFoldStrings() " {{{3
" Make the status string a list of all the folds
" Iterate through each fold level and add fold string to list
let foldStringList = []
let i = 1
while i <= foldlevel(".")
" Append string to list
call add(foldStringList, FormatFoldString(GetLastFoldLineNum(i)))
let i += 1
endwhile
" Add each fold line to status string
let statusString = ""
for i in foldStringList
let statusString = statusString."|".i
endfor
return statusString."|"
endfunction
function! GetLastFoldString() " {{{3
" Get the text of the last fold if following conditions exist
if (len(filter(split(execute(':scriptname'), "\n"), 'v:val =~? "vim-coiled-snake"')) > 0
\ && &filetype ==# 'python')
\ || &filetype ==# 'markdown'
\ || &filetype ==# 'vim'
let foldStr = FormatFoldString(GetLastFoldLineNum(foldlevel("."))) . "|$}{$"
else
let foldStr = ""
endif
return foldStr
endfunction
function! GetLastFoldLineNum(foldLvl) " {{{3
" Search backwards for fold marker
" Get the line number of last Fold
" TODO-MB [191126] - Try with zN or whatever the restore fold command is
normal zR
normal mz
normal [z
let line = line('.')
normal `z
return line
endfunction
function! FormatFoldString(lineNum) " {{{3
" Format fold string so it looks neat
" Get the line string of the current fold and remove special chars
let line = getline(a:lineNum)
" Remove programming language specific words
let line = RemoveFiletypeSpecific(line)
" Remove special (comment related) characters and extra spaces
let line = RemoveSpecialCharacters(line)
return line
endfunction
function! RemoveSpecialCharacters(line) " {{{3
" Remove special (comment related) characters and extra spaces
" Characters: " # ; /* */ // <!-- --> g:fold_marker_string
" Remove fold marker
let text = substitute(a:line, g:fold_marker_string.'\d\=', '', 'g')
" let text = substitute(a:line, g:fold_marker_string.'\d\=\|'.substitute(GetCommentString(), '%s', '', '').'\d\=\|', '', 'g')
let text = substitute(text, substitute(GetCommentString(), '%s', '', ''), '', 'g')
" let text = substitute(text, substitute('# %s', '%s', '', ''), '', 'g')
" Replace 2 or more spaces with a single space
let text = substitute(text, ' \{2,}', ' ', 'g')
" Remove leading and trailing spaces
let text = substitute(text, '^\s*\|\s*$', '', 'g')
" Remove text between () in functions
let text = substitute(text, '(\(.*\)', '()', 'g')
" Add nice padding
return " ".text." "
endfunction
function! RemoveFiletypeSpecific(line) " {{{3
" Remove programming language specific words
let text = a:line
if (&ft=='python')
let text = substitute(a:line, '\<def\>\|\<class\>', '', 'g')
elseif (&ft=='cs')
let text = substitute(a:line, '\<static\>\|\<int\>\|\<float\>\|\<void\>\|\<string\>\|\<bool\>\|\<private\>\|\<public\>\s', '', 'g')
elseif (&ft=='vim')
let text = substitute(a:line, '\<function\>!\s', '', 'g')
elseif (&ft=='markdown')
let text = substitute(a:line, '#', '', 'g')
elseif (&ft=='javascript')
let text = substitute(a:line, '=\|{\s', '', 'g')
elseif (&ft=='yaml')
let text = substitute(a:line, ':', '', 'g')
endif
return text
endfunction
" FontSize() {{{2
if has("unix")
function! FontSizePlus ()
let l:gf_size_whole = matchstr(&guifont, '\( \)\@<=\d\+$')
let l:gf_size_whole = l:gf_size_whole + 1
let l:new_font_size = ' '.l:gf_size_whole
let &guifont = substitute(&guifont, ' \d\+$', l:new_font_size, '')
endfunction
function! FontSizeMinus ()
let l:gf_size_whole = matchstr(&guifont, '\( \)\@<=\d\+$')
let l:gf_size_whole = l:gf_size_whole - 1
let l:new_font_size = ' '.l:gf_size_whole
let &guifont = substitute(&guifont, ' \d\+$', l:new_font_size, '')
endfunction
else
function! FontSizePlus ()
let l:gf_size_whole = matchstr(&guifont, '\(:h\)\@<=\d\+$')
let l:gf_size_whole = l:gf_size_whole + 1
let l:new_font_size = ':h'.l:gf_size_whole
let &guifont = substitute(&guifont, ':h\d\+$', l:new_font_size, '')
endfunction
function! FontSizeMinus ()
let l:gf_size_whole = matchstr(&guifont, '\(:h\)\@<=\d\+$')
let l:gf_size_whole = l:gf_size_whole - 1
let l:new_font_size = ':h'.l:gf_size_whole
let &guifont = substitute(&guifont, ':h\d\+$', l:new_font_size, '')
endfunction
endif
" Quit {{{2
" Close location list, preview window and quit
function! Quit()
if (&buftype != "quickfix")
lclose
endif
if (!&previewwindow)
pclose
endif
quit
endf
function! BufDo(command) " {{{2
" Just like bufdo, but restore the current buffer when done.
let currBuff=bufnr('%')
silent! execute 'bufdo ' . a:command
silent! execute 'buffer ' . currBuff
endfunction
function! CloseAll() " {{{2
" Close all loc lists, qf, preview and terminal windows
lclose
cclose
pclose
NvimTreeClose
" CopilotChatClose
for bufname in ['^fugitive', '/tmp/flow', 'git/gap', '~/git/Linux/config/mani.yaml', 'dotnet-test.sh']
let buffers = join(filter(range(1, bufnr('$')), 'buflisted(v:val) && bufname(v:val) =~# bufname'), ' ')
if trim(buffers) !=? ''
silent! exe 'bdelete '. buffers
endif
endfor
endf
function! CloseQuickFixWindow() " {{{2
" If the window is quickfix, proceed
if &buftype=="quickfix"
" If this window is last on screen quit without warning
if winbufnr(2) == -1
quit!
endif
endif
endfunction
function! CommentYank() "{{{2
normal! mz
let line = substitute(getline('.'), '\n$', '', '')
silent put!=line
lua require('mini.comment').toggle_lines(vim.fn.line('.'), vim.fn.line('.'))
normal! `z
endfunction
function! EditCommonFile(filename) " {{{2
" Open file in new teb
let current_filename = expand('%:t')
let openfilestring = 'tabedit ' . a:filename
silent exec openfilestring
endfunction
function! Figlet(...) " {{{2
" Print ascii art comment
" Read figlet output into list
let lines = systemlist('figlet ' . a:1)
" Add comments to each lines
call map(lines, {index, val -> trim(substitute(GetCommentString(), '%s', '', '') . val)})
" call writefile(lines, expand("/tmp/figlet.txt"))
" Dump list on screen
put=lines
endfunction
function! FindFunc(...) " {{{2
" Move cursor to next pattern match
if (a:2 == 'next')
call search(a:1)
FoldOpen
endif
" Record initial line number into "z
let @z = '|' . line('.') . '|'
" Clear quickfix list
lexpr []
" Put Results into QuickFix Window
silent execute 'g/'.a:1.'/laddexpr expand("%") . ":" . line(".") . ":" . GetLastFoldString() . getline(".") '
top lopen
endfunction
function! GetBufferList() " {{{2
" load all current buffers into a list
redir =>buflist
silent! ls!
redir END
return buflist
endfunction
function! GetCommentString() "{{{2
let commentstring = luaeval("require('ts_context_commentstring').calculate_commentstring()")
" ts_context_commentstring only works for html/js/vue
if commentstring == v:null
let commentstring = &commentstring
endif
return commentstring
endfunction
function! GetCurrentGitRepo() " {{{2
let result = system('basename "$(git -C ' . expand('%:h') . ' rev-parse --show-toplevel)"')
if v:shell_error || stridx(result, 'fatal') != -1
return ''
else
return substitute(result, '\n', '', 'g')
endif
endfunction
function! GetTODOs() " {{{2
" TODO [171103] - Add current file ONLY option
" Binary files that can be ignored
set wildignore+=*.jpg,*.docx,*.xlsm,*.mp4
" Seacrch the CWD to find all of your current TODOs
vimgrep /TODO-MB \[\d\{6}]/ **/* **/.* | cw 5
" Un-ignore the binary files
set wildignore-=*.jpg,*.docx,*.xlsm,*.mp4
endfunction
function! GitAddCommitPush() abort " {{{2
" Git - add all, commit and push
if g:vira_active_issue ==? 'none' || get(g:, 'vira_commit_text_enable', '') ==? ''
let commit_text=''
else
let commit_text=g:vira_active_issue . ':'
endif
if has('unix') " Linux
if has('nvim')
exe 'sp term://bash ~/git/Linux/git/gap'
else
exe 'term ++close bash --login -c "export TERM=tmux-256color; '.$HOME.'/git/Linux/git/gap '.commit_text.'"'
endif
else " Windows
exe '!"C:\Program Files\Git\usr\bin\bash.exe" ~/git/Linux/git/gap '.commit_text
endif
redraw!
endfunction
function! GitDeleteBranch() abort " {{{2
" Delete branch for active vira issue
if g:vira_active_issue ==? 'none'
echom 'Please select issue first'
return
endif
if g:vira_active_issue ==# FugitiveHead()
echom 'Change branch first'
return
endif
execute('Git branch -d ' . g:vira_active_issue)
execute('Git push origin --delete ' . g:vira_active_issue)
endfunction
function! GitMerge() abort " {{{2
" Merge active vira issue branch into dev
if g:vira_active_issue !=# FugitiveHead()
echom 'Issue and branch dont match'
return
endif
" Hacky method to merge into dev if it exists, otherwise merge into master
Git checkout master
Git checkout dev
" Merge message is like: 'VIRA-123: merge"
execute('Git merge -m "'. g:vira_active_issue . ': merge" ' . ' --no-ff ' . g:vira_active_issue)
Git push
endfunction
function! GitNewBranch() abort " {{{2
" Create new git branch based on active vira issue
if g:vira_active_issue ==? 'none'
echom 'Please select issue first'
return
endif
execute('Git checkout -b ' . g:vira_active_issue)
Git push -u
endfunction
function! InsertInlineComment(fold_marker) "{{{2
execute 'normal! A ' . substitute(GetCommentString(), '%s', g:fold_marker_string . a:fold_marker, '')
endfunction
function! InstallVimspectorGadgets(info) " {{{2
if a:info.status == 'installed' || a:info.force
!./install_gadget.py --enable-python
!./install_gadget.py --enable-go --update-gadget-config
!./install_gadget.py --force-enable-csharp --update-gadget-config
!./install_gadget.py --force-enable-node --update-gadget-config
endif
endfunction
function! MyTabLabel(n) " {{{2
" The tab label looks better as file name only - without entire path
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
let buf = bufname(buflist[winnr - 1])
return fnamemodify(buf, ':t')
endfunction
function! MyTabLine() " {{{2
let tabstring = ''
for i in range(tabpagenr('$'))
" select the highlighting
if i + 1 == tabpagenr()
let tabstring .= '%#TabLineSel#'
else
let tabstring .= '%#TabLine#'
endif
" set the tab page number (for mouse clicks)
let tabstring .= '%' . (i + 1) . 'T'
" the label is made by MyTabLabel()
let tabstring .= ' %{MyTabLabel(' . (i + 1) . ')} '
endfor
" after the last tab fill with TabLineFill and reset tab page nr
let tabstring .= '%#TabLineFill#%T'
" " right-align the label to close the current tab page
" if tabpagenr('$') > 1
" let tabstring .= '%=%#TabLine#%999Xclose'
" endif
return tabstring
endfunction
function! OnSave() " {{{2
wshada
endfunction
function! PasteClipboard() abort " {{{2
" See https://github.com/ferrine/md-img-paste.vim
let targets = filter(
\ systemlist('xclip -selection clipboard -t TARGETS -o'),
\ 'v:val =~# ''application/x-qt-image''')
" Paste regular text if not an image
if empty(targets)
normal! o
normal! ==
normal! P
return
endif
" Paste image into markdown document
call mdip#MarkdownClipboardImage()
endfunction
function! PromptAndComment(inline_comment, prompt_text, comment_prefix) " {{{2
" Add inline comment and align with other inline comments
" Prompt user for comment text
let prompt = UserInput(a:prompt_text)
" Abort the rest of the function if the user hit escape
if (prompt == '') | return | endif
" Temporarily disable auto-pairs wrapping so the comment delimiter doesn't repeat
let b:autopairs_enabled = 0
" Either inline comment or comment above current line
let insert_command = (a:inline_comment) ? 'A ' : 'O'
" Prepare execution script for adding commented line
let exe_string = 'normal ' . insert_command . substitute(GetCommentString(), '%s', a:comment_prefix . prompt, '')
" Add commented line to document
exe exe_string
" Re-enable auto-pairs
let b:autopairs_enabled = 1
endfunction
function! SetCurrentWorkingDirectory() " {{{2
" A standalone function to set the working directory to the project's root, or
" to the parent directory of the current file if a root can't be found:
let cph = expand('%:p:h', 1)
if cph =~ '^.\+://' | retu | en
for mkr in ['.git/', '.hg/', '.svn/', '.bzr/', '_darcs/', '.vimprojects']
let wd = call('find'.(mkr =~ '/$' ? 'dir' : 'file'), [mkr, cph.';'])
if wd != '' | let &acd = 0 | brea | en
endfo
exe 'lc!' fnameescape(wd == '' ? cph : substitute(wd, mkr.'$', '.', ''))
endfunction
function! ToggleList(bufname, pfx) " {{{2
" Toggle QuickFix/Location List, don't change focus
let buflist = GetBufferList()
for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
if bufwinnr(bufnum) != -1
" exec('quit')
exec(a:pfx.'close')
return
endif
endfor
" Location List
if a:pfx ==# 'l'
" Nicer error message than original
if len(getloclist(0)) == 0
echohl ErrorMsg
echo 'Location List is Empty.'
return
endif
" Open window with minimum height
top lopen
" QuickFix List
elseif a:pfx ==# 'c'
copen
endif
endfunction
function! UserInput(prompt) " {{{2
" Get a string input from the user
" Get input from user
call inputsave()
let reply=input(a:prompt)
call inputrestore()
" Return the user's reply
return l:reply
endfunction
function! WinDo(command) " {{{2
" Just like windo, but restore the current window when done.
let currwin=winnr()
execute 'windo ' . a:command
execute currwin . 'wincmd w'
endfunction
function! s:getExitStatus() abort " {{{2
" Get the exit status from a terminal buffer by looking for a line near the end
" of the buffer with the format, '[Process exited ?]'.
let ln = line('$')
" The terminal buffer includes several empty lines after the 'Process exited'
" line that need to be skipped over.
while ln >= 1
let l = getline(ln)
let ln -= 1
let exitCode = substitute(l, '^\[Process exited \([0-9]\+\)\]$', '\1', '')
if l != '' && l == exitCode
" The pattern did not match, and the line was not empty. It looks like
" there is no process exit message in this buffer.
break
elseif exitCode != ''
return str2nr(exitCode)
endif
endwhile
throw 'Could not determine exit status for buffer, ' . expand('%')
endfunc
function! s:afterTermClose(...) abort
" a:0 -> number of arguments
" a:1 -> expected name of buffer (with Process exited message)
" a:2 -> expected exit code (default is 0)
" This is a hack to easily handle the situation where I switched focus away
" from the terminal window
if bufname('%') !~# a:1
call CloseAll()
return
endif
if a:0 > 1
let expected_code = a:2
else
let expected_code = 0
end
if s:getExitStatus() == expected_code
bdelete!
endif
endfunc
function! s:VimspectorDotNet(i) abort
" Run vimspector debugger if DotNet build/test script succeeded
let i = a:i + 1
" Read file into memory and check if it contains the string: "Process Id:"
let filepath = '/tmp/dotnet-test.log'
let file = readfile(filepath)
let found = 0
for line in file
if line =~# 'Process Id:'
let found = 1
break
endif
endfor
if found
" Launch vimspector debugger
echo 'VimspectorDotNet passed'
call timer_start(20, { -> vimspector#Launch() })
return
else
" Keep retrying for 20 seconds
if i > 40
echo 'VimspectorDotNet failed'
return
endif
call timer_start(500, {-> s:VimspectorDotNet(i)})
endif
endfunc
augroup MyNeoterm
autocmd!
" The line '[Process exited ?]' is appended to the terminal buffer after the
" `TermClose` event. So we use a timer to wait a few milliseconds to read the
" exit status. Setting the timer to 0 or 1 ms is not sufficient; 20 ms seems to work for me.
autocmd TermClose * if (g:term_close == '++close') | call timer_start(20, { -> s:afterTermClose('/tmp/flow') }) | endif
autocmd TermClose *bash\ ~/git/Linux/git/gap call timer_start(20, { -> s:afterTermClose('/git/Linux/git/gap') })
" autocmd TermClose *bash\ ~/git/Linux/git/gap call timer_start(20, { -> s:afterTermClose('/git/Linux/git/gap', 1) })
augroup END
" Commands {{{1
" Figlet {{{2
" Draw ascii art comments
command! -nargs=+ -complete=command Figlet
\| silent call Figlet(<q-args>)
" Bufdo {{{2
" Just like bufdo, but restore the current buffer when done.
com! -nargs=+ -complete=command Bufdo call BufDo(<q-args>)
" Windo {{{2
" Just like windo, but restore the current window when done.
com! -nargs=+ -complete=command Windo call WinDo(<q-args>)
" Just like Windo, but disable all autocommands for super fast processing.
com! -nargs=+ -complete=command Windofast noautocmd call WinDo(<q-args>)
" CloseToggle {{{2
command! CloseToggle if (g:term_close == '') | let g:term_close = '++close' | echo 'Term will close' | else | let g:term_close = '' | echo 'Term will not close' | endif
" FindLocal {{{2
" Search for string in current file and put results in Location window
command! -nargs=+ -complete=command FindLocal
\| silent call FindFunc(<q-args>, 'next') | set hls
" \| try | silent call FindFunc(<q-args>, 'next') | catch | endtry | set hls
" FoldOpen {{{2
" Suppress errors when no fold exists
" The catch part of the command prevents an error that would move the cursor when there are no folds in the file
command! FoldOpen let save_cursor = getcurpos() | try | silent foldopen! | catch | call setpos('.', save_cursor) | endtry
" Grep {{{2
" Use ag to grep and put results quickfix list
command! -nargs=+ Grep execute 'silent grep! --ignore node_modules --follow <args>' | copen
" Optionally, add the following flags
" Show hidden files: --hidden
" Show git ignore files: --skip-vcs-ignores
" QuickFix/Location List Next {{{2
" Wrap around after hitting first/last record
command! Cnext try | cnext | catch | cfirst | catch | endtry
command! Cprev try | cprev | catch | clast | catch | endtry
command! Lnext try | lnext | catch | lfirst | catch | endtry
command! Lprev try | lprev | catch | llast | catch | endtry
" Replace ^M Line endings {{{2
" Useful when converting from DOS to Unix line endings
command! ReplaceMwithBlank try | %s/\r$// | catch | endtry
" Useful when converting from DOS to Unix line endings
command! ReplaceMwithNewLine try | %s/\r/\r/ | catch | endtry
" Mani {{{2
command! -nargs=+ -complete=command Mani try |
\ exe "sp term://mani -c ~/git/Linux/config/mani.yaml "
\ . <q-args> . ""| catch | endtry
" \ exe "terminal bash -c \"mani -c ~/git/Linux/config/mani.yaml "
" SpellToggle {{{2
command! SpellToggle if (&spell == 0) | setlocal spell | echo 'Spell-check enabled' | else | setlocal nospell | echo 'Spell-check disabled' | endif
" StartAsyncNeoVim {{{2
command! -nargs=1 StartAsyncNeoVim
\ call jobstart(<f-args>, {
\ 'on_exit': { j,d,e ->
\ execute('echom "command finished with exit status '.d.'"', '')
\ }
\ })
" ViraEnable {{{2
command! ViraEnable if (g:vira_commit_text_enable == '') | let g:vira_commit_text_enable = '+' | echo 'Jira issue git message prepending enabled' | else | let g:vira_commit_text_enable = '' | echo 'Jira issue git message prepending disabled' | endif
" Plugins{{{1
" Plugin Setup {{{2
" For nvim-tree
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
augroup CustomSetFileType
autocmd!
autocmd BufRead,BufNewFile *.sebol setfiletype sebol
autocmd BufRead,BufNewFile *.mmd setfiletype mermaid
augroup end
" _vim-plug {{{2
" Plugin manager
" Initialize plugin system
let vimPlugDir = vimHomeDir . '/plugged'
call plug#begin(vimPlugDir)
" Plug 'file:///home/mike/.vim/plugged/test'
Plug 'CopilotC-Nvim/CopilotChat.nvim', { 'branch': 'main' } " AI assistant
Plug 'JoosepAlviste/nvim-ts-context-commentstring' " For vue commentstrings
Plug 'L3MON4D3/LuaSnip' " Autocompletion
Plug 'PProvost/vim-ps1' " Powershell file types
Plug 'VonHeikemen/lsp-zero.nvim', {'branch': 'v3.x'} " Simple LSP config
Plug 'christoomey/vim-tmux-navigator' " Switch beween vim splits & tmux panes seamslessly
Plug 'echasnovski/mini.comment' " Commenting
Plug 'ellisonleao/gruvbox.nvim' " Gruvbox colorscheme
Plug 'godlygeek/tabular' " Align things
Plug 'hrsh7th/cmp-nvim-lsp' " Autocompletion
Plug 'hrsh7th/cmp-path' " Autocompletion
Plug 'hrsh7th/nvim-cmp' " Autocompletion
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } " Preview md in brwoser
Plug 'jkramer/vim-checkbox' " Checkbox toggle
Plug 'junegunn/fzf.vim' " fzf plugin
Plug 'junegunn/gv.vim' " Access git files easier
Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' } " VimScript testing
Plug 'kevinhwang91/nvim-bqf' " Quickfix niceties
Plug 'ludovicchabant/vim-gutentags' " Manage ctags
Plug 'lukas-reineke/indent-blankline.nvim' " Visual indent lines
Plug 'majutsushi/tagbar' " Use c-tags in real time and display tag bar
Plug 'mikeboiko/auto-pairs' " Auto-close brackets
Plug 'mikeboiko/img-paste.vim' " Paste images from clipboard
Plug 'mikeboiko/vim-flow' " For a neat development workflow
Plug 'mikeboiko/vim-markdown-folding' " Syntax based folding for md
Plug 'mikeboiko/vim-sort-folds' " Sort vim folds
Plug 'mipmip/vim-scimark' " Spreadsheet magic
Plug 'mtdl9/vim-log-highlighting' " log file highlighting
Plug 'n0v1c3/vira', { 'do': './install.sh', 'branch': 'dev'} " Jira integration
Plug 'neovim/nvim-lspconfig' " LSP Support
Plug 'nvim-lua/plenary.nvim' " Lua functions (prereq for null-ls)
Plug 'nvim-tree/nvim-tree.lua' " File Browser
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " Tree sitter
Plug 'nvim-treesitter/nvim-treesitter-textobjects' " Tree sitter text objects
Plug 'nvimtools/none-ls.nvim' " Custom LSP sources
Plug 'pbogut/fzf-mru.vim' " CtrlP style MRU files
Plug 'puremourning/vimspector', {'do': function('InstallVimspectorGadgets')} " DAP
Plug 'rhysd/conflict-marker.vim' " Git conflict resolution
Plug 'roosta/fzf-folds.vim', {'branch': 'main'} " fzf for folds
Plug 'rust-lang/rust.vim' " Rusty stuff
Plug 'stevearc/dressing.nvim' " Customize vim.ui.input
Plug 'tpope/vim-fugitive' " Git wrapper
Plug 'tpope/vim-repeat' " Repeat surround and commenting with .
Plug 'tpope/vim-rhubarb' " GitHub integration with fugitive
Plug 'tpope/vim-scriptease' " For debugging and writing plugins
Plug 'tpope/vim-surround' " Surround all the stuff
Plug 'vim-airline/vim-airline' " Nice status bar
Plug 'vim-scripts/ReplaceWithRegister' " Replace without copying to buffer
Plug 'zbirenbaum/copilot-cmp' " AI assistant
Plug 'zbirenbaum/copilot.lua' " AI assistant
" End initialization of plugin system
call plug#end()
" ag - silver searcher {{{2
if executable('ag')
" Use ag instead of grep (performance increase)
" set grepprg=ag\ --nogroup\ --nocolor
set grepprg=ag\ --silent\ --vimgrep\ --column\ $*
set grepformat=%f:%l:%c:%m
endif
" airline {{{2
" Fix font inconsistencies
let g:airline_powerline_fonts=1
let g:airline_section_a = '%{GetCurrentGitRepo()}'
" fugitive {{{2
augroup CustomFugitive
autocmd!
autocmd FileType gitcommit autocmd! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
augroup end
" fzf {{{2
" Remap hotkeys
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit' }
" Disable preview window
let g:fzf_preview_window = []
" fzf-folds {{{2
let g:fzf_folds_open = 1
" img-paste {{{2
" let g:mdip_imgdir = 'img'
let g:mdip_imgname = 'img'
" indentLine {{{2
let g:indentLine_char = '│'
" markdownpreview {{{2
let g:mkdp_auto_close = 0
let g:mkdp_refresh_slow = 1
" mini.comment {{{2
augroup CustomCommentStrings
autocmd!
autocmd FileType kql setlocal commentstring=//%s
autocmd FileType mermaid setlocal commentstring=\%\%%s
autocmd FileType sebol setlocal commentstring=!%s
autocmd FileType vader setlocal commentstring=#%s
autocmd FileType autohotkey setlocal commentstring=;%s
augroup end
" toggleterm {{{2
if has('nvim')
" lua require("toggleterm").setup{
" \ open_mapping = [[<c-\>]],
" \ hide_numbers = true
" \ }
autocmd! TermOpen term://* lua set_terminal_keymaps()
endif
" vim-unstack {{{2
let g:unstack_populate_quickfix=1
let g:unstack_layout = "portrait"
" vimspector {{{2
let g:vimspector_enable_mappings = 'HUMAN'
let g:vimspector_enable_winbar=0
" See https://code.visualstudio.com/docs/python/debugging
" https://puremourning.github.io/vimspector/schema/vimspector.schema.json
let g:vimspector_configurations = {
\ 'debugpy_config': {
\ 'adapter': 'debugpy',
\ 'filetypes': ['python'],
\ 'configuration': {
\ 'request': 'launch',
\ 'type': 'python',
\ 'cwd': '${fileDirname}',
\ 'args': ['*${ARGS}'],
\ 'program': '${file}',
\ 'python': '~/.pyenv/shims/python',
\ 'stopOnEntry': v:false,
\ 'console': 'integratedTerminal'
\ },
\ 'breakpoints': {
\ 'exception': {
\ 'raised': 'Y',
\ 'uncaught': 'Y',
\ 'userUnhandled': 'Y'
\ }
\ }
\ },
\ 'delve_config': {
\ 'adapter': 'vscode-go',
\ 'filetypes': ['go'],
\ 'configuration': {
\ 'request': 'launch',
\ 'program': '${fileDirname}',
\ 'mode': 'debug',
\ 'dlvToolPath': '$HOME/go/bin/dlv'
\ },
\ 'breakpoints': {
\ 'exception': {
\ 'raised': 'Y',
\ 'uncaught': 'Y',
\ 'userUnhandled': 'Y'
\ }
\ }
\ },
\ 'vscode-js-debug': {
\ 'adapter': 'js-debug',
\ 'filetypes': ['javascript'],
\ 'configuration': {
\ 'request': 'launch',
\ 'program': '${file}',
\ 'cwd': '${workspaceRoot}',
\ 'stopOnEntry': v:false
\ },
\ 'breakpoints': {
\ 'exception': {
\ 'all': '',
\ 'uncaught': ''
\ }
\ }
\ },
\ 'netcoredbg': {
\ 'adapter': 'netcoredbg',
\ 'filetypes': ['cs'],
\ 'configuration': {
\ 'request': 'launch',
\ 'program': '${workspaceRoot}/bin/Debug/net7.0/dotnet-test.dll',
\ 'args': [],
\ 'stopAtEntry': v:false,
\ 'cwd': '${workspaceRoot}',
\ 'env': {}
\ },
\ 'breakpoints': {
\ 'exception': {
\ 'raised': 'N',
\ 'uncaught': 'N',
\ 'userUnhandled': 'N'
\ }
\ }
\ }
\ }
let g:vimspector_sidebar_width = 60
" vimwiki {{{2
" let g:vimwiki_list = [{'path': '~/vimwiki/',
" \ 'syntax': 'markdown', 'ext': '.md'}]
" vira {{{2
let g:vira_config_file_projects = $HOME.'/git/Linux/config/vira_projects.yaml'
let g:vira_config_file_servers = $HOME.'/git/Linux/config/vira_servers.yaml'
let g:vira_issue_limit = 100
" let g:vira_report_width = 100
" Editor Settings {{{1
" Display{{{2
" 256 color
set t_Co=256
" Preferred background
set background=dark
" Preferred color scheme
silent! colorscheme gruvbox
" Set GVIM Font
" To select form availbale fonts :set guifont=*
if has("unix")
set guifont=Ubuntu\ Mono\ 13
else
set guifont=Consolas:h12
endif
" Display line number for current line
set number
" Display relative line number along the left hand side
" set relativenumber
" Start scrolling <x> lines before window border
set scrolloff=8
" Visual auto complete for command menu
set wildmenu
" Show command in bottom bar
set showcmd
" Don't show Insert/Normal Mode status on last line
set noshowmode
" Do not redraw during operations such as macro
set lazyredraw
" Don't wrap/line break in the middle of a word
set linebreak
" Always display the status line even if only one window is displayed
set laststatus=2
" Display hidden char
let g:display_hidden = "hidden"
" Change the text that is displayed while in a fold
set foldtext=v:folddashes.FormatFoldString(v:foldstart)
" Get rid of that ugly x in top right corner or tabline
set tabline=%!MyTabLine()
" Functionality {{{2
" Vim Start {{{3
" Save last file when exiting vim
" autocmd VimLeave * nested if (!isdirectory(vimHomeDir)) |
" \ call mkdir(vimHomeDir) |
" \ endif |
" \ execute "mksession! " . vimHomeDir . "/Session.vim"
" " Go to last file(s) if invoked without arguments.
" autocmd VimEnter * nested if argc() == 0 &&
" \ filereadable(vimHomeDir . "/Session.vim") |
" \ try |
" \ execute "source " . vimHomeDir . "/Session.vim"
" \ | catch | endtry