-
Notifications
You must be signed in to change notification settings - Fork 105
/
vimrc
1947 lines (1548 loc) · 59.6 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
" @wookayin's vimrc file
" https://dotfiles.wook.kr/vim/vimrc
"
" https://github.com/wookayin/dotfiles
scriptencoding utf-8
"""""""""""""""""""""""""""""""""""""""""
" 0. Load Plugin {{{
"""""""""""""""""""""""""""""""""""""""""
" All the vim plugins, powered by 'vim-plug', are
" listed up in the separate file 'plugins.vim'.
" It is for making this vimrc could also work out-of-box
" even if not managed by dotfiles.
if filereadable(expand('~/.vim/plugins.vim'))
source \~/.vim/plugins.vim
else
let g:plugs = {}
endif
" Automatically install missing plugins on startup
autocmd VimEnter *
\ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | q
\| endif
" }}}
"""""""""""""""""""""""""""""""""""""""""
" 1. General Settings {{{
"""""""""""""""""""""""""""""""""""""""""
filetype plugin on
filetype indent on
syntax on
set nocompatible
if filereadable('/bin/zsh')
set shell=/bin/zsh
endif
" use path '~/.vim' even on non-unix machine
set runtimepath+=~/.vim
" add ~/.local/bin to $PATH
let $PATH .= ':' . expand('~/.local/bin')
" load plugins with pathogen
try
runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
catch
endtry
" basic displays
set number " show line numbers
set ruler
" input settings
set backspace=indent,eol,start " allow backspaces over everything
set autoindent
set smartindent
set pastetoggle=<F8>
set nowrap
set textwidth=0 " disable automatic line breaking
set cursorline
" tab settings
set tabstop=4
set shiftwidth=4
set softtabstop=4
" tab navigation
set showtabline=2 " always show tab pannel
set scrolloff=3
" search
set ignorecase " case-insensitive by default
set smartcase " case-sensitive if keyword contains both uppercase and lowercase
set incsearch
set hlsearch
if has('nvim')
" live preview of substitute command, with a split window
" @seealso http://vimcasts.org/episodes/neovim-eyecandy/
set inccommand=split
endif
" When jumping to line, folds on the line should be opened (:help 'foldopen')
set foldopen+=jump
" use spaces for tabbing, by default
set expandtab
" listchars for whitespaces
set list
set listchars=tab:»\ ,trail:·,extends:>,precedes:<
augroup listchars_filetype
autocmd!
autocmd FileType GV setlocal listchars-=trail:·
augroup END
" wildmenu settings
set wildmenu
try
" neovim 0.4.0+: popupmenu completion in the cmdline mode
set wildoptions+=pum
set wildmode=longest:full,full
" make <up>, <down>, <tab>, <shift-tab> work well with popupmenu in cmdline
cnoremap <expr> <up> pumvisible() ? "<C-p>" : "<up>"
cnoremap <expr> <down> pumvisible() ? "<C-n>" : "<down>"
catch
" old wildmenu heavior (vanilla vim)
set wildmode=list,longest:full
endtry
set wildignore=*.swp,*.swo,*.class
" status line
set laststatus=2 " show anytime
set noshowmode " don't display mode, e.g. '-- INSERT --'
set showcmd
" native customized statusline, if airline is not available
" (this setting will be replaced afterwards by airline)
set statusline=%1*%{winnr()}\ %*%<\ %f\ %h%m%r%=%l,%c%V\ (%P)
" mouse behaviour
if has('mouse')
set mouse=nvc
endif
if ! has('nvim')
" vim only (not in neovim)
set ttymouse=xterm2
endif
" encoding and line ending settings
if !has('nvim')
set encoding=utf-8
endif
set fileencodings=utf-8,cp949,latin1
set fileformats=unix,dos
" split and autocomplete settings
set splitbelow " preview window at bottom
set completeopt=menuone,preview,longest " show preview and pop-up menu
" no fucking swap and backup files
set noswapfile
set nobackup
" miscellanious
set visualbell
set history=1000
set undolevels=1000
set lazyredraw " no redrawing during macro execution
" Make gitgutter signs, etc. be more responsive (default is 4000ms)
set updatetime=200
set matchpairs+=<:>
" when launching files via quickfix, FZF, or something else,
" first switch to existing tab (if any) that contains the target buffer,
" or open a new buffer by splitting window in the current tab otherwise.
set switchbuf+=usetab,split
" diff: ignore whitespaces
set diffopt+=iwhite
" jump to the last position when reopening a file
if has('autocmd')
let s:last_position_disable_filetypes = ['gitcommit']
au BufReadPost * if index(s:last_position_disable_filetypes, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"zz" | endif
endif
" use strong encryption
if ! has('nvim')
if v:version >= 800 || v:version == 704 && has('patch399')
set cryptmethod=blowfish2 " Requires >= 7.4.399
else
set cryptmethod=blowfish
endif
endif
" When opening http urls using netrw, follow 302 redirects
let g:netrw_http_cmd = 'curl -L -o'
" terminal mode (neovim)
if has('nvim')
au TermOpen * setlocal nonumber norelativenumber
endif
" Use nvr as git editor (inside neovim terminal)
if has('nvim') && executable('nvr')
let $GIT_EDITOR = 'nvr -cc split --remote-wait'
autocmd FileType gitcommit set bufhidden=delete
endif
" For debugging
function! ToggleVerbose()
if !&verbose
set verbosefile=~/.vim/verbose.log
set verbose=15
else
set verbose=0
set verbosefile=
endif
endfunction
" }}}
"""""""""""""""""""""""""""""""""""""""""
" 2. Key and Functional Mappings {{{
"""""""""""""""""""""""""""""""""""""""""
" the leader key
" (NOTE) leader key is mapped to vim-which-key, see sections below
let mapleader=',' " comma is the <Leader> key.
let maplocalleader=',' " comma : <LocalLeader>
inoremap <silent> <C-k> <ESC>:update<CR>
" navigation key mapping
map <silent> k gk
map <silent> j gj
sunmap k
sunmap j
nmap <up> gk
nmap <down> gj
inoremap <up> <c-\><c-o>gk
inoremap <down> <c-\><c-o>gj
noremap <C-F> <C-D>
noremap <C-B> <C-U>
" Ignore errornous input in Mac OS X
imap <D-space> <Nop>
" <Ctrl-Space> invokes <C-X><C-O> (omni-completion)
inoremap <C-Space> <C-x><C-o>
inoremap <C-@> <C-x><C-o>
" window navigation
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
" window resize (simply)
nnoremap - <C-W>-
nnoremap + <C-W>+
nnoremap < <C-w><
nnoremap > <C-w>>
" zoom and unzoom (like tmux) -- by 'vim-maximizer'
nnoremap <C-w>z :MaximizerToggle<CR>
let g:maximizer_set_default_mapping = 0 " do not map <F3>
" well...?
inoremap <C-C> <ESC>
" in terminal mode (neovim)
if has('nvim')
" <C-\><C-n> is the key sequence for escaping form terminal mode
" double <ESC> and double <C-\> also goes for escaping from terminal,
" whereas single <ESC> would be directly passed inside the terminal.
tnoremap <silent> <C-[><C-[> <C-\><C-n>
tnoremap <silent> <C-\><C-\> <C-\><C-n>
" Automatically enter insert mode when entering neovim terminal buffer
autocmd BufWinEnter,WinEnter term://* startinsert
autocmd TermOpen * startinsert
" terminal in a new tab or vsplit buffer
command! -nargs=* -complete=shellcmd Term :tabnew | :term <args>
command! -nargs=* -complete=shellcmd STerm :split | :term <args>
command! -nargs=* -complete=shellcmd VTerm :split | :term <args>
command! -nargs=* -complete=shellcmd TermSplit :split | :term <args>
command! -nargs=* -complete=shellcmd TermVSplit :vsplit | :term <args>
" Mapping for <c-hjkl> in terminal mode
" <c-h> might not work: see https://github.com/neovim/neovim/issues/2048
tmap <silent> <C-h> <C-\><C-n>:wincmd h<CR>
tmap <silent> <C-j> <C-\><C-n>:wincmd j<CR>
tmap <silent> <C-k> <C-\><C-n>:wincmd k<CR>
"tmap <C-l> <C-\><C-n><C-l>
" TODO: <c-l> is for clear screen...?
endif
if has('nvim')
" workaround for <c-h> mapping bug in neovim
" @see https://github.com/neovim/neovim/issues/2048
nmap <BS> <C-W>h
" ignore erroneous key input on scrolling, <ffffffff>
tnoremap <ScrollWheelLeft> <nop>
endif
" Buffer navigations
nnoremap [b :bprevious<CR>
nnoremap ]b :bnext<CR>
if has('nvim')
nnoremap <silent> [b <C-\><C-n>:bprevious<CR>
nnoremap <silent> ]b <C-\><C-n>:bnext<CR>
endif
" Tab navigations
nnoremap <silent> [t :tabprevious<CR>
nnoremap <silent> ]t :tabnext<CR>
if has('nvim')
tnoremap <silent> [t <C-\><C-n>:tabprevious<CR>
tnoremap <silent> ]t <C-\><C-n>:tabnext<CR>
endif
nnoremap <C-t> :tabnew<CR>
nnoremap <silent> <C-S-tab> :tabprevious<CR>
nnoremap <silent> <C-tab> :tabnext<CR>
if has('nvim')
tnoremap <silent> <C-S-tab> <C-\><C-n>:tabprevious<CR>
tnoremap <silent> <C-tab> <C-\><C-n>:tabnext<CR>
endif
" Handy tab navigations: <Alt-num>
nnoremap 1 1gt
nnoremap 2 2gt
nnoremap 3 3gt
nnoremap 4 4gt
nnoremap 5 5gt
nnoremap 6 6gt
nnoremap 7 7gt
nnoremap 8 8gt
nnoremap 9 9gt
" do not exit from visual mode when shifting
" (gv : select the preivous area)
vnoremap < <gv
vnoremap > >gv
" Locations
nnoremap [l :lprevious<CR>
nnoremap ]l :lnext<CR>
" -----------------------
" [F5] Make and Build {{{
" -----------------------
" use Make (vim-dispatch) or Neomake (neomake)
if has_key(g:plugs, 'neomake')
" neomake; always use the bang version so that :copen can sync
command! -nargs=0 -bang TheMake cexpr [] | Neomake!
command! -nargs=0 TheCopen copen
else
" vim-dispatch
command! -nargs=0 -bang TheMake Make<bang>
command! -nargs=0 TheCopen Copen
endif
" smartly dispatch according to filetype
function! s:run_make(bang)
let l:silent_filetypes = ['tex', 'pandoc', 'lilypond']
" (1) bang given, force background
if a:bang ==# '!' | TheMake!
" (2) for specified filetypes, use background
elseif index(l:silent_filetypes, &filetype) >= 0 | TheMake!
" (3) otherwise, make with foreground shown
else | TheMake
end
endfunction
command! -nargs=0 -bang RunMake call s:run_make("<bang>")
" A handy way to set makeprg.
command! -nargs=1 Makeprg let &g:makeprg="<args>" | echo "makeprg = <args>"
if has_key(g:plugs, 'vim-dispatch')
" use vim-dispatch if exists
" <F5>: run make, asynchronously or split windows (dispatch)
map <F5> <ESC>:w<CR>:RunMake<CR>
imap <F5> <ESC>:w<CR>:RunMake<CR>a
" <leader-F5>: run make with visible progress (split window in tmux)
map <leader><F5> <ESC>:w<CR>:RunMake!<CR>
else
" otherwise, fallback to default make
map <F5> <ESC>:w<CR>:make!<CR>
imap <F5> <ESC>:w<CR>:make!<CR>a
endif
" Alternative to <F5>
map <leader>m <F5>
" }}}
" <F6>: show/close quickfix window (scroll bottom)
function! QuickfixToggle()
let nr = winnr('$')
:TheCopen
let nr2 = winnr('$')
if nr == nr2 | cclose | endif
endfunction
map <silent> <F6> :call QuickfixToggle()<CR>
imap <silent> <F6> <ESC>:call QuickfixToggle()<CR>G:wincmd w<CR>a
nmap <silent> <C-Q> :call QuickfixToggle()<CR>
" <leader>L: show/close location list window
function! LocListToggle()
let nr = winnr('$')
:lopen
let nr2 = winnr('$')
if nr == nr2 | lclose | endif
endfunction
map <silent> <leader>L :call LocListToggle()<CR>
" [F4] Next Error [Shift+F4] Previous Error
map <F4> <ESC>:cn<CR>
map [26~ <ESC>:cp<CR>
map [1;2S <ESC>:cp<CR>
map [29~ <ESC>:cp<CR>
" [F2] save
imap <F2> <ESC>:w<CR>
map <F2> <ESC><ESC>:w<CR>
" save in the insert mode?
inoremap <C-S> <ESC>:update<CR>a
" Sudo Save (:Wsudo command)
command! Wsudo w !sudo tee % > /dev/null
" Useful leader key combinations {{{
" <leader><space> : turn off search highlight
nmap <silent> <leader><space> :noh<CR>
" Plugin ag.vim
" <leader>ag (or rg): Ag (search file contents)
nnoremap <leader>ag :Ag! -i ""<Left>
xnoremap <silent> <leader>ag y:Ag <C-R>"<CR>
if executable('rg')
" Use ripgrep instead :)
let g:ag_prg = 'rg --no-heading --vimgrep'
endif
" <leader>cd : switch to the directory of the current buffer
function! CD_to_file()
silent cd %:p:h
:pwd
" if NERDTree is open, chdir NERDTree as well
if exists('g:NERDTree') && g:NERDTree.IsOpen()
:NERDTreeCWD | wincmd w
endif
endfunction
nmap <silent> <leader>cd :<C-U>CD<CR>
command! -nargs=0 CD :call CD_to_file()
" <leader>R : screen sucks, redraw everything
function! Redraw()
:mode
call s:auto_termguicolors() " re-detect true colors
endfunction
nnoremap <silent> <leader>R :call Redraw()<CR>
" <leader>src : source ~/.vimrc
nnoremap <leader>src :source ~/.vimrc<CR>
" :Vimrc opens vim config files in a new tab
command! -nargs=0 Vimrc call s:open_vimrc_tab()
function! s:open_vimrc_tab()
tabnew ~/.vim/vimrc
botright vnew ~/.vim/plugins.vim
if filereadable(expand("~/.vim/plugins.local.vim"))
10sp ~/.vim/plugins.local.vim
endif
wincmd t " focus on the first buffer (~/.vimrc)
endfunction
" <leader>{y,x,p} : {yank,cut,paste} wrt the system clipboard
map <leader>y "*y
noremap <leader>x "*x
noremap <leader>p "*p
" <leader>w : save
nnoremap <leader>w :w!<CR>
" <leader>q : quit/close window
nnoremap <silent> <leader>q :q<CR>
" <leader>S : Strip trailing whitespaces
command! -nargs=0 Strip call StripTrailingWhitespaces()
nnoremap <leader>S :Strip<CR>
" <leader>df : diffthis
nnoremap <leader>df :diffthis<CR>
" Surround a word with quotes, single quotes, parens, brackets, braces, etc.
" requires and powered by the plugin surround.vim :-)
" (Note) for visual blocks, use S command from surround.vim
map <leader>s" ysiw"
map <leader>s' ysiw'
map <leader>s` ysiw`
map <leader>s* ysiw*l
map <leader>s_ ysiw_l
map <leader>s~ ysiw~l
map <leader>s$ ysiw$
map <leader>s( ysiw(
map <leader>s) ysiw)
map <leader>s[ ysiw[
map <leader>s] ysiw]
map <leader>s{ ysiw{
map <leader>s} ysiw}
" Zoom Tmux
noremap <silent> <leader>z :silent exec "!tmux resize-pane -Z"<CR>
" Prevent accidental <Ctrl-A> on Tmux
if !empty($TMUX)
nnoremap <C-a> <nop>
" To increase numbers, press <comma>, <c-a>, a ...?
nnoremap <leader><C-a> <C-a>
endif
" }}}
" }}}
"""""""""""""""""""""""""""""""""""""""""
" 3. More Functions and Commands {{{
"""""""""""""""""""""""""""""""""""""""""
" ----------------------------------------------------------------------------
" <Leader>?/! : Google it / Feeling lucky
" (code brought from @junegunn/dotfiles)
" ----------------------------------------------------------------------------
function! s:goog(pat, lucky)
let q = '"'.substitute(a:pat, '["\n]', ' ', 'g').'"'
let q = substitute(q, '[[:punct:] ]',
\ '\=printf("%%%02X", char2nr(submatch(0)))', 'g')
call system(printf('open "https://www.google.com/search?%sq=%s"',
\ a:lucky ? 'btnI&' : '', q))
endfunction
nnoremap <leader>? :call <SID>goog(expand("<cword>"), 0)<cr>
nnoremap <leader>! :call <SID>goog(expand("<cword>"), 1)<cr>
xnoremap <leader>? "gy:call <SID>goog(@g, 0)<cr>gv
xnoremap <leader>! "gy:call <SID>goog(@g, 1)<cr>gv
" }}}
"""""""""""""""""""""""""""""""""""""""""
" 4. Appearance (e.g. Colors, Syntax) {{{
"""""""""""""""""""""""""""""""""""""""""
" color settings
" @see http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
set t_Co=256 " use 256 color
set background=dark
if &term =~ '256color'
" Disable Background Color Erase (BCE) so that color schemes
" work properly when Vim is used inside tmux and GNU screen.
set t_ut=
endif
" 24-bit true color: neovim 0.1.5+ / vim 7.4.1799+
" enable ONLY if TERM is set valid and it is NOT under mosh
function! IsMosh()
let output = system('is_mosh -v')
if v:shell_error
return 0
endif
return !empty(l:output)
endfunction
function! s:auto_termguicolors(...)
if !(has('termguicolors'))
return
endif
if (&term == 'xterm-256color' || &term == 'nvim') && !IsMosh()
set termguicolors
else
set notermguicolors
endif
endfunction
if has('termguicolors')
" by default, enable 24-bit color, but lazily disable if under mosh
set termguicolors
if exists('*timer_start')
call timer_start(0, function('s:auto_termguicolors'))
else
call s:auto_termguicolors()
endif
endif
" apply base theme
silent! colorscheme xoria256
" airline theme: status line and tab line
if has('termguicolors') && &termguicolors
let g:airline_theme = 'deus'
else
let g:airline_theme = 'bubblegum'
endif
" override more customized colors
highlight StatusLine ctermfg=LightGreen
highlight ColorColumn ctermbg=52 guibg=#5f0000
highlight LineNr ctermfg=248 ctermbg=233 guifg=#a8a8a8 guibg=#121212
highlight SignColumn ctermfg=248 ctermbg=233 guifg=#a8a8a8 guibg=#121212
" gitgutter sign column (see afa4f2dd)
" guibg=<X> and ctermbg=<Y> should match that of "SignColumn"
highlight GitGutterAdd guifg=#009900 guibg=#121212 ctermfg=2 ctermbg=233
highlight GitGutterChange guifg=#bbbb00 guibg=#121212 ctermfg=3 ctermbg=233
highlight GitGutterDelete guifg=#ff2222 guibg=#121212 ctermfg=1 ctermbg=233
" some primitive colors customized on top of xoria256
highlight Normal ctermfg=255 guifg=white
highlight Comment ctermfg=035 guifg=#38B04A
highlight Constant ctermfg=204 guifg=#ff5f87
highlight PreProc ctermfg=219 guifg=#ffafff
highlight SpecialKey ctermfg=242 guifg=#666666
highlight Folded ctermbg=60 guibg=#404056
" colors for gui/24bit mode {{
" DiffAdd - inserted lines (dark green)
highlight DiffAdd guibg=#103a05 guifg=NONE
" DiffDelete - deleted/filler lines (gray 246)
highlight DiffDelete guibg=#949494
" DiffChange - changed lines (dark red)
highlight DiffChange guibg=#471515 guifg=NONE
" DiffChange - changed 'text'(brighter red)
highlight DiffText guibg=#721b1b guifg=NONE
" }}
highlight SpellBad guifg=NONE ctermfg=NONE
" no underline, current cursor line
highlight CursorLine cterm=none
" show cursorline for active window only
augroup NrHighlight
autocmd!
autocmd BufEnter * setlocal cursorline
autocmd BufLeave * setlocal nocursorline
augroup END
" filetype detections
au BufRead,BufNewFile /etc/nginx/* if &ft == '' | setfiletype nginx | endif
au BufRead,BufNewFile *.prototxt if &ft == '' | setfiletype yaml | endif
au BufRead,BufNewFile *.ipynb if &ft == '' | setfiletype json | endif
autocmd FileType git setlocal foldlevel=1
autocmd FileType gitcommit setlocal cc=72 textwidth=72
" remove trailing whitespaces on save
fun! StripTrailingWhitespaces()
let l = line('.')
let c = col('.')
%s/\s\+$//e
call cursor(l, c)
endfun
autocmd FileType c,cpp,java,javascript,html,ruby,python,pandoc
\ autocmd BufWritePre <buffer> :call StripTrailingWhitespaces()
" highlight trailing whitespaces
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
augroup trailing_whitespaces
autocmd!
autocmd FileType GV,gitmessengerpopup highlight clear ExtraWhitespace
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
augroup END
" Unset paste when leaving insert mode
autocmd InsertLeave * silent! set nopaste
" better popup menu colors (instead of dark black)
highlight Pmenu ctermfg=black guifg=black ctermbg=yellow guibg=#ffec99
highlight PmenuSel ctermfg=red guifg=red ctermbg=white guibg=white gui=bold
" neovim 0.4.0+ : semi-transparent popup menu
if has('nvim') && has('termguicolors')
silent! set pumblend=20
endif
" neovim 0.4.0+ : Default background for floating windows (should be dark, not Pmenu)
if hlexists('NormalFloat')
highlight NormalFloat ctermbg=233 guibg=#121212
endif
" http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor
function! ShowSyntaxGroup()
echo 'hi<' . synIDattr(synID(line('.'),col('.'),1),'name') . '> trans<'
\ . synIDattr(synID(line('.'),col('.'),0),'name') . '> lo<'
\ . synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name') . '>'
endfunction
noremap <leader>syn :call ShowSyntaxGroup()<cr>
" }}}
"""""""""""""""""""""""""""""""""""""""""
" 5. GUI Options {{{
"""""""""""""""""""""""""""""""""""""""""
" gui settings
if has('gui_running')
if has('unix')
let s:uname = substitute(system('uname -s'), '\n', '', '')
endif
if has('gui_win32')
language mes en " use english messages (korean characters broken)
set langmenu=none " use english context menus (korean characters broken)
set guioptions-=T " exclude toolbar
set guioptions-=m " exclude menubar
" font setting for windows
set guifont=Consolas:h11:cANSI
set guifontwide=GulimChe:h12:cDEFAULT
elseif has('gui_gtk2')
" font setting for Ubuntu linux (GTK)
set guifont=Ubuntu\ Mono\ derivative\ Powerline\ 12
elseif has('unix') && s:uname ==? 'Darwin'
" font setting for Mac OS X (Darwin)
set guifont=Monaco\ for\ Powerline:h12
set guifontwide=Apple\ SD\ Gothic\ Neo\ UltraLight:h12
endif
endif
" }}}
"""""""""""""""""""""""""""""""""""""""""
" 6. Plugin Settings {{{
"""""""""""""""""""""""""""""""""""""""""
" ----------------------------------------------------------------
" vim-localvimrc {{{
" store and restore all decisions on whether to load lvimrc
let g:localvimrc_persistent = 2
" ---------------------------------------------------------------- }}}
" vim-polyglot {{{
" in favor of python-mode and vimtex ...
let g:polyglot_disabled = ['python', 'latex']
" ---------------------------------------------------------------- }}}
" vim-startify {{{
let g:startify_bookmarks = [
\ '~/.vim/vimrc',
\ '~/.vim/plugins.vim',
\ ]
let g:startify_skiplist = [
\ 'COMMIT_EDITMSG',
\ $VIMRUNTIME .'/doc',
\ 'plugged/.*/doc',
\ 'bundle/.*/doc',
\ ]
" ---------------------------------------------------------------- }}}
" vim-eunuch {{{
" remove all rm-like commands, which are too dangerous (even no confirm...)
if has_key(g:plugs, 'vim-eunuch')
autocmd VimEnter * call s:remove_eunuch_commands()
function! s:remove_eunuch_commands()
if exists('g:loaded_eunuch')
delcommand Remove | delcommand Delete | delcommand Unlink
endif
endfunction
endif
" ---------------------------------------------------------------- }}}
" vim-emoji {{{
" replace emoji in selected lines
" (snippet brought from @junegunn/dotfiles)
function! s:replace_emojis() range
for lnum in range(a:firstline, a:lastline)
let line = getline(lnum)
let subs = substitute(line,
\ ':\([^:]\+\):', '\=emoji#for(submatch(1), submatch(0))', 'g')
if line != subs
call setline(lnum, subs)
endif
endfor
redraw!
endfunction
command! -range EmojiReplace <line1>,<line2>call s:replace_emojis()
xnoremap <leader>emoji :Emoji<CR>
" :Emoji --- emoji search with fzf
" insert-completion <c-x><c-e> (fzf-complete-emoji)
command! -nargs=* Emoji call fzf#run(Fzf_emoji_opts(<q-args>))
imap <expr> <silent> <C-x><C-e> fzf#vim#complete(Fzf_emoji_opts(''))
function! Fzf_emoji_opts(query)
let opts = {}
let opts.source = map(sort(emoji#list()), 'printf("%-10s \t %s", emoji#for(v:val), v:val)')
let opts.options = ['--delimiter', '\t', '--nth', '-1', '--no-multi']
if !empty(a:query)
let opts.options += ['--query', a:query]
endif
let opts.reducer = { lines -> split(lines[0])[0] } " for insert-complete mode
let opts.sink = { line -> execute('normal! a' . split(line)[0]) } " for normal-command mode
return fzf#wrap(opts)
endfunction
" ---------------------------------------------------------------- }}}
" vim-asterisk (enhanced *) {{{
" Use z (stay) behavior as default
if has_key(g:plugs, 'vim-asterisk')
"map * <Plug>(asterisk-z*)
"map # <Plug>(asterisk-z#)
map g* <Plug>(asterisk-gz*)
map g# <Plug>(asterisk-gz#)
endif
" Keep cursor position across matches
let g:asterisk#keeppos = 1
" ---------------------------------------------------------------- }}}
" incsearch {{{
" incsearch.vim
if has_key(g:plugs, 'incsearch.vim')
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
endif
" incsearch-fuzzy.vim
map z/ <Plug>(incsearch-fuzzy-/)
map z? <Plug>(incsearch-fuzzy-?)
map zg/ <Plug>(incsearch-fuzzy-stay)
" ---------------------------------------------------------------- }}}
" vim-highlightedyank {{{
if has_key(g:plugs, 'vim-highlightedyank') && !exists('##TextYankPost')
map y <Plug>(highlightedyank)
endif
"hi HighlightedyankRegion cterm=reverse gui=reverse
let g:highlightedyank_highlight_duration = 1000
" ---------------------------------------------------------------- }}}
" vim-quickhl {{{
nmap <leader>* <Plug>(quickhl-manual-this)
xmap <leader>* <Plug>(quickhl-manual-this)
nmap <leader>8 <Plug>(quickhl-manual-reset)
xmap <leader>8 <Plug>(quickhl-manual-reset)
" ---------------------------------------------------------------- }}}
" vim-highlightedundo {{{
if has_key(g:plugs, 'vim-highlightedundo')
nmap u <Plug>(highlightedundo-undo)
nmap <C-r> <Plug>(highlightedundo-redo)
nmap U <Plug>(highlightedundo-Undo)
nmap g- <Plug>(highlightedundo-gminus)
nmap g+ <Plug>(highlightedundo-gplus)
let g:highlightedundo#highlight_duration_delete = 500
let g:highlightedundo#highlight_duration_add = 700
endif
" ---------------------------------------------------------------- }}}
" vim-which-key {{{
" which-key buffer will appear vertically on the right
let g:which_key_vertical = 1
" Make timeout delay to be 300ms (before popup appears), default is 1000ms
set timeoutlen=300
" Remap <leader> key to vim-which-key version.
" The following mapping assumes <leader> key is ',' (comma)
if has_key(g:plugs, 'vim-which-key')
nnoremap <silent> <leader> :<c-u>WhichKey ','<CR>
endif
" ---------------------------------------------------------------- }}}
" editorconfig {{{
let g:EditorConfig_core_mode = 'vim_core'
"let g:EditorConfig_core_mode = 'python_external'
"let g:EditorConfig_core_mode = 'external_command'
" ---------------------------------------------------------------- }}}
" Airline {{{
" Note: for airline theme, see the 'appearance' section
" use airline, with powerline-ish theme
let g:airline_powerline_fonts=1
" [section customization] (:h airline-sections) {{{
" -----------------------
" section y (ffenc): skip if utf-8[unix]
let g:airline#parts#ffenc#skip_expected_string = 'utf-8[unix]'
" section z: current position, but more concisely
let g:airline_section_z = 'L%3l:%v'
" }}}
" enable tabline feature
let g:airline#extensions#tabline#enabled = 1
" Display buffers (like tabs) in the tabline
" if there is only one tab
let g:airline#extensions#tabline#show_buffers = 1
" suppress mixed-indent warning for javadoc-like comments (/** */)
let g:airline#extensions#whitespace#mixed_indent_algo = 1
" ---------------------------------------------------------------- }}}
" Neomake {{{
" so that ':Neomake clean' invokes 'make clean'
let g:neomake_clean_maker = { 'exe': 'make', 'args': ['clean'] }
" General hook/callback on starting and finishing jobs {
function! s:OnNeomakeStart(context)
" what will we do?
endfunction
function! s:OnNeomakeFinished(context)
let l:context = g:neomake_hook_context
" If there is any failed job (non-zero exit code), notify it.
let l:failure_message = ''
for job in l:context['finished_jobs']
if l:job['exit_code'] != 0
let l:failure_message = printf('%s%s ', l:failure_message, l:job['as_string']())
endif
endfor
if ! empty(l:failure_message)
echom 'Job Finished, FAIL: ' . l:failure_message
copen | wincmd p " copen, but not move to the quickfix window
let b:neomake_auto_copen = 1
else
echom 'Job Finished, Success.'
if get(b:, 'neomake_auto_copen', 0) == 1
" if quickfix list is opened automatically by neomake callback,
" we should automatically close it upon the success of neomake job.
silent cclose
let b:neomake_auto_copen = 0
endif
endif
endfunction
augroup neomake_hooks_common
au!
autocmd User NeomakeJobInit call s:OnNeomakeStart(g:neomake_hook_context)
autocmd User NeomakeFinished call s:OnNeomakeFinished(g:neomake_hook_context)
augroup END
" }
" ---------------------------------------------------------------- }}}
" FZF {{{
" If floating window is not available, use 33%-bottom layout