-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
1600 lines (1268 loc) · 48.8 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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" NOTE TO READERS
"
" This .vimrc file is the result of many many years of just dumping junk in
" here... some of it was dumped in for some one-off solution to some long
" forgotten problem, some of it was inherited from a friend who got me back
" into the habit of using vim, some of it was stuff that I set so long ago
" that in my mind 'that's just how vim works', some of it was written for
" very old versions of vim that didn't have better ways to do them...
"
" I've tried to clean it up some and document it, but as long as it does
" what I need, I continue to trudge along with this messy version of it.
"
" If you find something useful here, please feel free to grab it. If you
" have suggestions for improvements, I'd be glad to hear them... If you
" think it's just a pile of junk... oh well. :-)
"
" TODO:
"
" - Need to extract machine specific elements so that I have less churn in
" my primary file & it stays the same across all of my machines, easing
" maintenance
"
" - Extract Windows specific vs. Unix specific references to OS specific
" files
"
" - More cleanup
"
" - More documentation
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Function keys, documentation:
" F1: Not used, built in help
"
" F2: Increase font size
" S-F2: Decrease font size
" M-F2: Go to default font size
"
" F3: Edit alternate file (:e #)
"
" F4: Open filename under the cursor in this window
" S-F4: Open filename under cursor in a vertical split
" M-F4: Open filename under cursor in a horizontal split
"
" F5: Change the current directory to that of the current file
" M-F5: Change to the project root, always based on g:projectRoot
" M-S-F5: Change to one level ABOVE g:projectRoot
" C-F5: Change to project root (based on current file)
" C-S-F5: Change to one level ABOVE the project root
" (git folder of current file, or g:projectRoot if git folder not found)
"
" F6: Swap header/source
" S-F6: Swap header/source (h/cpp only)
"
" F7: Not used
"
" F8: Comment out selection, or current line
" S-F8: Uncomment out selection, or current line
" M-F8: I forget, what's different here?
"
" F9: Unused
" S-F9: Unused
" M-F9: Unused
"
" F10: Unused
"
" F11: Go to next error
" S-F11: go to previous error
" M-F11: Next error in next file
" M-F11: Previous error in previous file
"
" Deprecated... reused
" F12: Save file
" S-F12: Revert
" M-F12: Reload (built in)
scriptencoding utf-8
set encoding=utf-8
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Clean up old settings in case we're reloading...
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
mapc " remove all previous mappings
abc " remove all previous abbreviations
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Load machine specific settings
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let host_config_file=$HOME."/.vimrc_host.vim"
if !filereadable(host_config_file)
echo "Creating a template machine_specific configuration file in ".$HOME
let host_config_lines=[]
let host_config_lines=host_config_lines+["\"-------- fonts --------"]
if(has("mac"))
let host_config_lines=host_config_lines+["let font_base=\"Monaco\""]
elseif(has("unix"))
let host_config_lines=host_config_lines+["let font_base=\"Ubuntu Mono\""]
else
let host_config_lines=host_config_lines+["let font_base=\"Consolas\""]
endif
let host_config_lines=host_config_lines+["let initialfontindex=2"]
let host_config_lines=host_config_lines+[""]
let host_config_lines=host_config_lines+["\"-------- other --------"]
let host_config_lines=host_config_lines+["let defaultprojectconfig=$HOME.\"/.vim/projects/default\""]
let host_config_lines=host_config_lines+[""]
let host_config_lines=host_config_lines+["\"---------- plugins ---------"]
let host_config_lines=host_config_lines+["set runtimepath^=~/.vim/bundle/Align"]
let host_config_lines=host_config_lines+["set runtimepath^=~/.vim/bundle/ctrlp.vim"]
let host_config_lines=host_config_lines+["set runtimepath^=~/.vim/bundle/vim-abolish"]
let host_config_lines=host_config_lines+["set runtimepath^=~/.vim/bundle/vim-vinegar"]
let host_config_lines=host_config_lines+[""]
let host_config_lines=host_config_lines+["let g:ctrlp_regexp = 1"]
let host_config_lines=host_config_lines+[""]
let host_config_lines=host_config_lines+["\"---------- consider moving to project config ---------"]
let host_config_lines=host_config_lines+["\" set makeprg=ninja\ -C\ <<project build folder>>"]
let host_config_lines=host_config_lines+[""]
let host_config_lines=host_config_lines+["\" let g:projectRoot=\"<<project source root folder>>\""]
let host_config_lines=host_config_lines+["\" let g:projectName=\"<<project name>>\""]
let host_config_lines=host_config_lines+["\" let g:companyName=\"<<company name>>\""]
call writefile(host_config_lines, host_config_file)
endif
exec ":source ".host_config_file
if filereadable(defaultprojectconfig)
exec ":source ".defaultprojectconfig
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
filetype on " enable filetype detection
filetype plugin on "
filetype indent on "
set nocompatible " Leave vi in the past
set nobackup " Don't litter the filesystem with junk!
set viminfo='20,\"50 " Remember up to 20 previous files, 50 lines per register
set history=200 " keep 200 last commands
set showtabline=2 " Always show the tabline, even if there is only one tab
set ruler " Show the line & column number of the cursor position
set number " Always show line numbers
set swb=useopen " switchbuf, use already open buffer in current tab
set nrformats+=alpha " Used with CTRL-A and CTRL-X to increment and decrement the letter under the cursor
set nrformats-=octal " Used with CTRL-A and CTRL-X to increment and decrement the letter under the cursor
syntax on " Syntax highlighting
set hlsearch " Highlight Search, highlight all matches when searching
set is " Incremental Search (show next search result as you type it
set linebreak " Cause wrap to wrap in a sane way (break on word, rather than mid-word)
set nowrap " Don't wrap lines by default
set showcmd " Show how many lines/characters are selected in visual mode [off by default in mvim]
set showbreak=\ \ >>>\ " Characters to show on edges of wrapped lines
set textwidth=0 " never wrap on paste
set scrolloff=5 " Keep some lines above/below the cursor when scrolling
set grepprg=rg\ --vimgrep " Use ripgrep
set wildmenu " Show command line completions
" Write grep/make output to a file for faster I/O
fun! RedirectShellpipe()
" VIM 9: There's a change from vim 8 to vim 9 -- vim 8 used to add a
" space between makeprg/grepprg/etc and the shellpipe command....
" but not anymore, so I had to add an explicit space at the
" start....
set shellpipe=\ 2>&1\|tee\ ~/.vim/shellpipe.txt\ %s\ >\ /dev/null
endfun
if has("unix")
call RedirectShellpipe()
endif
inoremap jk <esc>
inoremap kj <esc>
let comment_string=""
set nolisp
set visualbell
if has("nvim")
set bg=dark
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" TODO: This whole augroup block is really old... there are better
" ways to do this now with filetype plugins... need to research
" and refactor.
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup quixfix
" automatically open cwindow after grep/make
autocmd!
autocmd QuickFixCmdPost [^l]* cwindow 10
autocmd QuickFixCmdPost l* lwindow 10
augroup END
augroup aft
au BufWrite,BufNewFile,BufRead,BufEnter *.aft set noet
augroup END
" vim editing mode at the bash prompt
augroup bash
au BufRead,BufEnter bash-fc-* set syntax=sh
augroup END
augroup cprog
au!
au BufWrite,BufNewFile,BufRead,BufEnter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc set list
au BufWrite,BufNewFile,BufRead,BufEnter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc set nolisp
au BufWrite,BufNewFile,BufRead,BufEnter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc set filetype=cpp syntax=cpp.doxygen
au BufWrite,BufNewFile,BufRead,BufEnter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc set formatoptions=crql cindent comments=sr:/*,mb:*,el:*/,:///,:// isk-=$
au BufWrite,BufNewFile,Bufread,BufEnter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc let comment_string = "//"
au BufWrite,BufNewFile,BufRead,BufEnter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc set cinkeys=0{,0},:,0#,!^F,o,O,e
au BufWrite,BufNewFile,BufRead,BufEnter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc let c_no_curly_error=1
au BufWrite,BufNewFile,BufRead,BufEnter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc set foldcolumn=3
au bufwrite,bufnewfile,bufread,bufenter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc syntax match dangerous_stuff "\s*\(std\::\)\?\(lock_guard\|scoped_lock\|QMutexLocker\)\(\s*<.*>\)\?\s*[({].*"
au bufwrite,bufnewfile,bufread,bufenter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc highlight Dangerous_Stuff ctermbg=red guibg=#FF0000 gui=bold
au BufWrite,BufNewFile,Bufread,BufEnter *.hpp,*.h,*.c,*.cc,*.cpp,*.ipp,*.icc call RKHighlights()
augroup END
augroup cmake
au!
au BufWrite,BufNewFile,Bufread,BufEnter CMakeLists.txt,*.cmake let comment_string="#"
au BufWrite,BufNewFile,Bufread,BufEnter CMakeLists.txt,*.cmake set comments=:#
au BufWrite,BufNewFile,Bufread,BufEnter CMakeLists.txt,*.cmake call RKHighlights()
augroup END
augroup Perl
au!
au BufWrite,BufNewFile,Bufread,BufEnter *.pl,*.pm set nolisp
au BufWrite,BufNewFile,Bufread,BufEnter *.pl,*.pm set isk+=$
au BufWrite,BufNewFile,Bufread,BufEnter *.pl,*.pm let comment_string = "#"
au BufWrite,BufNewFile,Bufread,BufEnter *.pl,*.pm set cinkeys="0{,0},:,!^F,o,O,e"
au BufWrite,BufNewFile,BufRead,BufEnter *.pl,*.pm set formatoptions=crql cindent
augroup END
augroup pyc
" Ooops... opened the pyc file in the Netrw browser, again... no problem!
au!
au BufRead *.pyc exec ':edit ' . substitute(bufname("%"), "\.pyc", ".py", "")
augroup END
augroup Python
au!
au BufWrite,BufNewFile,Bufread,BufEnter *.py set nolisp
au BufWrite,BufNewFile,Bufread,BufEnter *.py set ft=python " for some reason I sometimes don't get syntax highlighting, especially after the *.pyc autocmd
au BufWrite,BufNewFile,Bufread,BufEnter *.py inoremap <buffer> # X<BS>#
au BufWrite,BufNewFile,BufRead,BufEnter *.py set nocindent smartindent
au BufWrite,BufNewFile,BufRead,BufEnter *.py set shiftwidth=4 softtabstop=4 tabstop=4 expandtab
au BufWrite,BufNewFile,BufRead,BufEnter *.py set cinwords=if,elif,else,for,while,try,except,finally,def,class
au BufWrite,BufNewFile,Bufread,BufEnter *.py set formatoptions=crq2
au BufWrite,BufNewFile,Bufread,BufEnter *.py let comment_string = "#"
au BufWrite,BufNewFile,Bufread,BufEnter,FileType python setlocal equalprg=autopep8\ -
au BufWrite,BufNewFile,Bufread,BufEnter *.py call RKHighlights()
augroup END
augroup json
au!
au BufWrite,BufNewFile,BufRead,BufEnter,FileType json setlocal equalprg=python\ -m\ json.tool
augroup END
augroup Vimrc
au!
au BufWrite,BufNewFile,Bufread,BufEnter _vimrc,.vimrc,*.vim set nolisp
au BufWrite,BufNewFile,Bufread,BufEnter _vimrc,.vimrc,*.vim let comment_string = "\""
augroup END
augroup Lisp
au!
au BufWrite,BufNewFile,Bufread,BufEnter *.lsp,*.lisp,*.cl,*.el set lisp
au BufWrite,BufNewFile,Bufread,BufEnter *.lsp,*.lisp,*.cl,*.el let comment_string = ";"
augroup END
augroup Latex
au!
au BufWrite,BufNewFile,Bufread,BufEnter *.tex set foldmethod=marker
au BufWrite,BufNewFile,BufRead,BufEnter *.tex let comment_string = "%"
au BufWrite,BufNewFile,BufRead,BufEnter *.tex syntax match texUseProperTags "etc[^\}]\|\.\.\.\|etc"
au BufWrite,BufNewFile,BufRead,BufEnter *.tex highlight texUseProperTags guibg=#D00000 guifg=White
au BufWrite,BufNewFile,BufRead,BufEnter *.tex set spell
augroup END
augroup LogFiles
au!
au BufWrite,BufNewFile,Bufread,BufEnter *.log,*.log.* syntax match VLOGWARN ".*<WARN\s\+.*"
au BufWrite,BufNewFile,Bufread,BufEnter *.log,*.log.* syntax match VLOGERROR ".*<ERROR.*"
au BufWrite,BufNewFile,Bufread,BufEnter *.log,*.log.* syntax match VLOGFATAL ".*<FATAL.*"
au BufWrite,BufNewFile,Bufread,BufEnter *.log,*.log.* syntax match VLOGTEMP ".*RKTEMP:.*"
au BufWrite,BufNewFile,Bufread,BufEnter *.log,*.log.* highlight VLOGWARN guibg=#FFE900 guifg=#000000
au BufWrite,BufNewFile,Bufread,BufEnter *.log,*.log.* highlight VLOGERROR guibg=#F77B7D guifg=#000000
au BufWrite,BufNewFile,Bufread,BufEnter *.log,*.log.* highlight VLOGFATAL guibg=#FF0000 gui=bold guifg=#000000
au BufWrite,BufNewFile,Bufread,BufEnter *.log,*.log.* highlight VLOGTEMP guibg=#6F1DF2 gui=bold guifg=#000000
augroup END
augroup qml
au!
"au FileType * set formatoptions=tcq nocindent comments&
au BufWrite,BufNewFile,BufRead,BufEnter *.qml set nolisp
au BufWrite,BufNewFile,BufRead,BufEnter *.qml set filetype=javascript syntax=javascript
au BufWrite,BufNewFile,BufRead,BufEnter *.qml set formatoptions=crql cindent comments=sr:/*,mb:*,el:*/,:///,:// isk-=$
au BufWrite,BufNewFile,BufRead,BufEnter *.qml set cindent
au BufWrite,BufNewFile,Bufread,BufEnter *.qml let comment_string = "//"
au BufWrite,BufNewFile,BufRead,BufEnter *.qml set cinkeys=0{,0},:,0#,!^F,o,O,e
au BufWrite,BufNewFile,BufRead,BufEnter *.qml let c_no_curly_error=1
au BufWrite,BufNewFile,BufRead,BufEnter *.qml set foldcolumn=3
au BufWrite,BufNewFile,Bufread,BufEnter *.qml call RKHighlights()
augroup END
augroup vim_behavior
au!
au BufEnter,VimResized * call AutoResize()
augroup END
map <silent> ,ar :call ToggleAutoResize()<CR>
let g:autoResize = 0
fun! ToggleAutoResize()
if g:autoResize > 0
let g:autoResize = 0
set equalalways
exe "normal \<c-w>="
else
let g:autoResize = 1
set noequalalways
call AutoResize()
endif
echo 'Auto Resize: '.(g:autoResize?"ON":"OFF")
endfun
fun! AutoResize()
" Don't auto resize if equalalways is on...
if !&ea && g:autoResize
exe "normal \<c-w>_\<c-w>\|"
endif
endfun
fun! RKHighlights()
syntax match RKTEMP ".*RK\(ERR\)\=\s*TEMP.*"
highlight RKTEMP ctermbg=darkmagenta ctermfg=white guibg=#6F1DF2 gui=bold guifg=#000000
syntax match RKTODO ".*RK\(ERR\)\=\s*TODO.*"
highlight RKTODO ctermbg=darkyellow ctermfg=white guibg=#444400 gui=bold guifg=#000000
endfun
" Turn off syntax highlighting, etc. for large files
let g:LargeFile= 10 " in megabytes
let g:LargeFile= g:LargeFile*1024*1024
augroup LargeFile
au BufReadPre *
\ let f=expand("<afile>") |
\ if getfsize(f) >= g:LargeFile |
\ let b:eikeep= &ei |
\ let b:ulkeep= &ul |
\ set ei=FileType |
\ setlocal noswf bh=unload |
\ let f=escape(substitute(f,'\','/','g'),' ') |
" \ exe "au LargeFile BufEnter ".f." set ul=-1" |
\ exe "au LargeFile BufEnter ".f." set ul=2" |
\ exe "au LargeFile BufLeave ".f." let &ul=".b:ulkeep."|set ei=".b:eikeep |
\ exe "au LargeFile BufUnload ".f." au! LargeFile * ". f |
\ echomsg "***note*** handling a large file" |
\ endif
augroup END
"Toggle highlighting of stray whitespace
map <silent> ,ws :call ToggleHightlightStrayWS()<CR>
let g:HighlightStrayWhitespace=1
fun! ToggleHightlightStrayWS()
if g:HighlightStrayWhitespace > 0
let g:HighlightStrayWhitespace = 0
else
let g:HighlightStrayWhitespace = 1
endif
call UpdateWSHighlights()
echo 'Highlight Stray WS: '.(g:HighlightStrayWhitespace?"ON":"OFF")
endfun
fun! UpdateWSHighlights()
if g:HighlightStrayWhitespace > 0
au bufwrite,bufnewfile,bufread,bufenter *.py,*.h,*.c,*.cc,*.cpp,*.pl,*.ipp,*.icc syntax match straytabs "\t"
au bufwrite,bufnewfile,bufread,bufenter *.py,*.h,*.c,*.cc,*.cpp,*.pl,*.ipp,*.icc syntax match strayspaces "\s\+$"
au bufwrite,bufnewfile,bufread,bufenter *.py,*.h,*.c,*.cc,*.cpp,*.pl,*.ipp,*.icc highlight StrayTabs guibg=#454545 gui=bold
au bufwrite,bufnewfile,bufread,bufenter *.py,*.h,*.c,*.cc,*.cpp,*.pl,*.ipp,*.icc highlight StraySpaces guibg=#353030 gui=bold
syntax match straytabs "\t"
syntax match strayspaces "\s\+$"
highlight StrayTabs guibg=#454545 gui=bold
highlight StraySpaces guibg=#353030 gui=bold
else
au bufwrite,bufnewfile,bufread,bufenter *.py,*.h,*.c,*.cc,*.cpp,*.pl,*.ipp,*.icc syntax clear straytabs
au bufwrite,bufnewfile,bufread,bufenter *.py,*.h,*.c,*.cc,*.cpp,*.pl,*.ipp,*.icc syntax clear strayspaces
syntax clear straytabs
syntax clear strayspaces
endif
endfun
call UpdateWSHighlights()
" Make the statusline red for read-only files and blue for read-write files -- also makes the filename on the tab red
"
" Interestingly, old versions of vim seemed to have the guifg and guibg colors
" backwards and I either never noticed, or just hacked at it until these
" worked, but with vim 9.0 my colors were all wrong! Interestingly, the
" ctermfg and ctermbg colors still seem to be backwards!
if(v:version < 900)
au BufNew,BufAdd,BufWrite,BufNewFile,BufRead,BufEnter,FileChangedRO * :if &ro | hi StatusLine guifg=red guibg=black ctermbg=black ctermfg=red | :else | hi StatusLine guibg=white guifg=blue ctermbg=white ctermfg=blue | endif
au BufNew,BufAdd,BufWrite,BufNewFile,BufRead,BufEnter,FileChangedRO * :if &ro | hi TabLineSel guifg=red ctermfg=red | :else | hi TabLineSel guifg=gray ctermfg=gray | endif
else
au BufNew,BufAdd,BufWrite,BufNewFile,BufRead,BufEnter,FileChangedRO * :if &ro | hi StatusLine guibg=red guifg=black ctermbg=black ctermfg=red | :else | hi StatusLine guifg=white guibg=blue ctermbg=white ctermfg=20 | endif
au BufNew,BufAdd,BufWrite,BufNewFile,BufRead,BufEnter,FileChangedRO * :if &ro | hi TabLineSel guifg=red ctermfg=red | :else | hi TabLineSel guifg=gray ctermfg=gray | endif
endif
map ,python :!python %<CR>
" Make * search for the entire highlighted string when in visual select mode, rather than just the word under the cursor
vmap <silent> * y/<C-R>=substitute(escape(@", '\\/.*$^~[]'), '\n', '\\n', 'g')<CR><CR>
map <C-A> ggVG
map ,all mzggVG"*y`z
map ,fo V%:fo<CR>
vmap ,fo %:fo<CR>
" Set up the statusline (stl)
set stl=%f%h%m%r\ %{Options()}%=%l,%c%V\ %{line('$')}
"" augroup statusline
"" au!
"" au BufEnter,VimResized * call UpdateStatusline()
"" augroup END
""
"" function! UpdateStatusline()
"" if(winwidth(0) > 50)
"" set stl=%f%h%m%r\ %{Options()}%=%l,%c%V\ %{line('$')}
"" else
"" " set stl=%f%h%m%r\ %{Options()}%=%l,%c%V\ %{line('$')}
"" set stl=%f%h%m%r\ %y%=%l,%c%V\ %{line('$')}
"" endif
"" endfun
fu! Options()
let opt="ai".PlusOpt(&ai)
let opt=opt." rap".PlusOpt(&wrap)
let opt=opt." ic".PlusOpt(&ic)
let opt=opt." et".PlusOpt(&et)
let opt=opt." ar".(g:autoResize?"+":"-")
let opt=opt." sp".PlusOpt(&spell)
let opt=opt." ".&ff
let opt=opt." ".&ft
if &ft==?"cpp" || &ft==?"perl"
let text=" {f:" . FindCurrentFunction(0) . FindCurrentVisibility() "}"
let opt=opt.text
endif
if exists("g:projectName")
let text=" {p:" . g:projectName . "}"
let opt=opt.text
endif
return opt
endf
fu! PlusOpt(opt)
let option = a:opt
if option
return "+"
else
return "-"
endif
endf
set listchars=trail:·,precedes:<,extends:>,tab:→\
map ,fdos :set fileformat=dos<NL>
map ,funix :set fileformat=unix<NL>
" copy the full filename into the system clipboard
map ,fname :let @+ = fnamemodify(bufname("%"), ":p:")<CR>:<BS>
map ,share :call FilenameGitRelative(1)<CR>
map ,path :let @+ = fnamemodify(bufname("%"), ":p:h")<CR>:<BS>
map ,ym :let @* = matchstr(getline("."), @/)<CR>:<BS>
if(has("mac") || has("unix"))
set dir=~/.vim/vimswap
set bdir=~/.vim/vimswap
set udir=~/.vim/vimswap
if(!isdirectory(&dir))
silent! execute("!mkdir -p " . &dir)
endif
else
set dir=$TEMP\vimswap
set bdir=$TEMP\vimswap
if(!isdirectory(&dir))
silent! execute("!mkdir " . &dir)
endif
endif
set shiftwidth=4
set tabstop=4
set showmatch " briefly jump to matching bracket
set expandtab " replace tabs with spaces
set nowrapscan " don't search past end of file
set ignorecase
set autoindent
set backspace=indent,eol,start
set laststatus=2 " always show status line on last window
set cmdheight=2 " number of lines for cmd wndow
set cinoptions=g0 " scope declarations at column 0 of class
map ,cd :call ConditionalCD()<CR>
map <F5> ,cd
map <M-F5> :call GProjectRootCD()<CR>
map <M-S-F5> : call GProjectRootCD(1)<CR>
map <C-F5> : call ProjectRootCD()<CR>
map <C-S-F5> : call ProjectRootCD(1)<CR>
map <F11> :cn<CR>
map <s-f11> :cp<CR>
map <m-F11> :cnf<CR>
map <m-s-F11> :cpf<CR>
fun! ConditionalCD()
let folder=expand("%:p:h")
if (folder != "")
exec("cd ".folder)
echo "pwd is now: ".folder
else
:echohl WarningMsg | echo "Unable to determine path of current file." | echohl None
endif
endfun
fun! CdUpN(levels)
let l:levels = a:levels
while(l:levels > 0)
exec("cd ..")
let l:levels = l:levels - 1
endwhile
endfun
fun! ProjectRootCD(...)
let folder = FindGitRoot()
if(folder == "")
if !exists("g:projectRoot")
:echohl WarningMsg | echo "Unable to find project root (set default in hosts as g:projectRoot)." | echohl None
return
else
let folder=g:projectRoot
endif
endif
exec("cd ".folder)
if(a:0)
call CdUpN(a:0)
echo "Changed to folder: ".getcwd()
else
echo "Changed to project root folder: ".folder
endif
endfun
fun! GProjectRootCD(...)
let folder=g:projectRoot
exec("cd ".folder)
if(a:0)
call CdUpN(a:0)
echo "Changed to folder: ".getcwd()
else
echo "Changed to project root folder: ".folder
endif
endfun
map ,explorer :call LaunchExplorerPWD()<CR>
fun! LaunchExplorerPWD()
silent exec("!explorer %:p:h")
endfun
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" TODO: This stuff should probably go in the .gvimrc...
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <F2> :call CycleFonts(1)<CR>
map <S-F2> :call CycleFonts(-1)<CR>
map <M-F2> :let fontindex=g:initialfontindex<CR>:call CycleFonts(0)<CR>
map <F3> <C-^>
map <F6> :call LoadHeaderOrSrcFile(0)<CR>
map <S-F6> :call LoadHeaderOrSrcFile(1)<CR>
map <M-F6> ,2<F6>
map <F8> ,_nfcomment
map <M-F8> ,_ncomment
map <S-F8> ,_nuncomment
"map <F12> :w<CR>
"Alt-F12 will reload the file
"map <S-F12> :e!<NL>
imap <F2> <ESC><F2>a
imap <F3> <ESC><F3>a
imap <F5> <ESC><F5>a
imap <F6> <ESC><F6>a
imap <F7> <ESC><F7>a
imap <M-F7> <ESC><M-F7>a
imap <C-F7> <ESC><C-F7>a
imap <F12> <ESC><F12>a
imap <S-F12> <ESC><S-F12>
imap <F8> <ESC><F8>a
imap <F9> <ESC><F9>a
map ,80 :set co=80<CR>
map ,max :set lines=1000<CR>
map ,> :%:s/^[> ]*//ge<NL>:noh<NL>
map ,$> :.,$:s/^[> ]*//ge<NL>:noh<NL>
" Increase/Decrease the window size a bit
map <C-S-UP> 5<C-W>+
map <C-S-DOWN> 5<C-W>-
map <C-S-LEFT> 5<C-W><
map <C-S-RIGHT> 5<C-W>>
" Split windows, 2 to split the current window in half, v to split it vertically
map ,2 <C-W>s
map ,v <C-W>v
" Make windows equal size
map ,equal <C-W>=
" Make current window bigger
map ,tall <C-W>_
map ,wide <C-W>\|
map ,big ,tall,wide
" make current window 5 taller or shorter
map ,5 <C-W>5+
map ,% <C-W>5-
" Redo
" map U <C-R>
" Quick commands for editing this file
map ,svimrc :source $HOME/.vimrc<NL>
map ,evimrc :edit $HOME/.vimrc<NL>
map ,egvimrc :edit $HOME/.gvimrc<NL>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" TODO: Move this to a machine specific file
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map ,ahk :e $USERPROFILE\DOCUMENTS\AutoHotkey.ahk<CR>:set ft=autohotkey<CR>
" Swap the word under the cursor with the current buffer
map ,sw ciw<C-R>0<ESC>
" Sort the selected lines
vmap ,s :!sort<CR>
" Mark Swap: swap word at mark a and mark b
map ,msw mz`a"zyiw`b"yyiw`aciw<C-R>y<ESC>`bciw<C-R>z<ESC>`z
" insert the current date into the file
map ,date o<ESC>"=strftime("%Y.%m.%d")<NL>p
map ,dtime o<ESC>"=strftime("%Y.%m.%d %I:%M %p")<NL>p
" Make the current file writable
if has("unix")
map ,hijack :!chmod +w "<C-R>%"<NL>
else
map ,hijack :!attrib -r <C-R>%<NL>
endif
" replace the character with a carriage return
map ,no; :s/;/<C-Q><C-M>/ge<NL>:noh<NL>
map ,no, :s/,/<C-Q><C-M>/ge<NL>:noh<NL>
map ,nosp :s/ /<C-Q><C-M>/ge<NL>:noh<NL>
"replace spaces with the character
map ,yes; :s/ /;/ge<NL>:noh<NL>:noh<NL>
map ,yes, :s/ /,/ge<NL>:noh<NL>:noh<NL>
map ,;j :s/ */;/ge<NL>:noh<NL>
"remove trailing spaces
map ,rts :%s/\s\+$//<CR>
" Creates a row of === below the current line, same length as line
map ,= yyp:s/[^=]/=/ge<NL>:noh<NL>
"map ,:: O<ESC>"%p$?\.<NL>Dbd0A::<ESC>gJ:noh<NL>
map ,:: :let @" = expand("%:r") . "::"<CR>:<BS>P
map ,iifdef ggO<ESC>"%p$?\.<NL>Dbd00gU$A_H_<ESC>:r!uuidgen<CR>kgJviWUviW:s/-/_/g<CR>,ifdef<NL>:noh<NL>:g/pragma\s*once/d<CR>
map ,ifdef mzyyppkkI#ifndef <ESC>jI#define <ESC>jI#endif // <ESC>ddGo<ESC>po<ESC>`z:noh<NL>
" Include my header: Add a #include for the matching header to the top of a cpp file
map ,imh :0<CR>O#include "<C-R>=expand("%:t:r")<CR>.h"<ESC>
" Include my Qt MOC: Add a #include for the matching Qt moc to the bottom of a cpp file (for unit tests, etc)
map ,imm Go<CR>#include "<C-R>=expand("%:t:r")<CR>.moc"<CR><ESC>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Useful python header stuff
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map ,pyhead ggO#!/usr/bin/python<CR># -*- coding: utf-8 -*-<ESC>
ab pyhead #!/usr/bin/python<CR># -*- coding: utf-8 -*-
"imap <M-[> {<ESC>mza<NL>}<ESC>`za<NL>
if(has("mac"))
imap <D-[> {<NL>}<ESC>O
else
imap <M-[> {<NL>}<ESC>O
endif
"map ,fixconeline 0i<C-F><ESC>
"map ,cfix :normal ,fixconeline<NL>
"map ,ffix /{<NL>v%,cfix<NL>:noh<NL>
map ,cpp ,2<C-W>w,gc<C-W>w1G/clas<NL>Mjjyy,wPd0ywI::<ESC>0PO<ESC>PI#include
map ,_comment 0i<C-R>=comment_string<CR><ESC>
map ,_ncomment :normal ,_comment<NL>
map ,_fcomment I<C-R>=comment_string<CR><ESC>
map ,_nfcomment :normal ,_fcomment<NL>
map ,_uncomment :let @z = @/<CR>:s/^\(\s*\)<C-R>=escape(comment_string, '/')<CR>/\1/e<NL>:let @/ = @z<CR>:<BS>
map ,_nuncomment :normal ,_uncomment<NL>
map ,cw <ESC>mzggO<c-r>=comment_string<CR> Copyright (c) <c-r>=strftime("%Y")<cr>, <c-r>=g:companyName<cr>, All Rights Reserved<ESC>`z
map ,dark :colorscheme torte<cr>:set bg=dark<cr>
map ,light :colorscheme peachpuff<cr>:set bg=light<cr>
" Abbrevations
func! Eatchar(pat)
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfunc
" Remember... <ctrl-v><space> to actually type these things w/o expansion
iabbr <silent> vptr vtkSmartPointer<C-R>=Eatchar('\s')<CR>
iabbr <silent> cdcast dynamic_cast<C-R>=Eatchar('\s')<CR>
iabbr <silent> cscast static_cast<C-R>=Eatchar('\s')<CR>
iabbr <silent> crcast reinterpret_cast<C-R>=Eatchar('\s')<CR>
iabbr <silent> qdcast qSharedPointerDynamicCast<C-R>=Eatchar('\s')<CR>
iabbr <silent> qscast qSharedPointerCast<C-R>=Eatchar('\s')<CR>
map ,dos2unix mz:%s/<C-Q><C-M>$//g<NL>:noh<NL>`z
"map ,tblfmt :perl -S tblfmt.pl "FS=," "OFS= | "
map ,et :call ToggleOption("expandtab")<NL><C-L>
map ,ic :call ToggleOption("ignorecase")<NL><C-L>
map ,ai :call ToggleOption("autoindent")<NL><C-L>
map ,rap :call ToggleOption("wrap")<NL><C-L>
map ,nu :call ToggleOption("number")<NL><C-L>
map ,cuc : call ToggleOption("cuc")<NL><C-L>
map ,cul : call ToggleOption("cul")<NL><C-L>
map ,sp :call ToggleOption("spell")<NL><C-L>
vmap ,ali :call AlignThingy()<CR>
" This general-purpose function must escape it's arguments carefully.
fu! AlignThingy (...) range
" Deal with TABs
let originaletvalue = &expandtab
exe 'set et'
exe a:firstline . "," . a:lastline . "retab"
if (a:0 == 0)
let alignchar = input("Input align character: ")
endif
if (strlen( alignchar ) == 1)
let alignchar = escape( alignchar, ".*[^$" )
call AlignComments (alignchar, a:firstline, a:lastline )
endif
endf
" Originally for Comment alignment, this function is actually general-purpose.
fu! AlignComments (opencomm, firstln, lastln)
let opencomm = a:opencomm
let midln = a:firstln
let lastln = a:lastln
let maxcol = 0
let newcol = 0
" find the most indented comment
while midln <= lastln
let midlnStr = getline(midln)
let newcol = match ( midlnStr, opencomm )
if newcol > maxcol
let maxcol = newcol
endif
let midln = midln + 1
endwhile
let midln = a:firstln
while midln <= lastln
let midlnStr = getline(midln)
let curcol = match ( midlnStr, opencomm )
let spaces = maxcol - curcol
let spaceStr = ""
while spaces > 0
let spaceStr = spaceStr . " "
let spaces = spaces - 1
endwhile
call SubstLine ( midln, opencomm, spaceStr . '&', "" )
let midln = midln + 1
endwhile
endf
" Perform substitution on the existing line
" args :linenum s/pat/rep/flags
fu! SubstLine ( linenum, pat, rep, flags )
let thislineStr = getline( a:linenum )
let thislineStr = substitute( thislineStr, a:pat, a:rep, a:flags )
call setline( a:linenum, thislineStr )
endf
function! OptSet(name,value)
let name=a:name
let value=a:value
execute("let &".name."=".value)
endfunction
function! ToggleOption(option)
let option = a:option
execute ("set inv".option)
endf
function! LoadHeaderOrSrcFile(force_h_cpp)
let fnew = GetHeaderOrSrcFile(a:force_h_cpp)
if strlen(fnew) != 0
execute('edit ' . fnew)
endif
endf
"An empty string is a failure
function! GetHeaderOrSrcFile(force_h_cpp)
let extensions = 'h,ipp,cpp,c,h,'
if (a:force_h_cpp)
let extensions = 'h,cpp,h,'
endif
let oldmagic = &magic
let &magic = 1
let f_ext = fnamemodify(bufname('%'), ':e')
let f_root = fnamemodify(bufname('%'), ':r')
let result = ""
let ext_begin = match(extensions, f_ext ) + 1
while 1
let ext_begin = match(extensions, ',', ext_begin ) + 1
if ext_begin == 0
break
endif
let ext_end = match(extensions, ',', ext_begin)
let ext = strpart(extensions, ext_begin, ext_end - ext_begin)
let result = f_root . '.' . ext
if filereadable(result)
break
endif
" file wasn't readable, try replacing Inc w/ Src and Src w/ Inc
" -- quick and dirty implementation... I'm sure I could do something
" cleaner if I wanted to think about it
let result = substitute(result, 'Inc', 'Src', '')
if filereadable(result)
break
endif
let result = substitute(result, 'Src', 'Inc', '')
if filereadable(result)
break
endif
let result = ""
endwhile
let &magic = oldmagic
return result
endfunction
function! CycleFonts(amount)
let sizes = [ 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36 ]
let g:fontindex = g:fontindex + a:amount
let g:fontindex = max([g:fontindex, 0])
let g:fontindex = min([g:fontindex, len(sizes) - 1])
if(has("mac"))
let f = g:font_base . ":h" . sizes[g:fontindex]
elseif(has("unix"))
let f = g:font_base . " " . sizes[g:fontindex]
else
let f = g:font_base . ":h" . sizes[g:fontindex]
endif
let &guifont = f
endfunction
"fontindex is global for use in the CycleFonts() function
"but we won't reset the font if we've already started
if !exists("fontindex")
let fontindex=g:initialfontindex
call CycleFonts(0)
endif
" @r prints a ruler across the screen that looks something like this:
" ....+....1....+....2....+..
map @r O<ESC>:call RulerStr()<NL>0P0j
function! RulerStr()
let columns = &columns
let inc = 0
let str = ""
while (inc < columns)
let inc10 = inc / 10 + 1
let buffer = "."
if (inc10 > 9)
let buffer = ""
endif
let str = str . "....+..." . buffer . inc10
let inc = inc + 10
endwhile
let str = strpart(str, 0, columns)
let @@ = str
endfunction
map <F4> :call GetFileInThisWindow()<CR>
map <S-F4> :call GetFileInVSplit()<CR>
map <M-F4> :call GetFileInHSplit()<CR>
fun! GetFileLocation()
let fname = expand('<cfile>')
if(fname != '' && fname[0] =~ "[A-Za-z0-9]")
silent let path = system('find `pwd` -name '.fname.' | head -1')
return path
else
echo "No file under cursor"
return ""
endif
endfun
fun! GetFileInThisWindow()
let fname = GetFileLocation()