-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
2830 lines (2292 loc) · 100 KB
/
.vimrc
File metadata and controls
2830 lines (2292 loc) · 100 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
" .
" ##############......##############
" ##############......##############
" ##########..........##########
" ##########........##########
" ##########.......##########
" ##########.....##########..
" ##########....##########.....
" ..##########..##########.........
" ....##########.#########.............
" ..################JJJ............
" ################.............
" ##############.JJJ.JJJJJJJJJJ
" ############...JJ...JJ..JJ JJ
" ##########....JJ...JJ..JJ JJ
" ########......JJJ..JJJ JJJ JJJ
" ###### .........
" .....
" .
" -------------------------------------------------------------------------
" File: .vimrc
" Source: https://github.com/devpunks
" Author: devPunks (github.com/devpunks)
" Description: Vim(rc) configuration file.
" Gist: https://gist.github.com/snuggs/612093
" -------------------------------------------------------------------------
"
" Screencasts - http://vimcasts.org
" Cheatsheets:
" - https://vim.rtorr.com
" - https://devhints.io/vimscript
" TERM - https://vimhelp.org/term.txt.html
" Event order - https://vi.stackexchange.com/q/4493
" Auto Commands - https://vimhelp.org/autocmd.txt.html
" Tutorial - http://learnvimscriptthehardway.stevelosh.com
" https://w0rp.com/blog/post/vim-script-for-the-javascripter
" VIM9 Script - https://vimhelp.org/vim9.txt.html#Vim9-script
" Idiomatic .vimrc - https://github.com/romainl/idiomatic-vimrc
" Styleguide - https://google.github.io/styleguide/vimscriptguide.xml
" Programming - https://got-ravings.blogspot.com/2008/09/vim-pr0n-prototype-based-objects.html
"
" TODO:
" CLICKING LINE NUMBERS
" - https:/reddit.com/r/vim/comments/86pjx4/does_vim_currently_have_a_way_to_handle_clicks_on
" =========================================================================
" -------------------------------------------------------------------------
messages clear " Clear messages
" -------------------------------------------------------------------------
" Reset all autocommand groups
augroup VimDefaults | autocmd! | augroup END
augroup FileDefaults | autocmd! | augroup END
augroup UserDefaults | autocmd! | augroup END
" -------------------------------------------------------------------------
set encoding=UTF-8
scriptencoding UTF-8
set fileencoding=UTF-8
set termencoding=UTF-8
set emoji encoding=UTF-8
" https://stackoverflow.com/q/5845557
" TODO: remove if &compatible | set nocompatible | endif
if !!! exists ( 'g:pluginname_setting' )
unlet! skip_defaults_vim
let g:skip_defaults_vim=0
source $VIMRUNTIME/defaults.vim
endif
execute 'set <FocusLost>=\<Esc>[O'
execute 'set <FocusGained>=\<Esc>[I'
" xterm-focus-event tracking - https://github.com/vim/vim/issues/9296
let &t_fe = '\<Esc>[?1004h' " enable focus-event tracking
let &t_fd = '\<Esc>[?1004l' " disable focus-event tracking
" https://groups.google.com/g/vim_use/c/VyQSx90uaPE
" NOTES -------------------------------------------------------------------
" - https://superuser.com/q/935574/get-rid-of-null-character-in-vim-variable
" - https://til.hashrocket.com/posts/qll3kizlzj-check-that-an-executable-exists-on-the-path
" - Test executables - https://renenyffenegger.ch/notes/development/vim/script/vimscript/functions/executable
echom 'VIM:' v:version
echom 'BASH:' system ( 'echo -n $BASH_VERSION' )
if exists( '$TMUX' ) | echom "TMUX: " .. system( 'echo -n $(tmux -V)' ) | endif
if executable ( 'termux-info' ) | echom 'TERMUX:' $TERMUX_VERSION | endif
" =========================================================================
" {{{ SETTINGS
" =========================================================================
set shellcmdflag=-c " Make shell interactive
" TODO: Make shell -i(nteractive)
"set shellcmdflag=-ic " Make shell interactive
let $GIT_TRACE = 0
let &shell = $SHELL .. ' --login' " Add login
let $prefix = exists ( '$PREFIX' ) ? $PREFIX : '/usr' " Check for TERMUX $PREFIX
" - https://gist.github.com/romainl/7e2b425a1706cd85f04a0bd8b3898805
" - https://stackoverflow.com/q/2288756/how-to-set-working-current-directory-in-vim
set path =./**
set path +=$HOME
set path +=$prefix/include
echom '(vi) PATH:' &path
" increment formats - https://vimtricks.com/p/vimtrick-increment-numbers
set nrformats+=alpha
set nrformats-=octal
set updatetime=150 " (milliseconds)
" https://vimhelp.org/options.txt.html#%27timeout%27
set timeout " on mappings
set ttimeout " on keycodes
set ttimeoutlen=-1 " mappings
set timeoutlen=1000 " keykodes (milliseconds)
" https://vim.fandom.com/wiki/Folding
set foldenable
set foldlevel=1
set foldcolumn=2
set foldclose=all
set foldlevelstart=0
set foldmethod=indent " [ manual|indent|expr|marker|syntax|diff ]
set showcmd " show current command characters
set modeline " https://vim.fandom.com/wiki/Modeline_magic
set cmdheight=2 " sets the :ex command prompt line height
set modelines=1 " Head & tail mode lines (:help modeline)
set showcmdloc=statusline " Add current command to status
set showmatch matchtime=20 " jump to matching brace (in 1/10ths of seconds)
set wrapscan " Search respects wrapping
set hlsearch " result highlight grouping
set incsearch " highlight search matches
" TODO: Problematic for conditionals "A"=="a" vs "A"==?"a"
set smartcase " Capitalization case-sensitive search (overrides ignorecase)
" https://vi.stackexchange.com/q/11236
" https://learnvimscriptthehardway.stevelosh.com/chapters/22.html
set ignorecase " Case in-sensitive search
set fileignorecase " for files & directories
" Bells -------------------------------------------------------------------
" Set termcap(ability) for visual bell
set errorbells " Unset audio bell on errors
"set belloff+=wildmode " Turn off insert completion bell
" Set the window bell to flash
set t_vb=
if has ( 'gui_running' )
set visualbell t_vb=|250f " Nf - where N = milliseconds
elseif exists ( '$TMUX' )
set novisualbell " passthrough to TMUX
else
" <N> - where N = milliseconds
set visualbell t_vb=[?5h$<250>[?5l
endif
" Chrome ------------------------------------------------------------------
" shell window title
" http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#s3
" $ echo -e "\033]2;Your New Title\007"
" https://vim.fandom.com/wiki/Automatically_set_screen_title
" set title
" set t_ts=^[k
" set t_fs=^[\\
set title " Turn on title
set titlelen=75 " Text length of title
set titlestring="VIM SHELL TITLE %<%F%=%l/%L-%P" " Window Title String format
" tabs
set tabline=%!TabLine()
set showtabline=2 " :help setting-tabline
set tabpanel=0 " hide
set tabpanelopt=vert,columns:27,align:right
set tabpanel=%!TabPanel()
function! TabPanel() abort
return printf ( "📑%-2d📄 %%f", g:actual_curtabpage )
endfunction
<
" Menus -------------------------------------------------------------------
" :menu " :help menu
let do_no_lazyload_menus = 1
source $VIMRUNTIME/menu.vim
" - http://vim.wikia.com/wiki/Great_wildmode/wildmenu_and_console_mouse
" - https://stackoverflow.com/q/9511253/how-to-effectively-use-vim-wildmenu
set wildmenu
set infercase
set wildchar=<Tab>
set wildcharm=<C-z> " macros
set wildmode=list:full
set wildoptions=pum,tagfile
set wildignorecase
" set wildignore+=.DS_STORE,.git/,.bundle/,.cache/,.config/,.gem/,.local/,.npm/,.gnupg/,.ssh/,.vim/,bin/,downloads/,log/,logs/,node_modules/,storage/,tmp/,vendor/,images/
function s:ignore ( file = '.gitignore' ) abort
let l:exceptions = []
let l:exclusions = []
const l:root = fnamemodify (
\ finddir ( '.git/..', expand ('%:p:h' ) .. ';' .. $HOME )
\ ?? $HOME , ':p' )
const l:file = l:root .. a:file
echom 'Git Root:' l:root
if !!! filereadable ( l:file ) | return | endif
echom 'Git Ignore:' l:file
for line in readfile ( l:file )
if strlen ( trim ( line ) ) == 0 || match ( line, '^[ \t]*#' ) >= 0
continue
endif
if match ( line, '^[ \t]*!' ) >= 0
call add ( l:exceptions, trim ( line ) )
endif
if match ( line, '^[ \t]*!' ) < 0
call add ( l:exclusions, trim ( line ) )
endif
endfor
echom "\nExceptions:\n" ..
\ l:exceptions ->uniq()
\ ->map( { _, path -> substitute ( path, '^!', '**/', '' ) } )
\ ->map( { _, path -> substitute ( path, '^**\/\/', '', '' ) } )
\ ->join( ',' )
return l:exclusions ->uniq()
\ ->map( { _, path -> '**/' .. path } )
\ ->map( { _, path -> substitute ( path, '^**\/\/', '', '' ) } )
\ ->join( ',' )
endfunction " ignore
set wildignore=
let &g:wildignore=s:ignore ()
" Completion / LSPs -------------------------------------------------------
" (Insert) Tab complete
inoremap <expr> <Tab> pumvisible () ? '<C-n>' : '<C-o>:Tab<CR>'
inoremap <expr> <S-Tab> pumvisible () ? '<C-p>' : '<C-o>:echom "INSERT SHIFT + TAB"<CR>'
inoremap <expr> <M-Tab> pumvisible () ? ':echo "PUM"<CR> :':echom "INSERT ALT + TAB"<CR>'
" https://linuxhandbook.com/vim-auto-complete
" https://vim.fandom.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
" https://github.com/neoclide/coc.nvim/wiki/Using-coc-extensions#implemented-coc-extensions
set complete=.,t ".,w,b,u,i " -t - https://mail-archive.com/vim@vim.org/msg03963.html
set completepopup+=align:item,border:on
set completeopt+=menuone,noinsert,popup " noselect|noinsert for automatic completion
" -------------------------------------------------------------------------
" Complete () -
" -------------------------------------------------------------------------
set completefunc=s:complete
command! -bang -nargs=* Complete call s:complete ( <q-args>, v:none, v:none, <bang>0 )
function! s:complete ( token = '', command = '', cursor = 0, bang = 0 ) " abort
echom 'complete ():' .. join ( a:000, ',' )
let l:token = trim ( a:token ?? expand ( '<cword>' ) ) ?? '.'
echom 'Bang:' a:bang
echom 'Base:' a:command
echom 'Cursor Position:' a:cursor
echom 'Token: "' .. l:token .. '"'
echom 'Shazaam Completion (' l:token '):'
" Check if token is a number
return l:token =~# '^\d\+$'
\ ? l:token
\ : { 'refresh': 'always', 'words': [
\ { 'word': 'fooooo', 'abbr':'fo', 'menu': 'foo', 'info': 'brown fox',
\ 'kind': 'C', 'icase': 0, 'equal': 0, 'dup':1, 'empty': 0, 'user_data': '' },
\ { 'word': 'barrrrr', 'abbr':'ba', 'menu': 'bar', 'info': 'Lazy Dog',
\ 'kind': 'v', 'icase': 0, 'equal': 0, 'dup':1, 'empty': 0, 'user_data': '' }
\ ] }
endfunction " complete
" }}}
" =========================================================================
" {{{ Copy & 🍝Pasta
" :h clipboard
" =========================================================================
set selection=exclusive " No EOL CR/LF
set pastetoggle=<Leader>p " Allow toggle of (paste) insert indentation
set nopaste " non paste mode - https://vimtricks.com/p/vimtricks-avoid-paste-formatting
echom has ( 'clipboard_working' ) ?
\ 'Copy & 🍝Pasta' : '❌ NO Copy & 🍝Pasta'
" Clipboard Registers -----------------------------------------------------
" - https://stackoverflow.com/q/11489428
" - https://github.com/termux/termux-packages/issues/2308
" - https://vimtricks.com/p/vimtrick-the-clipboard-register
" - https://reddit.com/r/termux/comments/c17rwf/how_to_paste_to_vim_from_external_clipboard
" - OSC52 Escape to system clipboard - https://chromium.googlesource.com/apps/libapps/+/master/hterm/etc/osc52.vim
" vnoremap <C-c> "*y<cr>
" inoremap <C-v> “*p<cr>
if has ( 'unnamedplus' ) | set clipboard=unnamed,unnamedplus
else | set clipboard+=unnamed
endif
" copy and paste
" vmap <C-c> "+yi
" vmap <C-x> "+c
" vmap <C-v> c<ESC>"+p
" imap <C-v> <ESC>"+pa
" Termux ------------------------------------------------------------------
" https://ibnishak.github.io/blog/post/copy-to-termux-clip
if executable ( 'termux-clipboard-set' )
echom 'Termux Copy & 🍝Pasta'
" vnoremap <C-x> :!termux-clipboard-set<CR>
" vnoremap <C-c> :w !termux-clipboard-set<CR><CR>
" inoremap <C-v> <ESC>:read !termux-clipboard-get<CR>i
else
echom '❌ NO Termux Copy & 🍝Pasta'
endif
" }}}
" =========================================================================
" {{{ BUFFERS
" =========================================================================
" set nohidden possibly overridden by ZoomWin https://vimtricks.com/p/what-is-set-hidden
set hidden
set confirm " on persistence
set autowrite " on lost focus
set nohidden " Unload buffer when abandoned
set bufhidden=unload " [hide|unload|delete]
set equalalways " on load
set winwidth=1 " initial width
set winheight=1 " initial height
set winminwidth=0 " minimum width
set winminheight=0 " minimum height
set history=1000 " Increase undo limit
set tabpagemax=50 " Maximum number of tab pages
set switchbuf=usetab,newtab " split|vsplit|useopen|uselast
set splitbelow nosplitright " Where to place new buffer location
command! Flush :update | %bd | e# " https://vimtricks.com/p/closing-hidden-buffers
" autocmd QuickFixCmdPre * echom 'Executing QuickFixCmdPre'
" autocmd QuickFixCmdPost * echom 'Executing QuickFixCmdPost'
" }}}
" =========================================================================
" {{{ VIEWS, SESSIONS, VIMINFO
" - https://vimtricks.com/p/saving-session-state
" - https://learnvim.irian.to/basics/views_sessions_viminfo
" =========================================================================
" disable sessions
set viewoptions-=options
set viewoptions+=localoptions
set viewdir=$HOME/.vim/view
set sessionoptions-=options
set sessionoptions+=resize,winpos
set viminfo="NONE" " disable .viminfo
set viminfofile="NONE" " disable .viminfo
set viminfo='100,<50,s10,h,%
set viminfofile=$HOME/.vim/.viminfo
" }}}
" =========================================================================
" {{{ BACKUPS
" - https://groups.google.com/g/vim_use/c/K2Utwkh5f30?pli=1
" - https://alvinalexander.com/linux-unix/vi-vim-swap-backup-tilde-temporary-files-directory-move
" =========================================================================
set backup " keep a backup file (nobackup for inverse)
" Undo location
" set nobackup
" set nowritebackup
" set noswapfile
" set noundofile
set undodir=$TMPDIR " undo location
set directory=$TMPDIR " swap location
set backupdir=$TMPDIR " backup location
" }}}
" =========================================================================
" {{{ CURSOR
" =========================================================================
set ttyfast " for redraws
set nolazyredraw " Fast non-macro updates
set ttyscroll=3 " number of characters for redraws
set cursorline " highlight current cursor line
set cursorcolumn " highlight current cursor column
set nostartofline " respect cursor column position
set cursorlineopt=both " [number,line,both,screenline]
" reset cursor escapes
" use CSI for single quotes ('')
" use \e CSI for double quotes ("")
" https://stackoverflow.com/q/6488683
" https://vim.fandom.com/wiki/Change_cursor_shape_in_different_modes
let &t_SI = '' " START INSERT
let &t_SR = '' " START REPLACE
let &t_EI = '' " NORMAL (EXIT INSERT)
" CURSOR TYPE -------------------------------------------------------------
" 0 Default
" 1 Block (blinking)
" 2 Block (steady)
" 3 Underline (blinking)
" 4 Underline (steady)
" 5 Bar (blinking) (xterm)
" 6 Bar (steady) (xterm)
let &t_SI..="\e[5;0;0 q" " SI = START INSERT bar |
let &t_SR..="\e[3;0;0 q" " SR = START REPLACE underline _
let &t_EI..="\e[1;0;0 q" " EI = NORMAL (EXIT INSERT) block
" CURSOR COLOR ------------------------------------------------------------
let &t_SI..="\e]12;red\x7" " INSERT = red cursor
let &t_SR..="\e]12;blue\x7" " REPLACE = blue cursor
let &t_EI..="\e]12;green\x7" " NORMAL = green cursor
" reset cursor when vim exits
" autocmd VimLeave * silent !echo -ne "]12;cyan\x7"
autocmd VimDefaults VimLeave * silent !echo -ne '[0;0;0 q'
" GUI CURSOR --------------------------------------------------------------
if has ( 'gui_running' )
set guioptions=egmrt " remove ugly toolbar :-)
" https://vim.fandom.com/wiki/Configuring_the_cursor
set guicursor=i:blinkwait90
set guicursor+=i:ver100-iCursor
set guicursor+=n-v-c:blinkwait10
set guicursor+=n-v-c:block-Cursor
endif
" }}}
" =========================================================================
" {{{ MOUSE
" - https://vimhelp.org/options.txt.html#%27ttymouse%27
" =========================================================================
set t_RV= " Disable automatic mouse detection
if has ( 'mouse' ) | set mouse=a | endif " Enable mouse use in a(ll) modes
" https://vld.bg/articles/ttymouse-sgr
" https://stackoverflow.com/a/19253251
" https://stackoverflow.com/q/7000960/in-vim-why-doesnt-my-mouse-work-past-the-220th-column
if has ( 'mouse_sgr' ) | set ttymouse=sgr " Set sgr mouse
else | set ttymouse=xterm2 " degrade to xterm2 mouse
endif
" }}}
" =========================================================================
" {{{ GUTTER
" https://github.com/airblade/vim-gitgutter/commit/8db2fc5
" =========================================================================
set number
set numberwidth=4 " gutter columns
if has ( 'signs' ) " https://vimdoc.sourceforge.net/htmldoc/sign.html
" https://github.com/vim/vim/commit/394c5d8870b15150fc91a4c058dc571fd5eaa97e
set signcolumn=yes " [auto|number|yes|no|off]
endif
" }}}
" =========================================================================
" {{{ STATUS
" Word Count - https://vimtricks.com/p/count-words-and-lines
" - <C-g> - short format
" - g<C-g> - extended format
" - Status line - https://cromwell-intl.com/open-source/vim-word-count.html
" =========================================================================
set showmode " in status Vi (not Vim)
set shortmess= " Verbose command messaging
set shortmess-=S " Show search count
set laststatus=2 " Always show status line
if has ( 'win32' ) | set shortname=on | end
" https://vi.stackexchange.com/a/27508
set ruler " set cursor coordinates
set rulerformat=📏%P⏬%l⏩%c%V " overridden by statusline
set statusline=%#Statement# " initialize highlight group
" buffer number
set statusline+=﹟%n\
" git changes
set statusline+=%{%g:GitChanges()%}
" file type
set statusline+=💻%Y\
" mode
set statusline+=%{(mode()=~#'^c')?'💲':''} " Command
set statusline+=%{(mode()=~#'^i')?'📝':''} " Insert
set statusline+=%{(mode()=~#'^n')?'📄':''} " Normal
set statusline+=%{(mode()=~#'^R')?'📃':''} " Replace
set statusline+=%{(mode()=~#'^V')?'🔎':''} " Visual Line
" https://gnu.org/software/grep/manual/html_node/Character-Classes-and-Bracket-Expressions.html
set statusline+=%{(mode()=~#'^[[:cntrl:]]')?'🔍':''} " Visual Block ()
" full file name
set statusline+=%-4.15F%m
" TODO: Remove (Guten)Tags dependency
if &runtimepath =~ 'gutentag'
set statusline+=%{gutentags#statusline_cb(function('TagsStatus'))}
endif
" flags
set statusline+=\ %r%h
" change to default highlight
set statusline+=\ %#StatusLine#\
" percentage
set statusline+=%-7((%p%%)⇳%)
" cursor line, total lines
set statusline+=%L☰LOC
" breakpoint
set statusline+=\ %<
" align right
set statusline+=%=
" cursor column position
set statusline+=%5(%4l⇩%)✖%-8.(⇨%-c%-V%)
" Show Command
set statusline+=\|%1.(%k%)
" Show Control Character Value
set statusline+=\|%-2(%S%)
" Show Cursor Character Values
set statusline+=%{CursorCharacter()}
set statusline+=%< " breakpoint
set statusline+=%#Normal# " set highlight
" formatoptions
set statusline+=\ 📜\ %{&fo}
" show colorscheme on statusline
set statusline+=\ 🎨\ %{get(g:,'colors_name','NONE')}\
" }}}
" =========================================================================
" {{{ MAPPINGS
" - :help ga
" - https://vi.stackexchange.com/q/16161
" - https://vi.stackexchange.com/q/2089
" - https://vi.stackexchange.com/q/7722/how-to-debug-a-mapping
" set a map leader for more key combos
" - https://stackoverflow.com/q/1764263/what-is-the-leader-in-a-vimrc-file
" " https://stevelosh.com/blog/2010/09/coming-home-to-vim/#using-the-leader
" - https://subscription.packtpub.com/book/data/9781789341096/3/ch03lvl1sec26/the-leader-key
let g:mapleader = ','
" :h modifyOtherKeys
" let &t_TI = ''
" let &t_TE = ''
" let &t_TI = '[>4;2m'
" let &t_TE = '[>4;m'
echom 'modifyOtherKeys: t_TI='..&t_TI..' t_TI='..&t_TE
" =========================================================================
" Map semi-colon to colon (no need to press <SHIFT>)
nnoremap ; :
" Splits
nnoremap _ :split<CR>
nnoremap <Bar> :vsplit<CR> :wincmd l<CR>
" <CTRL+h> Focus on pane to left
nnoremap <C-h> <C-w>h
" <CTRL+j> Focus on pane down
nnoremap <C-j> <C-w>j
" <CTRL+k> Focus on pane up
nnoremap <C-k> <C-w>k
" <CTRL+l> Focus on pane to right
nnoremap <C-l> <C-w>l
" Equal sized panes
nnoremap = <C-w>=
" Maximize pane (tmux zoom)
nnoremap <C-z> <C-w>_ \| <C-w>\|
" :Bdelete menu<CR>
nnoremap <Del> x
nnoremap <Del> x
nnoremap <Tab> :Tab<CR>
nnoremap <Space> :Space<CR>
nnoremap <Enter> :Enter<CR>
nnoremap <C-f> :Search<CR>
nnoremap <S-Tab> :echom 'SHIFT + TAB'<CR>
nnoremap <Tab><Enter> :echom 'TAB + ENTER'<CR>
nnoremap <Enter><Tab> :echom 'ENTER + TAB'<CR>
nnoremap <Tab><Space> :echom 'TAB + SPACE'<CR>
nnoremap <Space><Tab> :echom 'SPACE + TAB'<CR>
nnoremap <Space><Enter> :echom 'SPACE + ENTER'<CR>
nnoremap <Enter><Space> :echom 'ENTER + SPACE'<CR>
" TODO: don't clobber Tab
" inoremap <Tab> <C-o>:echom 'INSERT TAB'<CR>
inoremap <Tab><Enter> <C-o>:echom 'INSERT TAB + ENTER'<CR>
inoremap <Enter><Tab> <C-o>:echom 'INSERT ENTER + TAB'<CR>
inoremap <Tab><Space> <C-o>:echom 'INSERT TAB + SPACE'<CR>
inoremap <Space><Tab> <C-o>:echom 'INSERT SPACE + TAB'<CR>
inoremap <Space><Enter> <C-o>:echom 'INSERT SPACE + ENTER'<CR>
inoremap <Enter><Space> <C-o>:echom 'INSERT ENTER + SPACE'<CR>
" TODO: FIX ECHO MESSAGE PRINTING TO COMMAND LINE
nnoremap <silent> <C-c> :if v:hlsearch \| nohlsearch \| endif <CR>
nnoremap <Leader>? :h index<CR>
nnoremap <Leader>/ :verbose map<CR>
" tabs
nnoremap <silent> L :tabnext<CR>
nnoremap <silent> H :tabprevious<CR>
" TODO: Prevent overriding <C-o> & C-t>
" - https://stackoverflow.com/q/27588664/difference-between-c-t-and-c-o-in-vim
" Open Url on this line with the browser \w
cnoremap <C-o> :call Browse ()<CR>
" tabs - https://gist.github.com/Starefossen/5957088
" TODO: <C-t> conflicts with :tab pop
nnoremap <silent><Tab><Del> :Bwipeout menu<CR>
" current buffer in new (t)ab
nnoremap <Leader>t <C-w>t
" TODO: Determine if the following two commands work
" simulate break pane in TMUX
nnoremap <C-w>t :tab split<CR>
" All buffers into tabs
nnoremap <C-w>T :tabo<CR> :bufdo tab split<CR>
" normal mode: save
nnoremap <C-s> :update<CR> :echo 'Updated'<CR>
" visual mode: escape to normal and update
vnoremap <C-s> <C-c>:update<CR> :echo 'Updated'<CR>
" insert mode: escape to normal and save
inoremap <C-s> <C-o>:write<CR><C-o>:echo 'Updated'<CR>
" https://vimhelp.org/terminal.txt.html
if has ( 'terminal' )
" set termwinkey=<Esc> " TODO: fix ESC key in Termux
set termwinkey=<C-w> " The key that starts a CTRL-W command in a terminal window.
nnoremap <S-t> :terminal<CR>
" :h terminal
autocmd VimDefaults TerminalWinOpen echo 'Terminal Window Open'
" setlocal bufhidden=hide
endif
" Reload .vimrc configuration
" nnoremap <Leader>R :source ~/.vimrc
cnoremap <C-r> :source ~/.vimrc<CR>
" }}}
" =========================================================================
" {{{ FILES
" - Tagbar C-Tags https://github.com/preservim/tagbar/wiki
" - Per type configuration - https://vimtricks.com/p/per-file-type-configs
" - autocommands - https://gist.github.com/romainl/6e4c15dfc4885cb4bd64688a71aa7063
" =========================================================================
let g:blacklist = [ 'nofile', 'help', 'terminal', 'startify' ] " filetypes
set autoread " re-read files
set noautowrite " do not autowrite
set noautowriteall " do not autowrite (all)
set nofixendofline " Disable <EOL> insertion
" Indentation ------------------------------------
set smarttab " 'tab' insertion
set autoindent " auto(matically smart)indent
set copyindent " copy previous line indentation
set breakindent " break with existing line indent
" TODO: remove set smartindent " indent based off current line on load
filetype indent on " filetype - https://vimdoc.sourceforge.net/htmldoc/filetype.html
" Meta-chars ------------------------------------
set fillchars+=fold:↯,foldopen:-,foldclose:+,foldsep:↯
set fillchars+=stl:▲,stlnc:\ ,vert:‖,diff:-,eob:𝕏,lastline:▶
" Format Options ------------------------------------
set joinspaces " Add two spaces after punctuation
" https://vimdoc.sourceforge.net/htmldoc/change.html#fo-table
set formatoptions= " reset
set formatoptions+=c " autowrap `c`omments (with leader)
set formatoptions+=j " Delete joining line comment
set formatoptions+=l " preserve existing lines
set formatoptions+=n " Format numbered lists
set formatoptions+=o " Preserve o/O insert comments
set formatoptions+=q " autowrap comments with gq program
set formatoptions+=r " Preserve comment on CRLF newline
set formatoptions+=t " autowrap using `t`extwidth
set formatoptions+=/ " do not insert // leader unless after statement unless BOL
set fileformats=unix,dos " set <LF> (unix) first, then try <CR><LF> (DOS)
" -------------------------------------------------------------------------
" Omni-Complete
" - See $VIMRUNTIME/autoload/*
" - https://vim.fandom.com/wiki/Omni_completion
" - Defaults - https://github.com/vim/vim/tree/master/runtime/autoload
" -------------------------------------------------------------------------
autocmd FileDefaults VimEnter * set omnifunc=syntaxcomplete#Complete
" -------------------------------------------------------------------------
" Tar - https://vi.stackexchange.com/a/2224
" -------------------------------------------------------------------------
let g:loaded_tar = 1
let g:loaded_tarPlugin = 1
" -------------------------------------------------------------------------
" Zip - https://vi.stackexchange.com/q/2223/how-to-tell-vim-not-to-try-to-unzip-a-file
" -------------------------------------------------------------------------
let g:loaded_zip = 1
let g:loaded_zipPlugin = 1
" -------------------------------------------------------------------------
" .vimrc - https://vimhelp.org
" -------------------------------------------------------------------------
" Autoload .vimrc on write
autocmd FileDefaults BufWritePost $MYVIMRC nested source $MYVIMRC
" -------------------------------------------------------------------------
" .tmux.conf - https://man7.org/linux/man-pages/man1/tmux.1.html
" -------------------------------------------------------------------------
" Autoload .tmux.conf on write
autocmd FileDefaults BufWritePost .tmux.conf
\ echom 'Loading TMUX Configuration'
\| call system ( 'tmux source-file "$HOME/.tmux.conf"' )
\| call system ( 'tmux display-message "Source file loaded! (#{config_files})"' )
" -------------------------------------------------------------------------
" CSV - https://github.com/chrisbra/csv.vim
" -------------------------------------------------------------------------
autocmd FileDefaults BufNewFile,BufReadPost *.csv,*.dat call g:CSV ()
function g:CSV () abort
setfiletype csv
" let l:csv_arrange_align = 'l*'
ArrangeColumn
echom 'loaded CSV (See https://github.com/chrisbra/csv.vim)'
let g:csv_highlight_column = 'y'
endfunction " CSV
" -------------------------------------------------------------------------
" Markdown - http://vimcasts.org/episodes/hard-wrapping-text
" -------------------------------------------------------------------------
augroup FileDefaults
autocmd BufNewFile,BufReadPost *.md setlocal formatoptions-=t formatoptions+=n
autocmd BufNewFile,BufReadPost README setlocal formatoptions-=t formatoptions+=n
augroup END
" -------------------------------------------------------------------------
" XML - See $VIMRUNTIME/autoload/xmlcomplete.vim
" -------------------------------------------------------------------------
autocmd FileDefaults FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
" -------------------------------------------------------------------------
" HTML - https://vimtricks.com/p/vim-autocomplete-html-tags
" -------------------------------------------------------------------------
autocmd FileDefaults FileType html,eruby setlocal omnifunc=htmlcomplete#CompleteTags
" Slim - https://github.com/slim-template/vim-slim
autocmd FileDefaults BufNewFile,BufReadPost *.slim setlocal filetype=slim
" -------------------------------------------------------------------------
" CSS - https://simplified.guide/vim/auto-complete-css
" -------------------------------------------------------------------------
augroup FileDefaults
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd BufNewFile,BufReadPost *.css,*.sss,*.sass,*.scss call g:CSS ()
augroup END
function! g:CSS () abort
match WarningMsg /-\(moz\|webkit\|o\|ms\)-/
setlocal filetype=css
if &runtimepath !~ 'vim-css3-syntax' | return | endif
if &runtimepath !~ 'tagbar' | return | endif
let g:tagbar_type_css = {
\ 'ctagstype' : 'Css',
\ 'kinds' : [
\ 'c:classes',
\ 's:selectors',
\ 'i:identities'
\ ]
\ } " tagbar_type_css
endfunction " g:CSS
" -------------------------------------------------------------------------
" Go
" -------------------------------------------------------------------------
autocmd FileDefaults FileType go setlocal omnifunc=syntaxcomplete#Complete
" -------------------------------------------------------------------------
" PHP - https://simplified.guide/vim/auto-complete-php
" -------------------------------------------------------------------------
autocmd FileDefaults FileType php setlocal omnifunc=phpcomplete#CompletePHP
" -------------------------------------------------------------------------
" Python - https://simplified.guide/vim/auto-complete-python
" -------------------------------------------------------------------------
autocmd FileDefaults FileType python setlocal omnifunc=python3complete#Complete
" -------------------------------------------------------------------------
" Javascript - https://simplified.guide/vim/auto-complete-javascript
" -------------------------------------------------------------------------
augroup FileDefaults
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd BufNewFile,BufReadPost *.js,*.es,*.mjs setlocal filetype=javascript
augroup END
" -------------------------------------------------------------------------
" Nodejs - https://simplified.guide/vim/auto-complete-javascript
" -------------------------------------------------------------------------
autocmd FileDefaults BufNewFile,BufReadPost * call s:DetectNode ()
function! s:DetectNode ()
if getline ( 1 ) !~ 'node' | return | endif
setlocal filetype=javascript
setlocal omnifunc=javascriptcomplete#CompleteJS
endfun
" -------------------------------------------------------------------------
" Ruby - https://stackoverflow.com/q/15720313/vim-omnicomplete-with-ruby-only-partially-works/22805517#22805517
" -------------------------------------------------------------------------
augroup FileDefaults
autocmd BufNewFile,BufReadPost *.erb :setlocal filetype=eruby
autocmd BufNewFile,BufReadPost Gemfile :setlocal filetype=ruby
autocmd BufNewFile,BufReadPost Rakefile,*.rake :setlocal filetype=rake
autocmd FileType ruby,rake setlocal omnifunc=rubycomplete#Complete
augroup END
let g:tagbar_type_ruby = {
\ 'ctagsbin' : 'ripper-tags',
\ 'ctagsargs' : [ '-f', '-' ],
\ 'scope2kind' : { 'class' : 'c' },
\ 'kind2scope' : { 'c' : 'class', 'm' : 'class' },
\ 'kinds' : [
\ 'a:aliases',
\ 'f:methods',
\ 'm:modules',
\ 'c:classes',
\ 'C:constants',
\ 'd:describes',
\ 'F:singleton methods'
\ ] } " g:tagbar_type_ruby
" }}}
" =========================================================================
" {{{ FUNCTIONS
" - https://tecmint.com/bash-scripts-linux-sysadmin
" =========================================================================
let shazam='Bar'
function Foo{g:shazam} () abort
echom 'Shazzaaaam'
endfunction
command! Tab call s:tab ()
function! s:tab () abort
echom 'Tabbbbbiiiiing'
" Call (User) completefunc
execute "normal! \<C-x>"
endfunction " tab
command! Space call s:space ()
function! s:space () abort
echom 'Spacing ( Not Yet Implemented. See :Space command )'
endfunction " space
command! Enter call s:enter ()
function! s:enter () abort
echom 'Entering ( Not Yet Implemented. See :Enter command )'
endfunction " enter
autocmd UserDefaults CursorHoldI * :Idle
command! Idle call s:idle ()
function! s:idle () abort
echom 'Idling ( Not Yet Implemented. See :Idle command )'
endfunction " idle
finish
" -------------------------------------------------------------------------
" Define () - current word
" - Dictionary
" -------------------------------------------------------------------------
command -bang -nargs=? -complete=custom,Complete Define call s:define ( <bang>0, <f-args> )
function s:define ( ... ) " abort
echom 'define ():'
const l:bang = get ( a:, 1, v:false )
const l:term = get ( a:, 2, expand ( '<cword>' ) )
echom 'argument count:' argc ()
echom 'bang:' l:bang
let @/ = l:term
echom '"' .. l:term .. '"'
endfunction " define
" -------------------------------------------------------------------------
" Thesaurus
" - Moby - https://gutenberg.org/iles/3202/mthesaur.txt
" -------------------------------------------------------------------------
nnoremap <leader>t g:Thesaurus ()
autocmd VimDefaults VimEnter * call g:Thesaurus ()
function! g:Thesaurus () abort
let l:path = expand ( '$HOME/mthesaur.txt' )
if !!! filereadable ( path ) | return | endif
" https://github.com/vim/vim/issues/1611
" https://thesynack.com/posts/vim-thesaurus
echom 'setting thesaurus to' path
set thesaurus=path " https://stackoverflow.com/q/33453468
" let s:saved_ut = &ut
" if &ut > 200 | let &ut = 200 | endif
" augroup ThesaurusAuGroup
" autocmd CursorHold,CursorHoldI <buffer>
" \ let &ut = s:saved_ut |
" \ set iskeyword-=32 |
" \ autocmd! ThesaurusAuGroup
" augroup END
" return ":set iskeyword+=32\<cr>vaWovea\<c-x>\<c-t>"
endfunction " Thesaurus
" -------------------------------------------------------------------------
" Search () - in buffers, windows, tabs, tags, scopes
" - :help @/
" -------------------------------------------------------------------------
set hlsearch
command! -bang -nargs=? -complete=customlist,s:fuzz Search call s:search ( <bang>0, <f-args> )
function! s:search ( ... ) abort
echom 'search ():'
const l:bang = get ( a:, 1, v:false )
const l:term = get ( a:, 2, expand ( '<cword>' ) )
echom 'argument count:' argc ()
echom 'bang:' l:bang
let @/ = l:term
echom '"' .. l:term .. '"'
endfunction " search
function s:fuzz ( ... ) abort
const l:term = get ( a:, 1, expand ( '<cword>' ) )
echom 'This is the -complete=func' l:term
echom a:000
return [ 'shaaa', 'zaaaaam' ]
endfunction " fuzz
" -------------------------------------------------------------------------
" Find () - in buffer
" - :help ascii
" -------------------------------------------------------------------------
" :h finddir()
" :h findfile()
command! -bang -nargs=* -complete=custom,Complete Find call s:find ( <bang>0, <f-args> )
function! s:find ( ... ) abort
echom 'find ():'
const l:bang = get ( a:, 1, v:false )
const l:term = get ( a:, 2, expand ( '<cword>' ) )
echom 'argument count:' argc ()
echom 'bang:' l:bang
let @/ = l:term
echom '"' .. l:term .. '"'
set showtabpanel=1 " show