-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_vimrc.tmpl
More file actions
1170 lines (1043 loc) · 37.8 KB
/
dot_vimrc.tmpl
File metadata and controls
1170 lines (1043 loc) · 37.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" set x=y [[[ "
set autoindent
set autoread
set background=dark
" set colorcolumn=80
set clipboard+=unnamedplus
set diffopt=filler,context:3
if has('nvim-0.3.2') || has("patch-8.1.0360")
set diffopt=filler,internal,algorithm:histogram,indent-heuristic
endif
set encoding=utf-8
set expandtab
" set foldmethod=indent
set foldmethod=marker
set hlsearch
" set ignorecase
set linebreak
set linespace=5
set mouse=a
if exists('+mousescroll')
set mousescroll=ver:5,hor:1
endif
" set mouse=c
set nofixendofline
" set noswapfile
set relativenumber
set shiftwidth=4
set smartcase
set tabstop=4
" set t_Co=256
set termguicolors
set timeoutlen=350
" set timeoutlen=200
" set tw=75
" set tw=70
set tw=60
set undodir=~/.vim/undo
set undofile
" set updatetime=1000
" set updatetime=500
set updatetime=500
autocmd VimResized * wincmd =
filetype plugin on
filetype indent on
syntax on
autocmd CursorHold * if getcmdwintype() == '' | checktime | endif
" cursor indicator [[[ "
" set listchars=tab:\|\
" set list
" set cursorcolumn
" set cursorline
" ]]] cursor indicator "
" ]]] set x=y "
" commands for file types [[[ "
filetype plugin indent on
autocmd BufNewFile,BufRead .* set syntax=sh
autocmd BufRead,BufNewFile /tmp/calcurse*,~/.calcurse/notes/* set filetype=markdown
autocmd FileType *css,gitcommit,haskell,htmldjango,html,graphql,javascript,javascriptreact,json,lisp,markdown,
\racket,tex,text,typescript,typescriptreact,yaml set tabstop=2 shiftwidth=2
" autocmd BufNewFile,BufRead *.md set filetype=markdown
" autocmd Filetype markdown set textwidth=0
autocmd Filetype markdown set textwidth=55
" autocmd Filetype html set foldmarker=0
autocmd BufNewFile,BufRead *.gd set expandtab!
autocmd Filetype go set noexpandtab sw=4
" autocmd FileType go,html,java,javascript,python,lua set fdm=indent
" autocmd FileType go,html,java,javascript,javascriptreact,Jenkinsfile,python,lua set fdm=indent
autocmd FileType go,html,java,Jenkinsfile,python,lua set fdm=indent
" autocmd FileType html,javascript,Jenkinsfile,python,lua set fdm=indent
autocmd BufNewFile,BufRead *.gql setfiletype graphql
autocmd Filetype markdown let g:AutoPairs = {'(':')', '[':']', '{':'}','"':'"', "`":"`", '```':'```', '"""':'"""', "'''":"'''", "*":"*"}
" autocmd Filetype markdown map <F8> :LivedownToggle<CR>
autocmd Filetype markdown let g:AutoPairs={'(':')', '[':']', '{':'}','"':'"', "`":"`", '```':'```', '"""':'"""', "'''":"'''","*":"*"}
autocmd Filetype markdown map <F8> :MarkdownPreview<CR>
autocmd Filetype markdown map <F9> :MarkdownPreviewStop<CR>:MarkdownPreview<CR>
autocmd Filetype markdown inoremap < <Esc><<A
autocmd Filetype markdown inoremap << <
autocmd Filetype markdown inoremap > <Esc>>>A
autocmd Filetype markdown inoremap >> >
" autocmd Filetype markdown set commentstring=<!---\ %s\ -->
" format options [[[ "
" a = auto-format paragraphs
" c = wrap comments
" j = remove comment header when joining lines
" M = don't add space when joining lines
" q = format comments with gq
" t = wrap lines
" v = break lines in insert
" w = whitespace continues paragraph
" ]]] format options "
" autocmd FileType markdown,tex,text set spell spelllang=en_us formatoptions=acjMqtvw
autocmd FileType markdown,tex,text set spell spelllang=en_us formatoptions=cjMqtvw
autocmd Filetype groovy,Jenkinsfile,taskdata set tw=0
autocmd Filetype json nnoremap <leader>j :%!python -m json.tool<CR>
autocmd Filetype json set foldmethod=marker
autocmd Filetype racket set commentstring=;%s;
autocmd Filetype racket let g:AutoPairs = {'(':')', '[':']', '{':'}','"':'"', "`":"`", '```':'```', '"""':'"""', "'''":"'''"}
autocmd FileType sh map <F8> :!clear && shellcheck %<CR>
autocmd FileType tex set updatetime=1000 timeoutlen=300
autocmd FileType tex map <F8> :VimtexCompile<CR>
autocmd VimEnter *.tex VimtexCompile
autocmd VimLeave *.tex !tex-clean %:p
autocmd BufNewFile,BufRead *.tmpl set tw=0 sw=2 ft=go-template fmr=[[[,]]]
" " auto-reload vimrc [[[ "
" augroup myvimrc
" au!
" au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
" augroup END
" " ]]] auto-reload vimrc "
" ]]] commands for file types "
" commands for specific files [[[ "
autocmd BufNewFile,BufRead watson*.fish set tabstop=2 shiftwidth=2 expandtab
autocmd BufWritePost config.def.h silent !cd %:p:h; sudo rm config.h; sudo bear make install
" autocmd BufRead config.def.h map <F8> :silent !cd %:p:h; sudo rm config.h; sudo bear make install<CR>
autocmd BufRead config.def.h map <F10> :silent !cd %:p:h<CR>:!sudo rm config.h; sudo bear make install<CR>
autocmd BufRead config.def.h set updatetime=3000
autocmd BufRead commit-msg.txt set filetype=gitcommit tw=72
autocmd VimLeave /etc/default/grub !sudo grub-mkconfig -o /boot/grub/grub.cfg
" autocmd BufWritePost key_* !sync-shortcuts
autocmd BufNewFile,BufRead key_* map <F1> :w<CR>:silent !sync-shortcuts<CR>
" map <F1> :silent !scp %:p k@192.168.0.17:/home/k/a1<CR>
" map <F2> :silent !scp -P 2222 e1.html e1_style.css kevin@127.0.0.1:/home/kevin/Downloads/e1<CR>
" map <F6> :make -C ~/Documents/resume cv<CR>
" ]]] commands for specific files "
" vim-plug [[[
" plug auto-install
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
" prequisite for other plugins
Plug 'vim-scripts/L9'
" find files from within Vim
" Plug 'vim-scripts/FuzzyFinder'
{{ if not .gui }}
" Gotham color scheme
Plug 'whatyouhide/vim-gotham'
{{ end }}
" " collection of Vim color schemes
" Plug 'flazz/vim-colorschemes'
" " preview Vim color scheme easily within Vim
" Plug 'xolox/vim-colorscheme-switcher'
" " prerequisite for above plugin
" Plug 'xolox/vim-misc'
" automatically save buffers upon returning to normal mode
Plug '907th/vim-auto-save'
let g:auto_save = 1
" let g:auto_save_events = ["CursorHold", "CursorHoldI"]
let g:auto_save_events = ["CursorHold"]
" autocmd VimEnter *.tex let g:auto_save = 0
" provides various functionality for writing LaTeX in Vim
Plug 'lervag/vimtex'
" au BufWritePost *.tex silent call Tex_RunLaTeX()
au BufWritePost *.tex silent !pkill -USR1 xdvi.bin
let g:Tex_MultipleCompileFormats = 'dvi,pdf'
" let g:vimtex_view_general_viewer = 'evince'
let g:vimtex_view_general_viewer = 'zathura'
" let g:vimtex_quickfix_latexlog = {
" \ 'overfull' : 0,
" \ 'underfull' : 0,
" \ 'global' : 0,
" \ 'packages' : {
" \ 'biblatex' : 0,
" \ 'gensymb' : 0,
" \ },
" \ 'references' : 0,
" \ 'unused' : 0,
" \}
let g:vimtex_quickfix_ignore_filters = [
\'Overfull',
\]
let g:vimtex_quickfix_autoclose_after_keystrokes = 5
let g:vimtex_compiler_latexmk = {
\ 'continuous' : 1,
\}
" \ 'continuous' : 0,
{{ if and (not (eq .chezmoi.username "root")) (eq .chezmoi.username "kevin") }}
if has('nvim')
Plug 'neovim/nvim-lspconfig'
Plug 'Saghen/blink.cmp', { 'tag': 'v1.*' }
endif
{{ end }}
" wrote short bits of text that expand into whatever you want
" demo: https://www.youtube.com/watch?v=Zik6u0klD40
Plug 'SirVer/ultisnips'
" better key bindings for UltiSnipsExpandTrigger
let g:UltiSnipsExpandTrigger = "<tab>"
let g:UltiSnipsJumpForwardTrigger = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<C-tab>"
let g:ultisnips_javascript = {
\ 'keyword-spacing': 'always',
\ 'semi': 'never',
\ 'space-before-function-paren': 'never',
\ }
" custom snippets
Plug 'Kevin-Mok/vim-snippets'
Plug 'vim-airline/vim-airline'
let g:airline_powerline_fonts = 1
let g:airline_theme='kmwal'
let g:airline_skip_empty_sections = 1
let g:airline#extensions#whitespace#enabled = 0
let g:km_airline_path_style = get(g:, 'km_airline_path_style', 'context')
let g:km_airline_show_file_flags = get(g:, 'km_airline_show_file_flags', 1)
let g:km_airline_show_cursor_info = get(g:, 'km_airline_show_cursor_info', 1)
let g:airline_section_error = ''
let g:airline_section_warning = ''
let g:airline_section_b = ''
let g:airline_section_c = '%{KmAirlinePath()}'
let g:airline_section_x = '%{KmAirlineFileFlags()}'
let g:airline_section_y = ''
let g:airline_section_z = '%{KmAirlineCursorInfo()}'
" continue Markdown lists when started
" arc
Plug 'dkarter/bullets.vim'
" coordinate Vim color scheme with terminal color scheme
Plug 'dylanaraps/wal.vim'
" Plug 'morhetz/gruvbox'
Plug 'bluz71/vim-nightfly-colors', { 'as': 'nightfly' }
" repeat plugin commands
Plug 'tpope/vim-repeat'
" better Django support
Plug 'tweekmonster/django-plus.vim'
" auto-close brackets
Plug 'jiangmiao/auto-pairs'
let g:AutoPairsMapSpace = 0
Plug 'henrik/vim-indexed-search'
Plug 'PotatoesMaster/i3-vim-syntax'
" vim file explorer
Plug 'terryma/vim-multiple-cursors'
" let g:multi_cursor_select_all_word_key='<C-a>'
let g:multi_cursor_exit_from_visual_mode=0
let g:multi_cursor_exit_from_insert_mode=0
Plug 'dag/vim-fish'
" live preview Markdown"
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install', 'for': 'markdown' }
let g:mkdp_auto_start = 0
let g:mkdp_theme = 'dark'
let g:mkdp_echo_preview_url = 1
let g:mkdp_markdown_css = expand('~/.vim/markdown-preview/github-dark.css')
" git helper
Plug 'tpope/vim-fugitive'
" auto reload file
Plug 'djoshea/vim-autoread'
" Plug 'mustache/vim-mustache-handlebars'
" Plug 'trapd00r/vim-syntax-vidir-ls'
Plug 'calviken/vim-gdscript3'
" display hex colors in Vim
" Plug 'RRethy/vim-hexokinase'
Plug 'junegunn/goyo.vim'
" prevent commands being executed through modelines "
Plug 'ciaranm/securemodelines/'
" different colors for each layer of surrounding brackets
Plug 'luochen1990/rainbow'
let g:rainbow_active = 1
" easy custom text objects
Plug 'kana/vim-textobj-user'
" latex custom text objects
Plug 'rbonvall/vim-textobj-latex'
" swap words
Plug 'tommcdo/vim-exchange'
" Plug 'scrooloose/nerdtree'
" let NERDTreeQuitOnOpen=1
" let NERDTreeShowHidden=1
" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Plug 'junegunn/fzf.vim'
Plug 'christoomey/vim-tmux-navigator'
" mappings [[[ "
let g:tmux_navigator_no_mappings = 1
nnoremap <A-j> :TmuxNavigateDown<cr>
nnoremap <A-k> :TmuxNavigateUp<cr>
nnoremap <A-h> :TmuxNavigateLeft<cr>
nnoremap <A-l> :TmuxNavigateRight<cr>
" nnoremap <C-Down> :TmuxNavigateDown<cr>
" nnoremap <C-Up> :TmuxNavigateUp<cr>
" nnoremap <C-Left> :TmuxNavigateLeft<cr>
" nnoremap <C-Right> :TmuxNavigateRight<cr>
" ]]] mappings "
" highlight multiple words
" TODO: mapping conflicts "
" Plug 'inkarkat/vim-mark'
" Plug 'jceb/vim-orgmode'
" let g:org_todo_keywords=['TODO', 'STARTED', '|', 'DONE']
Plug 'junegunn/vim-easy-align'
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
Plug 'wlangstroth/vim-racket'
Plug 'neovimhaskell/haskell-vim'
" Plug 'masukomi/vim-markdown-folding'
Plug 'mikeboiko/vim-markdown-folding'
autocmd FileType markdown set foldexpr=NestedMarkdownFolds()
Plug 'cespare/vim-toml'
Plug 'dpelle/vim-LanguageTool'
" increment dates with C-a
Plug 'tpope/vim-speeddating'
Plug 'martinda/Jenkinsfile-vim-syntax'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
let g:go_fmt_command = ""
Plug 'buoto/gotests-vim'
Plug 'tomlion/vim-solidity'
Plug 'jparise/vim-graphql'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'mlaursen/vim-react-snippets', { 'branch': 'main' }
Plug 'cristianoliveira/vim-react-html-snippets'
Plug 'jidn/vim-dbml'
" Plug 'FuDesign2008/emoji-snippets.vim'
Plug 'tpope/vim-surround'
" Plug 'tpope/vim-commentary'
Plug 'preservim/nerdcommenter'
"Plug 'vimwiki/vimwiki'
"let g:vimwiki_list = [{'path': '~/vimwiki/', 'syntax': 'markdown', 'ext': '.md'}]
"Plug 'tools-life/taskwiki'
" ]]] vim-plug "
" Mappings [[[ "
call plug#end()
function! LoadWalPalette() abort
let l:wal_colors_path = expand('~/.cache/wal/colors-wal.vim')
if !filereadable(l:wal_colors_path)
return {}
endif
let l:wal_lines = readfile(l:wal_colors_path)
let l:wal_text = join(l:wal_lines, "\n")
let l:palette = {
\ 'path': l:wal_colors_path,
\ 'mtime': getftime(l:wal_colors_path),
\ 'raw': l:wal_text,
\ 'bg': matchstr(l:wal_text, 'let color0 = "\zs#[0-9A-Fa-f]\{6}\ze"'),
\ 'const': matchstr(l:wal_text, 'let color1 = "\zs#[0-9A-Fa-f]\{6}\ze"'),
\ 'string': matchstr(l:wal_text, 'let color2 = "\zs#[0-9A-Fa-f]\{6}\ze"'),
\ 'type': matchstr(l:wal_text, 'let color3 = "\zs#[0-9A-Fa-f]\{6}\ze"'),
\ 'func': matchstr(l:wal_text, 'let color4 = "\zs#[0-9A-Fa-f]\{6}\ze"'),
\ 'keyword': matchstr(l:wal_text, 'let color5 = "\zs#[0-9A-Fa-f]\{6}\ze"'),
\ 'special': matchstr(l:wal_text, 'let color6 = "\zs#[0-9A-Fa-f]\{6}\ze"'),
\ 'fg': matchstr(l:wal_text, 'let color7 = "\zs#[0-9A-Fa-f]\{6}\ze"'),
\ 'line': matchstr(l:wal_text, 'let color8 = "\zs#[0-9A-Fa-f]\{6}\ze"'),
\ }
if empty(l:palette.bg)
let l:palette.bg = '#000000'
endif
if empty(l:palette.fg)
let l:palette.fg = '#ffffff'
endif
for l:key in ['const', 'string', 'type', 'func', 'keyword', 'special', 'line']
if empty(l:palette[l:key])
let l:palette[l:key] = l:palette.fg
endif
endfor
let l:palette.sign = l:palette.func
let l:palette.fingerprint = sha256(l:wal_text)
return l:palette
endfunction
let s:km_wal_terminal_opacity = 0.9
function! KmWalHexToRgb(color) abort
let l:color = substitute(a:color, '^#', '', '')
if strlen(l:color) != 6
return [0, 0, 0]
endif
return [
\ str2nr(l:color[0:1], 16),
\ str2nr(l:color[2:3], 16),
\ str2nr(l:color[4:5], 16),
\ ]
endfunction
function! KmWalBlend(color_a, color_b, weight) abort
let l:weight = a:weight + 0.0
if l:weight < 0.0
let l:weight = 0.0
elseif l:weight > 1.0
let l:weight = 1.0
endif
let l:rgb_a = KmWalHexToRgb(a:color_a)
let l:rgb_b = KmWalHexToRgb(a:color_b)
let l:blended = []
for l:index in range(0, 2)
call add(l:blended, float2nr(round(l:rgb_a[l:index] * (1.0 - l:weight) + l:rgb_b[l:index] * l:weight)))
endfor
return printf('#%02X%02X%02X', l:blended[0], l:blended[1], l:blended[2])
endfunction
function! KmWalRelativeLuminance(color) abort
let l:rgb = KmWalHexToRgb(a:color)
let l:channels = []
for l:channel in l:rgb
let l:normalized = l:channel / 255.0
if l:normalized <= 0.03928
call add(l:channels, l:normalized / 12.92)
else
call add(l:channels, pow((l:normalized + 0.055) / 1.055, 2.4))
endif
endfor
return 0.2126 * l:channels[0] + 0.7152 * l:channels[1] + 0.0722 * l:channels[2]
endfunction
function! KmWalContrastRatio(color_a, color_b) abort
let l:luminance_a = KmWalRelativeLuminance(a:color_a)
let l:luminance_b = KmWalRelativeLuminance(a:color_b)
if l:luminance_a >= l:luminance_b
let l:lighter = l:luminance_a
let l:darker = l:luminance_b
else
let l:lighter = l:luminance_b
let l:darker = l:luminance_a
endif
return (l:lighter + 0.05) / (l:darker + 0.05)
endfunction
function! KmWalEffectiveBackground(bg) abort
return KmWalBlend(a:bg, '#FFFFFF', 1.0 - s:km_wal_terminal_opacity)
endfunction
function! KmWalCompareAccentCandidates(left, right) abort
if a:left.contrast > a:right.contrast
return -1
endif
if a:left.contrast < a:right.contrast
return 1
endif
if a:left.spread > a:right.spread
return -1
endif
if a:left.spread < a:right.spread
return 1
endif
if a:left.value < a:right.value
return -1
endif
if a:left.value > a:right.value
return 1
endif
return 0
endfunction
function! KmWalReadableAccentLanes(palette) abort
let l:effective_bg = KmWalEffectiveBackground(a:palette.bg)
let l:seen = {}
let l:candidates = []
for l:key in ['const', 'string', 'type', 'func', 'keyword', 'special']
let l:accent = toupper(get(a:palette, l:key, a:palette.fg))
if has_key(l:seen, l:accent)
continue
endif
let l:seen[l:accent] = 1
let l:rgb = KmWalHexToRgb(l:accent)
call add(l:candidates, {
\ 'value': l:accent,
\ 'contrast': KmWalContrastRatio(l:accent, l:effective_bg),
\ 'spread': max(l:rgb) - min(l:rgb),
\ })
endfor
if empty(l:candidates)
return [a:palette.fg, a:palette.fg, a:palette.fg]
endif
call sort(l:candidates, 'KmWalCompareAccentCandidates')
let l:lanes = []
for l:candidate in l:candidates
call add(l:lanes, l:candidate.value)
if len(l:lanes) == 3
break
endif
endfor
while len(l:lanes) < 3
call add(l:lanes, l:lanes[-1])
endwhile
return l:lanes
endfunction
function! KmAirlinePathVariants(full_path) abort
if empty(a:full_path)
return ['[No Name]']
endif
let l:path = a:full_path
if empty(l:path)
return ['[No Name]']
endif
if stridx(l:path, '~/') == 0
let l:prefix = '~/'
let l:segments = split(l:path[2:], '/')
elseif l:path ==# '~'
return ['~']
elseif stridx(l:path, '/') == 0
let l:prefix = '/'
let l:segments = split(l:path[1:], '/')
else
let l:prefix = ''
let l:segments = split(l:path, '/')
endif
if empty(l:segments)
return [l:path]
endif
let l:variants = [l:path]
if len(l:segments) > 2
let l:short_segments = copy(l:segments)
for l:index in range(0, len(l:segments) - 3)
let l:short_segments[l:index] = strcharpart(l:short_segments[l:index], 0, 1)
endfor
call add(l:variants, l:prefix . join(l:short_segments, '/'))
endif
if len(l:segments) >= 2
call add(l:variants, join(l:segments[-2:], '/'))
endif
call add(l:variants, l:segments[-1])
let l:unique = []
for l:variant in l:variants
if index(l:unique, l:variant) < 0
call add(l:unique, l:variant)
endif
endfor
return l:unique
endfunction
function! KmAirlinePath() abort
let l:full_path = expand('%:p:~')
if empty(l:full_path)
return '[No Name]'
endif
if get(g:, 'km_airline_path_style', 'context') !=# 'context'
return substitute(l:full_path, '^'. escape($HOME, '\') , '~', '')
endif
let l:variants = KmAirlinePathVariants(l:full_path)
let l:width = min([max([1, winwidth(0)]), max([1, &columns])])
if l:width >= 72 || len(l:variants) == 1
return l:variants[0]
endif
if l:width >= 56 && len(l:variants) >= 2
return l:variants[1]
endif
if l:width >= 32 && len(l:variants) >= 3
return l:variants[2]
endif
return l:variants[-1]
endfunction
function! KmAirlineFileFlags() abort
if !get(g:, 'km_airline_show_file_flags', 1)
return ''
endif
let l:flags = []
if &modified
call add(l:flags, '+')
endif
if &readonly
call add(l:flags, 'RO')
endif
if &buftype ==# 'help'
call add(l:flags, 'H')
endif
if &previewwindow
call add(l:flags, 'PV')
endif
return join(l:flags, ' ')
endfunction
function! KmAirlineCursorInfo() abort
if !get(g:, 'km_airline_show_cursor_info', 1)
return ''
endif
return printf('%d:%d %d%%', line('.'), col('.'), float2nr((line('.') * 100.0) / max([1, line('$')])))
endfunction
function! ApplyWalAirlineTheme() abort
if !exists('g:loaded_airline')
return
endif
let g:airline_theme = 'kmwal'
unlet! g:airline#themes#kmwal#palette
if exists('*airline#themes#kmwal#refresh')
call airline#themes#kmwal#refresh()
endif
if exists('*airline#switch_theme')
call airline#switch_theme('kmwal')
endif
if exists(':AirlineRefresh') == 2
silent! AirlineRefresh
endif
redrawstatus
endfunction
function! ApplyWalTheme() abort
if !exists('g:colors_name') || g:colors_name !=# 'wal'
return
endif
let l:palette = LoadWalPalette()
if empty(l:palette)
let g:km_wal_last_fingerprint = ''
highlight Normal ctermbg=0 ctermfg=7
highlight NormalNC ctermbg=0 ctermfg=7
highlight EndOfBuffer ctermbg=0 ctermfg=0
highlight NonText ctermbg=0 ctermfg=0
highlight LineNr ctermbg=0 ctermfg=8
highlight CursorLineNr ctermbg=0 ctermfg=8
highlight FoldColumn ctermbg=0 ctermfg=7
highlight SignColumn ctermbg=0 ctermfg=4
highlight Folded ctermbg=0 ctermfg=8
highlight Comment ctermbg=0 ctermfg=8
highlight Constant ctermbg=0 ctermfg=1
highlight Number ctermbg=0 ctermfg=1
highlight Boolean ctermbg=0 ctermfg=1
highlight String ctermbg=0 ctermfg=2
highlight Character ctermbg=0 ctermfg=2
highlight Type ctermbg=0 ctermfg=3
highlight StorageClass ctermbg=0 ctermfg=3
highlight Structure ctermbg=0 ctermfg=3
highlight Typedef ctermbg=0 ctermfg=3
highlight Identifier ctermbg=0 ctermfg=4
highlight Function ctermbg=0 ctermfg=4
highlight Statement ctermbg=0 ctermfg=5
highlight Keyword ctermbg=0 ctermfg=5
highlight Conditional ctermbg=0 ctermfg=5
highlight Repeat ctermbg=0 ctermfg=5
highlight Label ctermbg=0 ctermfg=5
highlight Operator ctermbg=0 ctermfg=5
highlight PreProc ctermbg=0 ctermfg=6
highlight Include ctermbg=0 ctermfg=6
highlight Macro ctermbg=0 ctermfg=6
highlight PreCondit ctermbg=0 ctermfg=6
highlight Special ctermbg=0 ctermfg=6
highlight SpecialChar ctermbg=0 ctermfg=6
highlight Delimiter ctermbg=0 ctermfg=6
highlight Tag ctermbg=0 ctermfg=6
else
let g:km_wal_last_mtime = l:palette.mtime
let g:km_wal_last_fingerprint = l:palette.fingerprint
let l:accent_lanes = KmWalReadableAccentLanes(l:palette)
let l:palette.func_lane = l:accent_lanes[0]
let l:palette.keyword_lane = l:accent_lanes[1]
let l:palette.special_lane = l:accent_lanes[2]
let l:palette.sign = l:palette.func_lane
execute 'highlight Normal ctermbg=0 ctermfg=7 guibg=' . l:palette.bg . ' guifg=' . l:palette.fg
execute 'highlight NormalNC ctermbg=0 ctermfg=7 guibg=' . l:palette.bg . ' guifg=' . l:palette.fg
execute 'highlight EndOfBuffer ctermbg=0 ctermfg=0 guibg=' . l:palette.bg . ' guifg=' . l:palette.bg
execute 'highlight NonText ctermbg=0 ctermfg=0 guibg=' . l:palette.bg . ' guifg=' . l:palette.bg
execute 'highlight LineNr ctermbg=0 ctermfg=8 guibg=' . l:palette.bg . ' guifg=' . l:palette.line
execute 'highlight CursorLineNr ctermbg=0 ctermfg=8 guibg=' . l:palette.bg . ' guifg=' . l:palette.line
execute 'highlight FoldColumn ctermbg=0 ctermfg=7 guibg=' . l:palette.bg . ' guifg=' . l:palette.fg
execute 'highlight SignColumn ctermbg=0 ctermfg=4 guibg=' . l:palette.bg . ' guifg=' . l:palette.sign
execute 'highlight Folded ctermbg=0 ctermfg=8 guibg=' . l:palette.bg . ' guifg=' . l:palette.line
execute 'highlight Comment ctermbg=0 ctermfg=8 guibg=' . l:palette.bg . ' guifg=' . l:palette.line
execute 'highlight Constant ctermbg=0 ctermfg=1 guibg=' . l:palette.bg . ' guifg=' . l:palette.const
execute 'highlight Number ctermbg=0 ctermfg=1 guibg=' . l:palette.bg . ' guifg=' . l:palette.const
execute 'highlight Boolean ctermbg=0 ctermfg=1 guibg=' . l:palette.bg . ' guifg=' . l:palette.const
execute 'highlight String ctermbg=0 ctermfg=2 guibg=' . l:palette.bg . ' guifg=' . l:palette.string
execute 'highlight Character ctermbg=0 ctermfg=2 guibg=' . l:palette.bg . ' guifg=' . l:palette.string
execute 'highlight Type ctermbg=0 ctermfg=3 guibg=' . l:palette.bg . ' guifg=' . l:palette.type
execute 'highlight StorageClass ctermbg=0 ctermfg=3 guibg=' . l:palette.bg . ' guifg=' . l:palette.type
execute 'highlight Structure ctermbg=0 ctermfg=3 guibg=' . l:palette.bg . ' guifg=' . l:palette.type
execute 'highlight Typedef ctermbg=0 ctermfg=3 guibg=' . l:palette.bg . ' guifg=' . l:palette.type
execute 'highlight Identifier ctermbg=0 ctermfg=4 guibg=' . l:palette.bg . ' guifg=' . l:palette.func_lane
execute 'highlight Function ctermbg=0 ctermfg=4 guibg=' . l:palette.bg . ' guifg=' . l:palette.func_lane
execute 'highlight Statement ctermbg=0 ctermfg=5 guibg=' . l:palette.bg . ' guifg=' . l:palette.keyword_lane
execute 'highlight Keyword ctermbg=0 ctermfg=5 guibg=' . l:palette.bg . ' guifg=' . l:palette.keyword_lane
execute 'highlight Conditional ctermbg=0 ctermfg=5 guibg=' . l:palette.bg . ' guifg=' . l:palette.keyword_lane
execute 'highlight Repeat ctermbg=0 ctermfg=5 guibg=' . l:palette.bg . ' guifg=' . l:palette.keyword_lane
execute 'highlight Label ctermbg=0 ctermfg=5 guibg=' . l:palette.bg . ' guifg=' . l:palette.keyword_lane
execute 'highlight Operator ctermbg=0 ctermfg=5 guibg=' . l:palette.bg . ' guifg=' . l:palette.keyword_lane
execute 'highlight PreProc ctermbg=0 ctermfg=6 guibg=' . l:palette.bg . ' guifg=' . l:palette.special_lane
execute 'highlight Include ctermbg=0 ctermfg=6 guibg=' . l:palette.bg . ' guifg=' . l:palette.special_lane
execute 'highlight Macro ctermbg=0 ctermfg=6 guibg=' . l:palette.bg . ' guifg=' . l:palette.special_lane
execute 'highlight PreCondit ctermbg=0 ctermfg=6 guibg=' . l:palette.bg . ' guifg=' . l:palette.special_lane
execute 'highlight Special ctermbg=0 ctermfg=6 guibg=' . l:palette.bg . ' guifg=' . l:palette.special_lane
execute 'highlight SpecialChar ctermbg=0 ctermfg=6 guibg=' . l:palette.bg . ' guifg=' . l:palette.special_lane
execute 'highlight Delimiter ctermbg=0 ctermfg=6 guibg=' . l:palette.bg . ' guifg=' . l:palette.special_lane
execute 'highlight Tag ctermbg=0 ctermfg=6 guibg=' . l:palette.bg . ' guifg=' . l:palette.special_lane
endif
highlight! link pythonBuiltin Identifier
highlight! link pythonBuiltinObj Identifier
highlight! link pythonBuiltinFunc Function
highlight! link pythonFunction Function
highlight! link pythonDecorator PreProc
highlight! link pythonInclude Include
highlight! link pythonImport Include
highlight! link pythonRun PreProc
highlight! link pythonStatement Statement
highlight! link pythonConditional Conditional
highlight! link pythonRepeat Repeat
highlight! link pythonException Statement
highlight! link pythonExceptions Statement
highlight! link pythonOperator Operator
call ApplyWalAirlineTheme()
endfunction
function! RefreshWalThemeIfChanged() abort
if !exists('g:colors_name') || g:colors_name !=# 'wal'
return
endif
if exists('g:km_wal_refreshing') && g:km_wal_refreshing
return
endif
let l:wal_colors_path = expand('~/.cache/wal/colors-wal.vim')
if !filereadable(l:wal_colors_path)
return
endif
let l:palette = LoadWalPalette()
if empty(l:palette)
return
endif
if exists('g:km_wal_last_fingerprint') && g:km_wal_last_fingerprint ==# l:palette.fingerprint
return
endif
let g:km_wal_refreshing = 1
try
silent! colorscheme wal
call ApplyWalTheme()
call ApplyWalAirlineTheme()
finally
let g:km_wal_refreshing = 0
endtry
endfunction
function! StartWalThemeWatcher() abort
if !exists('*timer_start')
return
endif
if exists('g:km_wal_theme_timer')
call timer_stop(g:km_wal_theme_timer)
endif
let g:km_wal_theme_timer = timer_start(1000, {-> RefreshWalThemeIfChanged()}, {'repeat': -1})
endfunction
augroup km_wal_background
autocmd!
autocmd ColorScheme wal call ApplyWalTheme()
autocmd CursorHold,CursorHoldI,FocusGained,VimResume * call RefreshWalThemeIfChanged()
autocmd VimEnter * call StartWalThemeWatcher()
augroup END
{{ if .gui }}
" autocmd vimenter * ++nested colorscheme gruvbox
" colorscheme nightfly
colorscheme wal
{{ else }}
" colorscheme gotham256
colorscheme wal
{{ end }}
call ApplyWalTheme()
call ApplyWalAirlineTheme()
call StartWalThemeWatcher()
" normal mappings [[[ "
function! JumpScrollIndent() abort
if getline('.') =~# '\S'
return indent('.')
endif
let l:fallback_line = prevnonblank(line('.'))
if l:fallback_line > 0
return indent(l:fallback_line)
endif
let l:fallback_line = nextnonblank(line('.'))
if l:fallback_line > 0
return indent(l:fallback_line)
endif
return 0
endfunction
function! JumpToNextIndentedChild() abort
let l:base_indent = indent('.')
for l:line_number in range(line('.') + 1, line('$'))
if getline(l:line_number) =~# '\S' && indent(l:line_number) > l:base_indent
call cursor(l:line_number, 1)
normal! zt
return v:true
endif
endfor
return v:false
endfunction
function! JumpToNextParagraphStart() abort
if getline('.') =~# ':\s*\($\|#\)'
if JumpToNextIndentedChild()
return
endif
endif
let l:max_indent = JumpScrollIndent()
for l:line_number in range(line('.') + 1, line('$'))
if getline(l:line_number) =~# '\S' && indent(l:line_number) <= l:max_indent
call cursor(l:line_number, 1)
normal! zt
return
endif
endfor
endfunction
function! JumpToPrevParagraphStart() abort
let l:max_indent = JumpScrollIndent()
for l:line_number in range(line('.') - 1, 1, -1)
if getline(l:line_number) =~# '\S' && indent(l:line_number) <= l:max_indent
call cursor(l:line_number, 1)
normal! zt
return
endif
endfor
if line('.') > 1
call cursor(1, 1)
normal! zt
endif
endfunction
nnoremap <ScrollWheelUp> :call JumpToPrevParagraphStart()<CR>
nnoremap <ScrollWheelDown> :call JumpToNextParagraphStart()<CR>
nnoremap Y yy
" visual select across lines by default "
nnoremap v <C-V>
" last macro "
nnoremap Q @@
" toggle fold "
nnoremap , za
" jump to horizontal position for mark "
nnoremap ' `
" indenting
nnoremap > >>
nnoremap < <<
inoremap << <Esc><<A
" ]]] normal mappings "
" leader mappings [[[ "
let mapleader="\<Space>"
" find alias
nnoremap <leader>a /^ <Left>
nnoremap <leader>ac :.s/\(\w\w\)/\u\1\U\2/g<CR>
" replace until end of line
nnoremap <leader>c c$
" delete until end of line
nnoremap <leader>d d$
" delete entire buffer
nnoremap <leader>dg ggdG
" delete entire line
nnoremap <leader>dl 0d$
" delete lines matching pattern
" nnoremap <leader>dls :g//d<left><left>
nnoremap <leader>dls q:ig//d<left><left>
" show docs for cur word
if has('nvim')
nnoremap <leader>do :KMHover<CR>
endif
" delete line into system clipboard
nnoremap <leader>D "+dd
" delete entire buffer into system clipboard
nnoremap <leader>DA "+ggdG
" find copied text
nnoremap <leader>f q/p<CR>
" find merge conflicts
nnoremap <leader>fc /[<>=\|]\{7\}<CR>
" reload folds
nnoremap <leader>fmi :set foldmethod=indent<CR> zM
nnoremap <leader>fmm :set foldmethod=marker<CR> zM
" code action
if has('nvim')
nnoremap <leader>fi :KMCodeAction<CR>
endif
" check filetype
nnoremap <leader>ft :se ft?<CR>
" check todo's
nnoremap <leader>ftd /TODO<CR>
" go to definition
if has('nvim')
nnoremap <leader>g :KMDefinitionSplit<CR>
endif
" nnoremap <leader>gb <C-O>
nnoremap <leader>gb :Git blame<CR>
" vimdiff split
nnoremap <leader>gd :Gvdiff
nnoremap <leader>gdh :Gvdiff HEAD^
nnoremap <leader>gdm :Gvdiff master<CR>
nnoremap <leader>gdo :Gvdiff orig/master<CR>
" toggle search highlighting
nnoremap <leader>h :set hlsearch! hlsearch?<CR>
" help
nnoremap <leader>he :vert help
nnoremap <leader>ht :set tabstop=2 shiftwidth=2 expandtab<CR>
nnoremap <leader>vhe :vert help
" don't add space when joining lines "
" nnoremap <leader>j gJ
" jump forward
nnoremap <leader>j <C-I>
" join all paragraphs into single line "
nnoremap <leader>jl :set tw=9999999<CR>gggqG
" jump back
nnoremap <leader>k <C-O>
" format current line
nnoremap <leader>l Vgq
" format this and next line
nnoremap <leader>ll Vjgq
" move cursor to middle of line
" nnoremap <leader>m :call cursor(0, len(getline('.'))/2)<CR>
nnoremap <leader>m :vert Man
" apply normal command to selection
vnoremap <leader>n q:anorm
" turn off autoformat"
" nnoremap <leader>na :set spell spelllang=en_us formatoptions=cjMqtvw<CR>
nnoremap <leader>nt :NERDTree<CR>
" check if in neovim
nnoremap <leader>nv :echo has('nvim')<CR>
" don't wrap lines
nnoremap <leader>nw :set nowrap<CR>
" recursively open fold
nnoremap <leader>o zO
" paste from?
" nnoremap <leader>p "*p
" format paragraph
nnoremap <leader>p gqip
" Plug commands
nnoremap <leader>pli :PlugInstall<CR>
nnoremap <leader>plc :PlugClean<CR>
nnoremap <leader>plu :PlugUpdate<CR>
" don't break lines
nnoremap <leader>py :set tw=0<CR>
" replace in next x lines
" nnoremap <leader>r q:i.,.+s///g<ESC>Fsi
" replace in line
nnoremap <leader>r q:i.s///g<left><left><left>
" replace in visual selection
vnoremap <leader>r q:is///g<ESC>3ha
" replace in entire file
" nnoremap <leader>R q:i%s///g<ESC>2F/i
nnoremap <leader>ra q:i%s///g<ESC>2F/i
" remove italics tags