-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.vimrc
1830 lines (1642 loc) · 56.9 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
"---------------------------------------------------------------------------
" .vimrc
"---------------------------------------------------------------------------
" Initialize:"{{{
"
augroup MyVimrcCmd
autocmd!
augroup END
let s:MSWindows = has('win95') + has('win16') + has('win32') + has('win64')
let s:Android = !s:MSWindows && executable('uname') ? system('uname -m')=~#'armv7l' : 0
if !exists('$DOTVIM')
if s:MSWindows
let $DOTVIM = expand($VIM . '/vimfiles')
else
let $DOTVIM = expand('~/.vim')
endif
endif
let $MYLOCALVIMRC = $DOTVIM.'/.local.vimrc'
nnoremap <silent> <Space>ev :<C-u>edit $MYVIMRC<CR>
nnoremap <silent> <Space>eg :<C-u>edit $MYGVIMRC<CR>
nnoremap <silent> <Space>el :<C-u>edit $MYLOCALVIMRC<CR>
nnoremap <silent> <Space>tv :<C-u>tabedit $MYVIMRC<CR>
nnoremap <silent> <Space>tg :<C-u>tabedit $MYGVIMRC<CR>
nnoremap <silent> <Space>tl :<C-u>tabedit $MYLOCALVIMRC<CR>
nnoremap <silent> <Space>rv :<C-u>source $MYVIMRC \| if has('gui_running') \| source $MYGVIMRC \| endif <CR>
nnoremap <silent> <Space>rg :<C-u>source $MYGVIMRC<CR>
nnoremap <silent> <Space>rl :<C-u>if 1 && filereadable($MYLOCALVIMRC) \| source $MYLOCALVIMRC \| endif <CR>
if s:MSWindows
" set shellslash
set visualbell t_vb=
endif
nnoremap <Space>o/ :<C-u>setlocal shellslash! shellslash?<CR>
set noautochdir
nnoremap <Space>oc :<C-u>setlocal autochdir! autochdir?<CR>
"---------------------------------------------------------------------------
" Encoding:"{{{
"
" based on encode.vim
" https://sites.google.com/site/fudist/Home/vim-nihongo-ban/vim-utf8
if !has('gui_macvim')
if !has('gui_running') && s:MSWindows
set termencoding=cp932
set encoding=cp932
elseif s:MSWindows
set termencoding=cp932
set encoding=utf-8
else
set encoding=utf-8
endif
"set default fileencodings
if &encoding == 'utf-8'
set fileencodings=ucs-bom,utf-8,default,latin1
elseif &encoding == 'cp932'
set fileencodings=ucs-bom
endif
" set fileencodings for character code automatic recognition
if &encoding !=# 'utf-8'
set encoding=japan
set fileencoding=japan
endif
if has('iconv')
let s:enc_euc = 'euc-jp'
let s:enc_jis = 'iso-2022-jp'
" check whether iconv supports eucJP-ms.
if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb"
let s:enc_euc = 'eucjp-ms'
let s:enc_jis = 'iso-2022-jp-3'
" check whether iconv supports JISX0213.
elseif iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb"
let s:enc_euc = 'euc-jisx0213'
let s:enc_jis = 'iso-2022-jp-3'
endif
" build fileencodings
if &encoding ==# 'utf-8'
let s:fileencodings_default = &fileencodings
let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
let &fileencodings = &fileencodings .','. s:fileencodings_default
unlet s:fileencodings_default
else
let &fileencodings = &fileencodings .','. s:enc_jis
set fileencodings+=utf-8,ucs-2le,ucs-2
if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$'
set fileencodings+=cp932
set fileencodings-=euc-jp
set fileencodings-=euc-jisx0213
set fileencodings-=eucjp-ms
let &encoding = s:enc_euc
let &fileencoding = s:enc_euc
else
let &fileencodings = &fileencodings .','. s:enc_euc
endif
endif
" give priority to utf-8
if &encoding == 'utf-8'
set fileencodings-=utf-8
let &fileencodings = substitute(&fileencodings, s:enc_jis, s:enc_jis.',utf-8','')
endif
" clean up constant
unlet s:enc_euc
unlet s:enc_jis
endif
" set fileformats automatic recognition
if s:MSWindows
set fileformats=dos,unix,mac
else
set fileformats=unix,mac,dos
endif
" to use the encoding to fileencoding when not included the Japanese
if has('autocmd')
function! AU_ReCheck_FENC()
if &fileencoding =~# 'iso-2022-jp' && search("[^\x01-\x7e]", 'n') == 0
let &fileencoding = &encoding
if s:MSWindows
let &fileencoding = 'cp932'
endif
endif
endfunction
autocmd MyVimrcCmd BufReadPost * call AU_ReCheck_FENC()
endif
" When internal encoding is not cp932 in Windows,
" and environment variable contains multi-byte character
command! -nargs=+ Let call Let__EnvVar__(<q-args>)
function! Let__EnvVar__(cmd)
let cmd = 'let ' . a:cmd
if s:MSWindows && has('iconv') && &enc != 'cp932'
let cmd = iconv(cmd, &enc, 'cp932')
endif
exec cmd
endfunction
endif
scriptencoding utf-8
"}}}
"---------------------------------------------------------------------------
" MacVim:"{{{
"
if has('gui_macvim')
set macmeta
let macvim_hig_shift_movement = 1
let macvim_skip_cmd_opt_movement = 1
if has('kaoriya') && has('vim_starting')
let $PATH = simplify($VIM . '/../../MacOS') . ':' . $PATH
set migemodict=$VIMRUNTIME/dict/migemo-dict
set migemo
let $SSH_ASKPASS = simplify($VIM . '/../../MacOS') . '/macvim-askpass'
set noimdisable
set imdisableactivate
endif
endif
"}}}
"}}}
"---------------------------------------------------------------------------
" Load Plugins:"{{{
"
let $PACKPATH = $DOTVIM . '/pack/Bundle'
if !exists('$GIT_PROTOCOL')
let $GIT_PROTOCOL = 'https'
endif
if s:Android
let $GITHUB_COM = $GIT_PROTOCOL.'://207.97.227.239/'
else
let $GITHUB_COM = $GIT_PROTOCOL.'://github.com/'
endif
" let $BITBUCKET_ORG = 'https://bitbucket.org/'
let s:plugins = {'start': [], 'opt': []}
call add(s:plugins.opt, $GITHUB_COM.'mattn/webapi-vim')
call add(s:plugins.opt, $GITHUB_COM.'vim-jp/vimdoc-ja')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-ref')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-ft-help_fold')
call add(s:plugins.opt, $GITHUB_COM.'tpope/vim-fugitive')
call add(s:plugins.opt, $GITHUB_COM.'gregsexton/gitv')
call add(s:plugins.opt, $GITHUB_COM.'mhinz/vim-signify')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-textobj-user')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-textobj-indent')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-textobj-syntax')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-textobj-line')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-textobj-fold')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-textobj-entire')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-textobj-between')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-textobj-comment')
call add(s:plugins.opt, $GITHUB_COM.'h1mesuke/textobj-wiw')
call add(s:plugins.opt, $GITHUB_COM.'vimtaku/vim-textobj-sigil')
call add(s:plugins.opt, $GITHUB_COM.'sgur/vim-textobj-parameter')
call add(s:plugins.opt, $GITHUB_COM.'terryma/vim-expand-region')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-operator-user')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-operator-replace')
call add(s:plugins.opt, $GITHUB_COM.'tyru/operator-camelize.vim')
call add(s:plugins.opt, $GITHUB_COM.'tyru/operator-reverse.vim')
call add(s:plugins.opt, $GITHUB_COM.'emonkak/vim-operator-sort')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-qfreplace')
if !s:Android
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-fontzoom')
endif
if !s:Android
call add(s:plugins.opt, $GITHUB_COM.'nathanaelkane/vim-indent-guides')
endif
call add(s:plugins.opt, $GITHUB_COM.'daisuzu/rainbowcyclone.vim')
call add(s:plugins.opt, $GITHUB_COM.'vim-scripts/matchparenpp')
call add(s:plugins.opt, $GITHUB_COM.'vim-scripts/matchit.zip')
call add(s:plugins.opt, $GITHUB_COM.'tpope/vim-surround')
call add(s:plugins.opt, $GITHUB_COM.'t9md/vim-textmanip')
call add(s:plugins.opt, $GITHUB_COM.'tomtom/tcomment_vim')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-niceblock')
call add(s:plugins.opt, $GITHUB_COM.'kana/vim-altr')
call add(s:plugins.opt, $GITHUB_COM.'vim-scripts/Unicode-RST-Tables')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-visualstar')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-quickrun')
call add(s:plugins.opt, $GITHUB_COM.'rhysd/vim-grammarous')
call add(s:plugins.opt, $GITHUB_COM.'Shougo/vimproc.vim')
if !s:Android
call add(s:plugins.opt, $GITHUB_COM.'Shougo/vinarise')
endif
if !s:Android
call add(s:plugins.opt, $GITHUB_COM.'s-yukikaze/vinarise-plugin-peanalysis')
endif
call add(s:plugins.opt, $GITHUB_COM.'daisuzu/tree.vim')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-prettyprint')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-editvar')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-showtime')
call add(s:plugins.opt, $GITHUB_COM.'tyru/open-browser.vim')
call add(s:plugins.opt, $GITHUB_COM.'yuratomo/w3m.vim')
if !s:Android
call add(s:plugins.opt, $GITHUB_COM.'sjl/gundo.vim')
endif
call add(s:plugins.opt, $GITHUB_COM.'vim-scripts/sudo.vim')
call add(s:plugins.opt, $GITHUB_COM.'vim-scripts/Align')
call add(s:plugins.opt, $GITHUB_COM.'h1mesuke/vim-alignta')
call add(s:plugins.opt, $GITHUB_COM.'thinca/vim-scall')
call add(s:plugins.opt, $GITHUB_COM.'mattn/sonictemplate-vim')
call add(s:plugins.opt, $GITHUB_COM.'LeafCage/vimhelpgenerator')
call add(s:plugins.opt, $GITHUB_COM.'t9md/vim-choosewin')
call add(s:plugins.opt, $GITHUB_COM.'alfredodeza/pytest.vim')
call add(s:plugins.opt, $GITHUB_COM.'klen/python-mode')
call add(s:plugins.opt, $GITHUB_COM.'davidhalter/jedi-vim')
call add(s:plugins.opt, $GITHUB_COM.'vim-perl/vim-perl')
call add(s:plugins.opt, $GITHUB_COM.'c9s/perlomni.vim')
call add(s:plugins.opt, $GITHUB_COM.'pangloss/vim-javascript')
call add(s:plugins.opt, $GITHUB_COM.'marijnh/tern_for_vim')
call add(s:plugins.opt, $GITHUB_COM.'vim-scripts/SQLUtilities')
call add(s:plugins.opt, $GITHUB_COM.'mattn/emmet-vim')
call add(s:plugins.opt, $GITHUB_COM.'hail2u/vim-css3-syntax')
call add(s:plugins.opt, $GITHUB_COM.'fatih/vim-go')
call add(s:plugins.opt, $GITHUB_COM.'prabirshrestha/vim-lsp')
call add(s:plugins.opt, $GITHUB_COM.'mattn/vim-lsp-settings')
call add(s:plugins.opt, $GITHUB_COM.'github/copilot.vim')
function! s:has_plugin(name)
return globpath(&runtimepath, 'plugin/' . a:name . '.vim') !=# ''
\ || globpath(&runtimepath, 'autoload/' . a:name . '.vim') !=# ''
endfunction
function! s:mkdir_if_not_exists(path)
if !isdirectory(a:path)
call mkdir(a:path, 'p')
endif
endfunction
function! s:create_helptags(path)
if isdirectory(a:path)
execute 'helptags ' . a:path
endif
endfunction
function! InstallPackPlugins()
for key in keys(s:plugins)
let dir = expand($PACKPATH . '/' . key)
call s:mkdir_if_not_exists(dir)
for url in s:plugins[key]
let dst = expand(dir . '/' . split(url, '/')[-1])
if isdirectory(dst)
" plugin is already installed
continue
endif
echo 'installing: ' . dst
let cmd = printf('git clone --recursive %s %s', url, dst)
call system(cmd)
call s:create_helptags(expand(dst . '/doc/'))
endfor
endfor
endfunction
function! UpdateHelpTags()
for key in keys(s:plugins)
let dir = expand($PACKPATH . '/' . key)
for url in s:plugins[key]
let dst = expand(dir . '/' . split(url, '/')[-1])
if !isdirectory(dst)
" plugin is not installed
continue
endif
echomsg 'helptags: ' . dst
call s:create_helptags(expand(dst . '/doc/'))
endfor
endfor
endfunction
function! UpdatePackPlugins()
topleft split
edit `='[update plugins]'`
setlocal buftype=nofile
let s:pidx = 0
call timer_start(100, 'PluginUpdateHandler', {'repeat': len(s:plugins.opt)})
endfunction
function! PluginUpdateHandler(timer)
let dir = expand($PACKPATH . '/' . 'opt')
let url = s:plugins.opt[s:pidx]
let dst = expand(dir . '/' . split(url, '/')[-1])
let cmd = printf('git -C %s pull --ff --ff-only', dst)
call job_start(cmd, {'out_io': 'buffer', 'out_name': '[update plugins]'})
let s:pidx += 1
if s:pidx == len(s:plugins.opt)
call UpdateHelpTags()
endif
endfunction
let s:pidx = 0
function! PackAddHandler(timer)
let plugin_name = split(s:plugins.opt[s:pidx], '/')[-1]
let plugin_path = expand($PACKPATH . '/opt/' . plugin_name)
if isdirectory(plugin_path)
execute 'packadd ' . plugin_name
endif
let s:pidx += 1
if s:pidx == len(s:plugins.opt)
packadd cfilter
" for filetype plugin
doautocmd FileType
" fugitive.vim requires do autocmd
doautocmd fugitive BufReadPost
" for vim-lsp
call lsp#enable()
" for vim-signify
SignifyEnable
" for vim-indent-guides
IndentGuidesEnable
endif
endfunction
if has('vim_starting') && has('timers')
packadd vim-textobj-user
packadd vim-operator-user
autocmd MyVimrcCmd VimEnter * call timer_start(1, 'PackAddHandler', {'repeat': len(s:plugins.opt)})
endif
filetype plugin indent on
"}}}
"---------------------------------------------------------------------------
" Mouse:"{{{
"
set mouse=a
set nomousefocus
set nomousehide
"set guioptions+=a
"}}}
"---------------------------------------------------------------------------
" Edit:"{{{
"
set nobackup
set browsedir=buffer
set clipboard=unnamed,unnamedplus
set tabstop=4
set softtabstop=4
set shiftwidth=4
set smarttab
set expandtab
set backspace=indent,eol,start
set whichwrap=b,s,<,>,[,]
set wildmenu
set virtualedit+=block
set autoindent
" Smart indenting
set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
" for smartindent
inoremap # X<C-H><C-V>#
set completeopt=menuone,longest
" settings for Japanese folding
set formatoptions+=mM
" don't continue the comment line automatically
set formatoptions-=ro
autocmd MyVimrcCmd FileType * setlocal formatoptions-=ro
" settings for Japanese formatting
let format_allow_over_tw = 1
set nrformats=alpha,hex
" tags "{{{
set tags=./tags
set tags+=tags;
set tags+=./**/tags
"}}}
" grep "{{{
command! UseGitgrep set grepprg=git\ grep\ -n\ --no-color
command! UseJvgrep set grepprg=jvgrep\ -n\ --no-color
if executable('jvgrep')
:UseJvgrep
else
set grepprg=grep\ -nH
endif
command! -nargs=+ Sgrep silent grep! <args>
nnoremap <Space>sg :<C-u>Sgrep <cword> %<CR>
autocmd MyVimrcCmd QuickfixCmdPre make,grep,grepadd,vimgrep,vimgrepadd,helpgrep copen
"}}}
autocmd MyVimrcCmd InsertLeave * if &paste | set nopaste | endif
nnoremap <Space>op :<C-u>set paste! paste?<CR>
"}}}
"---------------------------------------------------------------------------
" View:"{{{
"
" Fonts:"{{{
if has('xfontset')
set guifontset=a14,r14,k14
elseif has('unix')
elseif has('mac')
set guifont=Osaka-mono:h14
elseif s:MSWindows
" set guifont=MS_Gothic:h12:cSHIFTJIS
" set guifontwide=MS_Gothic:h12:cSHIFTJIS
set guifont=MS_Gothic:h10:cSHIFTJIS
set linespace=1
endif
" For Printer :
if has('printer')
if s:MSWindows
set printfont=MS_Mincho:h12:cSHIFTJIS
" set printfont=MS_Gothic:h12:cSHIFTJIS
endif
endif
"}}}
" Color Scheme:"{{{
colorscheme torte
"}}}
set nonumber
nnoremap <Space>on :<C-u>setlocal number! number?<CR>
set showmatch
set laststatus=2
set cmdheight=2
set showcmd
set title
set showtabline=2
set display=uhex
set previewheight=12
set winwidth=20
set t_Co=256
if &term =~# 'xterm'
let &t_SI = "\<Esc>[5 q"
let &t_SR = "\<Esc>[3 q"
let &t_EI = "\<Esc>[1 q"
endif
set nowrap
nnoremap <Space>ow :<C-u>setlocal wrap! wrap?<CR>
set nolist
nnoremap <Space>ol :<C-u>setlocal list! list?<CR>
set listchars=tab:>-,extends:<,precedes:>,trail:-,eol:$,nbsp:%
" Limit horizontal scrollbar size to the length of the cursor line
set guioptions+=h
" Hide Toolbar
set guioptions-=T
" Toggle horizontal scrollbar
nnoremap <silent> <Space>oh :
\ if &guioptions =~# 'b' <Bar>
\ set guioptions-=b <Bar>
\ else <Bar>
\ set guioptions+=b <Bar>
\ endif <CR>
if has('gui_running')
" Window width
set columns=160
" Window height
set lines=40
endif
" Command-line height
set cmdheight=2
" Tabline settings "{{{
function! s:is_modified(n) "{{{
return getbufvar(a:n, '&modified') == 1 ? '+' : ''
endfunction "}}}
function! s:tabpage_label(n) "{{{
let title = gettabwinvar(a:n, 0, 'title')
if title !=# ''
return title
endif
let bufnrs = tabpagebuflist(a:n)
let buflist = join(map(copy(bufnrs), 'v:val . s:is_modified(v:val)'), ',')
let curbufnr = bufnrs[tabpagewinnr(a:n) - 1]
let fname = pathshorten(bufname(curbufnr))
let label = '[' . buflist . ']' . fname
let hi = a:n is tabpagenr() ? '%#TabLineSel#' : '%#TabLine#'
return '%' . a:n . 'T' . hi . label . '%T%#TabLineFill#'
endfunction "}}}
function! MakeTabLine() "{{{
let titles =map(range(1, tabpagenr('$')), 's:tabpage_label(v:val)')
let sep = ' | '
let tabpages = join(titles, sep) . sep . '%#TabLineFill#%T'
let info = fnamemodify(getcwd(), '~:') . ' '
return tabpages . '%=' . info
endfunction "}}}
set guioptions-=e
set tabline=%!MakeTabLine()
"}}}
" Visualization of the full-width space and the blank at the end of the line "{{{
if has('syntax')
syntax on
" for POD bug
" syn sync fromstart
function! ActivateInvisibleIndicator()
syntax match InvisibleJISX0208Space "\%u3000" display containedin=ALL
highlight InvisibleJISX0208Space term=underline ctermbg=Blue guibg=darkgray gui=underline
syntax match InvisibleTrailedSpace "\s\+$" display containedin=ALL
if has('gui_macvim')
highlight InvisibleTrailedSpace term=underline ctermbg=darkgray guibg=lightgray
else
highlight InvisibleTrailedSpace term=underline ctermbg=darkgray gui=undercurl guisp=darkorange
endif
" syntax match InvisibleTab "\t" display containedin=ALL
" highlight InvisibleTab term=underline ctermbg=white gui=undercurl guisp=darkslategray
endfunction
call ActivateInvisibleIndicator()
augroup invisible
autocmd! invisible
autocmd BufNew,BufRead * call ActivateInvisibleIndicator()
augroup END
endif
"}}}
" XPstatusline + fugitive#statusline "{{{
let g:statusline_max_path = 50
function! StatusLineGetPath() "{{{
let p = expand('%:.:h')
let p = substitute(p, expand('$HOME'), '~', '')
if len(p) > g:statusline_max_path
let p = simplify(p)
let p = pathshorten(p)
endif
return p
endfunction "}}}
nnoremap <Plug>view:switch_status_path_length :let g:statusline_max_path = 200 - g:statusline_max_path<cr>
nnoremap ,t <Plug>view:switch_status_path_length
augroup Statusline
autocmd! Statusline
autocmd BufEnter * call <SID>SetFullStatusline()
autocmd BufLeave,BufNew,BufRead,BufNewFile * call <SID>SetSimpleStatusline()
augroup END
function! StatusLineRealSyn()
let synId = synID(line('.'),col('.'),1)
let realSynId = synIDtrans(synId)
if synId == realSynId
return 'Normal'
else
return synIDattr( realSynId, 'name' )
endif
endfunction
function! s:SetFullStatusline() "{{{
setlocal statusline=
" buffer number
setlocal statusline+=%#StatuslineBufNr#%-1.2n
" flags
setlocal statusline+=\ %h%#StatuslineFlag#%m%r%w
" path
setlocal statusline+=%#StatuslinePath#\ %-0.50{StatusLineGetPath()}%0*
" file name
setlocal statusline+=%#StatuslineFileName#\/%t
" file size
setlocal statusline+=%#StatuslineFileSize#\ \(%{GetFileSize()}\)
try
call fugitive#statusline()
" Git branch name
setlocal statusline+=\ %{fugitive#statusline()}
catch /E117/
endtry
" current char
setlocal statusline+=%#StatuslineChar#\ \ %{GetCharacterCode()}
" encoding
setlocal statusline+=%#StatuslineTermEnc#(%{&termencoding},
" file encoding
setlocal statusline+=%#StatuslineFileEnc#%{&fileencoding},
" file format
setlocal statusline+=%#StatuslineFileFormat#%{&fileformat}\)
" filetype
setlocal statusline+=%#StatuslineFileType#\ %{strlen(&ft)?&ft:'**'}\ .
" syntax name
setlocal statusline+=%#StatuslineSyn#\ %{synIDattr(synID(line('.'),col('.'),1),'name')}\ %0*
" real syntax name
setlocal statusline+=%#StatuslineRealSyn#\ %{StatusLineRealSyn()}\ %0*
setlocal statusline+=%=
" position
setlocal statusline+=\ %-10.(%l/%L,%c-%v%)
" position percentage
setlocal statusline+=\ %P
endfunction "}}}
function! s:SetSimpleStatusline() "{{{
setlocal statusline=
" path
setlocal statusline+=%#StatuslineNC#%-0.20{StatusLineGetPath()}%0*
" file name
setlocal statusline+=\/%t
endfunction "}}}
" Get character code on cursor with 'fileencoding'.
function! GetCharacterCode()
let str = iconv(matchstr(getline('.'), '.', col('.') - 1), &enc, &fenc)
let out = '0x'
for i in range(strlen(str))
let out .= printf('%02X', char2nr(str[i]))
endfor
if str ==# ''
let out .= '00'
endif
return out
endfunction
" Return the current file size in human readable format.
function! GetFileSize()
let size = &encoding ==# &fileencoding || &fileencoding ==# ''
\ ? line2byte(line('$') + 1) - 1 : getfsize(expand('%'))
if size < 0
let size = 0
endif
let format = has('float') ? '%0.2f' : '%d'
let div_unit = has('float') ? 1024.0 : 1024
for unit in ['B', 'KB', 'MB']
if size < 1024
" return size . unit
return printf(format . unit, size)
endif
let size = size / div_unit
endfor
return printf(format . 'GB', size)
endfunction
"}}}
augroup MyVimrcCmd
autocmd ColorScheme * call s:onColorScheme()
augroup END
function! s:onColorScheme()
" Color name: $VIMRUNTIME/colors/lists/default.vim
" IME Color "{{{
if has('multi_byte_ime') || has('xim')
" Set the color of the cursor when the IME ON
highlight CursorIM guibg=#a020f0 guifg=NONE
" Default IME settings in search mode and insert mode
set iminsert=0 imsearch=0
if has('xim') && has('GUI_GTK')
"set imactivatekey=C-Space
endif
endif
if has('multi_byte_ime')
" highlight Cursor guifg=NONE guibg=Green
highlight CursorIM guifg=NONE guibg=#a020f0
endif
"}}}
" Additional settings of Color "{{{
" highlight Cursor guifg=Black guibg=Green gui=bold
highlight Search ctermfg=Black ctermbg=Red cterm=bold guifg=#000000 guibg=#ff0000 gui=bold
highlight Visual cterm=reverse guifg=#404040 gui=bold
highlight Folded guifg=blue guibg=darkgray
highlight TabLine ctermfg=Black ctermbg=White guifg=#000000 guibg=#dcdcdc gui=underline
highlight TabLineFill term=none cterm=none ctermfg=Black ctermbg=White guifg=#000000 guibg=#dcdcdc gui=underline
highlight TabLineSel term=bold cterm=bold ctermfg=White ctermbg=Blue guifg=White guibg=Blue gui=bold
"}}}
" For completion menu "{{{
highlight Pmenu ctermfg=White ctermbg=DarkBlue guifg=#0033ff guibg=#99cccc gui=none
highlight PmenuSel ctermfg=Black ctermbg=Cyan guifg=#ccffff guibg=#006699 gui=none
highlight PmenuSbar ctermfg=White ctermbg=LightCyan guifg=#ffffff guibg=#848484 gui=none
highlight PmenuThumb ctermfg=White ctermbg=DarkGreen guifg=#ffffff guibg=#006699 gui=none
"}}}
" For indent-guides "{{{
let cterm_colors = (&background == 'dark') ? ['darkgray', 'gray'] : ['lightgray', 'white']
let gui_colors = (&background == 'dark') ? ['#262626', '#4d4d4d'] : ['#b3b3b3', '#d9d9d9']
execute 'highlight IndentGuidesEven guibg=' . gui_colors[0] . ' guifg=' . gui_colors[1] . ' ctermbg=' . cterm_colors[0] . ' ctermfg=' . cterm_colors[1]
execute 'highlight IndentGuidesOdd guibg=' . gui_colors[1] . ' guifg=' . gui_colors[0] . ' ctermbg=' . cterm_colors[1] . ' ctermfg=' . cterm_colors[0]
"}}}
" For signify "{{{
highlight SignifySignAdd cterm=bold ctermbg=237 ctermfg=119 guifg=#000000 guibg=#00ff00
highlight SignifySignDelete cterm=bold ctermbg=237 ctermfg=167 guifg=#000000 guibg=#ff0000
highlight SignifySignChange cterm=bold ctermbg=237 ctermfg=227 guifg=#000000 guibg=#ffff00
"}}}
endfunction
call s:onColorScheme()
"}}}
"---------------------------------------------------------------------------
" Search:"{{{
"
set nowrapscan
set incsearch
set ignorecase
nnoremap <Space>oi :<C-u>setlocal ignorecase! ignorecase?<CR>
set smartcase
nnoremap <Space>os :<C-u>setlocal smartcase! smartcase?<CR>
set hlsearch
nohlsearch
nnoremap <ESC><ESC> :nohlsearch<CR>
"}}}
"---------------------------------------------------------------------------
" Utilities:"{{{
"
" :tcd to the directory of the current file or specified path "{{{
command! -nargs=? -complete=dir -bang TCD call s:ChangeCurrentDir('<args>', '<bang>')
function! s:ChangeCurrentDir(directory, bang)
if a:directory == ''
if &buftype !=# 'terminal'
tcd %:p:h
endif
else
execute 'tcd' . a:directory
endif
if a:bang == ''
pwd
endif
endfunction "}}}
nnoremap <silent> <Space>cd :<C-u>TCD<CR>
" Files "{{{
cabbrev %% %:p:h
command! -bar ToScratch setlocal buftype=nofile bufhidden=hide noswapfile
command! -bar ToScratchForFiles ToScratch | setlocal iskeyword+=.
command! GoScratch set ft=go | ToScratch | Template main
command! -bar -nargs=? ModsNew <mods> new | if <q-args> ==# 'Files:.' | edit `='[Files:' . fnamemodify(getcwd(), ':p:h') . ']'` | elseif len(<q-args>) | edit [<args>] | endif
if executable('files')
let s:files_cmd = 'files -a'
let s:files_opts = ''
elseif s:MSWindows
let s:files_cmd = 'dir'
let s:files_opts = '/b /s /a-d'
else
let s:files_cmd = 'find '
let s:files_opts = '-type f'
endif
command! -bar -nargs=1 -complete=dir Files <mods> ModsNew Files:<args> | ToScratchForFiles | execute 'r! ' . s:files_cmd . ' "<args>" ' . s:files_opts
command! FilesBuffer <mods> Files %:p:h
command! FilesCurrent <mods> Files .
command! MRU <mods> ModsNew MRU | ToScratchForFiles | call setline(1, filter(v:oldfiles, 'filereadable(expand(v:val))'))
" list results of given ex-cmd(e.g. :buffers, :scriptnames)
command! -nargs=1 -complete=command L <mods> ModsNew <args> | ToScratchForFiles | call setline(1, split(execute(<q-args>), '\n'))
command! ScriptNames <mods> L scriptnames
command! Buffers <mods> L buffers
"}}}
" Occur "{{{
command! Occur execute 'vimgrep /' . @/ . '/ %'
command! StarOccur execute 'vimgrep /' . expand('<cword>') . '/ %'
nnoremap <Leader>oc :<C-u>Occur<CR>
nnoremap <Leader>so :<C-u>StarOccur<CR>
"}}}
" SwapColon "{{{
nnoremap <Space>sc :<C-u>SwapColon<CR>
command! SwapColon call SwapColon()
function! SwapColon()
if maparg(';', 'n') == ':'
nunmap ;
nunmap :
vunmap ;
vunmap :
nunmap q;
else
nnoremap ; :
nnoremap : ;
vnoremap ; :
vnoremap : ;
nnoremap q; q:
endif
endfunction
"}}}
" TermGuiColors "{{{
command! TermGuiColors call TermGuiColors()
function! TermGuiColors()
execute "set t_8f=\e[38;2;%lu;%lu;%lum"
execute "set t_8b=\e[48;2;%lu;%lu;%lum"
set termguicolors
endfunction
"}}}
" Command-line window "{{{
autocmd MyVimrcCmd CmdwinEnter * call s:init_cmdwin()
function! s:init_cmdwin()
nnoremap <buffer> q :<C-u>quit<CR>
nnoremap <buffer> <TAB> :<C-u>quit<CR>
inoremap <buffer><expr><C-h> pumvisible() ? "\<C-y>\<C-h>" : "\<C-h>"
inoremap <buffer><expr><BS> pumvisible() ? "\<C-y>\<C-h>" : "\<C-h>"
inoremap <buffer><expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
startinsert!
endfunction
"}}}
" DiffClip() "{{{
" http://vimwiki.net/?tips%2F49
command! -nargs=0 -range DiffClip <line1>, <line2>:call DiffClip('0')
" get diff with register reg
function! DiffClip(reg) range
exe "let @a=@" . a:reg
exe a:firstline . "," . a:lastline . "y b"
tabnew "new
" clear the buffer after close this window
set buftype=nofile bufhidden=wipe
put a
diffthis
lefta vnew "vnew
set buftype=nofile bufhidden=wipe
put b
diffthis
endfunction
"}}}
" DiffScratch() "{{{
command! DiffScratch call DiffScratch()
function! DiffScratch()
tabnew
set buftype=nofile bufhidden=wipe
diffthis
lefta vnew
set buftype=nofile bufhidden=wipe
diffthis
endfunction
"}}}
" NextIndent() "{{{
" http://vim.wikia.com/wiki/Move_to_next/previous_line_with_same_indentation
"
" Jump to the next or previous line that has the same level or a lower
" level of indentation than the current line.
"
" exclusive (bool): true: Motion is exclusive
" false: Motion is inclusive
" fwd (bool): true: Go to next line
" false: Go to previous line
" lowerlevel (bool): true: Go to line with lower indentation level
" false: Go to line with the same indentation level
" skipblanks (bool): true: Skip blank lines
" false: Don't skip blank lines
function! NextIndent(exclusive, fwd, lowerlevel, skipblanks)
let line = line('.')
let column = col('.')
let lastline = line('$')
let indent = indent(line)
let stepvalue = a:fwd ? 1 : -1
while (line > 0 && line <= lastline)
let line = line + stepvalue
if ( ! a:lowerlevel && indent(line) == indent ||
\ a:lowerlevel && indent(line) < indent)
if (! a:skipblanks || strlen(getline(line)) > 0)
if (a:exclusive)
let line = line - stepvalue
endif
exe line
exe "normal " column . "|"
return
endif
endif
endwhile
endfunc
" Moving back and forth between lines of same or lower indentation.
nnoremap <silent> [l :call NextIndent(0, 0, 0, 1)<cr>
nnoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<cr>
nnoremap <silent> [L :call NextIndent(0, 0, 1, 1)<cr>
nnoremap <silent> ]L :call NextIndent(0, 1, 1, 1)<cr>
vnoremap <silent> [l <esc>:call NextIndent(0, 0, 0, 1)<cr>m'gv''
vnoremap <silent> ]l <esc>:call NextIndent(0, 1, 0, 1)<cr>m'gv''
vnoremap <silent> [L <esc>:call NextIndent(0, 0, 1, 1)<cr>m'gv''
vnoremap <silent> ]L <esc>:call NextIndent(0, 1, 1, 1)<cr>m'gv''
onoremap <silent> [l :call NextIndent(0, 0, 0, 1)<cr>
onoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<cr>
onoremap <silent> [L :call NextIndent(1, 0, 1, 1)<cr>
onoremap <silent> ]L :call NextIndent(1, 1, 1, 1)<cr>
"}}}
" Split and Go "{{{
" USAGE:
" [count]sag - Split the current window horizontally and, go to line [count].
" [count]sav - Split the current window vertically and, go to line [count].
nnoremap sag :<C-u>SplitAndGo split<CR>
nnoremap sav :<C-u>SplitAndGo vsplit<CR>
command! -count=1 -nargs=1 -complete=customlist,SAG_Complete SplitAndGo call SplitAndGo(<q-args>)
function! SplitAndGo(cmd)
let cnt = v:count ? v:count : 1
let cmd = cnt > line('.') ? 'botright '.a:cmd : 'topleft '.a:cmd
" execute cmd
call s:split(cmd, 'preview')
execute cnt
normal! zv
endfunction
function! SAG_Complete(ArgLead, CmdLine, CursorPos)
return ['split', 'vsplit']
endfunction
" For don't split the window if the window name is already exists.
" http://d.hatena.ne.jp/osyo-manga/20120826/1345944705
function! s:is_number(str)
return (type(a:str) == type(0)) || (a:str =~ '^\d\+$')
endfunction
function! s:winnrlist(...)
return a:0
\ ? range(1, tabpagewinnr(a:1, "$"))
\ : range(1, tabpagewinnr(tabpagenr(), "$"))
endfunction
function! s:winlist(...)
let tabnr = a:0 == 0 ? tabpagenr() : a:1
return map(s:winnrlist(tabnr), '{
\ "winnr" : v:val,
\ "name" : gettabwinvar(tabnr, v:val, "name")
\ }')
endfunction
function! s:winnr(...)
return a:0 == 0 ? winnr()
\ : a:1 ==# "$" ? winnr("$")
\ : a:1 ==# "#" ? winnr("#")
\ : !s:is_number(a:1) ? (filter(s:winlist(), 'v:val.name ==# a:1') + [{'winnr' : '-1'}])[0].winnr
\ : a:1
endfunction
function! s:winname(...)
return a:0 == 0 ? s:winname(winnr())
\ : a:1 ==# "$" ? s:winname(winnr("$"))
\ : a:1 ==# "#" ? s:winname(winnr("#"))
\ : !s:is_number(a:1) ? (filter(s:winlist(), 'v:val.name ==# a:1') + [{'name' : ''}])[0].name