-
Notifications
You must be signed in to change notification settings - Fork 8
/
.vimrc
1435 lines (1286 loc) · 44.1 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
"
" ============================================================================
" === Initialization ====================================================={{{1
" Skip initialization for vim-tiny or vim-small.
if 0 | endif
if &compatible
set nocompatible
endif
" if has('vim_starting')
" " Print vim startup time.
" if has('reltime')
" let g:startuptime = reltime()
" augroup VimStartUpTimeAu
" autocmd!
" autocmd VimEnter * let g:startuptime = reltime(g:startuptime) | redraw
" \ | echomsg 'startuptime: ' . reltimestr(g:startuptime)
" augroup END
" endif
" endif
" OS detection flag.
let s:is_windows = has('win16') || has('win32') || has('win64')
let s:is_cygwin = has('win32unix')
let s:is_mac = !s:is_windows && !s:is_cygwin
\ && (has('mac') || has('macunix') || has('gui_macvim')
\ || (!executable('xdg-open') && system('uname') =~? '^darwin'))
" Language.
if s:is_windows
" For Windows.
language messages ja_JP
elseif s:is_mac
" For Mac.
language messages C
" language ctype C
language time C
else
" For Linux.
language messages C
endif
" Help language.
set helplang& helplang=ja,en
" shortmess.
" Don't give the intro message when starting Vim.
" Abbreviate all messages.
set shortmess& shortmess=atToOI
" Ddon't give |ins-completion-menu| messages.
" http://qiita.com/koara-local/items/40153e1135bb8101cf2d
if has('patch-7.4.314')
set shortmess+=c
endif
" Don't give the file info when editing a file.
if has('patch-7.4.1570')
set shortmess+=F
endif
" Change path separator to slash(/) for Win.
if s:is_windows && exists('+shellslash')
set shellslash
endif
" vim directory.
" Windows : $VIM/vimfiles
" Linux/Mac : ~/.vim
if s:is_windows
let $DOTVIM = expand('~/vimfiles')
else
let $DOTVIM = expand('~/.vim')
endif
" Set .gvimrc path.
if !exists('$MYGVIMRC')
let $MYGVIMRC = expand('~/.gvimrc')
endif
" cache directory.
let $CACHE = expand('~/.cache')
if !isdirectory(expand($CACHE))
echoerr '[WARNING] "' . $CACHE , '" does not exist. Run mkdir -p ' . expand($CACHE)
echoerr '-> mkdir -p ' . expand($CACHE)
call mkdir(expand($CACHE), 'p')
endif
" Save current working directory for a tab page.
let t:cwd = getcwd()
" Set <Leader> key (default: \) for global plugin.
let g:mapleader = ','
" Set <LocalLeader> key for filetype plugin to avoid conflicts.
" let g:maplocalleader = '\'
" Release keymappings for plug-in.
nnoremap ; <Nop>
xnoremap ; <Nop>
nnoremap , <Nop>
xnoremap , <Nop>
augroup MyAutoCmd
autocmd!
augroup END
" Disable menu.vim.
" This flag(M) must be added in the .vimrc file, before switching on syntax or
" filetype recognition (when the |gvimrc| file is sourced the system menu has
" already been loaded; the ':syntax on' and ':filetype on' commands load the menu too).
if has('gui_running')
set guioptions+=M
endi
" Disable menu for GUI. (:help menus)
let did_install_default_menus = 1
let did_install_syntax_menu = 1
" Disable default plugins.
let g:loaded_gzip = 1
let g:loaded_tar = 1
let g:loaded_tarPlugin = 1
let g:loaded_zip = 1
let g:loaded_zipPlugin = 1
let g:loaded_rrhelper = 1
let g:loaded_2html_plugin = 1
let g:loaded_vimball = 1
let g:loaded_vimballPlugin = 1
let g:loaded_getscript = 1
let g:loaded_getscriptPlugin = 1
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
let g:loaded_netrwSettings = 1
let g:loaded_netrwFileHandlers = 1
let g:loaded_matchparen = 1
let g:loaded_LogiPat = 1
let g:loaded_logipat = 1
let g:loaded_tutor_mode_plugin = 1
let g:loaded_spellfile_plugin = 1
let g:loaded_man = 1
let g:loaded_matchit = 1
" }}}
" === Define functions ==================================================={{{1
" Anywhere SID.
function! s:SID_PREFIX() abort
return matchstr(expand('<sfile>'), '<SNR>\d\+_\zeSID_PREFIX$')
endfunction
" Toggle options.
function! ToggleOption(option_name) abort
execute 'setlocal' a:option_name.'!'
execute 'setlocal' a:option_name.'?'
endfunction
" Toggle variables.
function! ToggleVariable(variable_name) abort
if eval(a:variable_name)
execute 'let' a:variable_name.' = 0'
else
execute 'let' a:variable_name.' = 1'
endif
echo printf('%s = %s', a:variable_name, eval(a:variable_name))
endfunction
" Execute with selected text.
" (for open-browser.vim)
"http://deris.hatenablog.jp/entry/2013/07/05/023835
function! ExecuteWithSelectedText(command) abort
if a:command !~? '%s'
return
endif
let reg = '"'
let [save_reg, save_type] = [getreg(reg), getregtype(reg)]
normal! gvy
let selectedText = @"
call setreg(reg, save_reg, save_type)
if selectedText == ''
return
endif
execute printf(a:command, selectedText)
endfunction
" }}}
" === Dein ==============================================================={{{1
if filereadable(expand('~/.vim/rc/plugins/dein.rc.vim'))
execute 'source' expand('~/.vim/rc/plugins/dein.rc.vim')
endif
syntax enable
filetype plugin indent on
" }}}
" === Encoding ==========================================================={{{1
" http://d.hatena.ne.jp/ka-nacht/20080220/1203433500
" http://www.kawaz.jp/pukiwiki/?vim#cb691f26
" http://d.hatena.ne.jp/over80/20080907/1220794834
"
" encoding
" vim内部で使用する文字コード
" バッファ/レジスタ/vimスクリプトなどの文字列に適用される
" vim全体で共通のグローバルオプション
" 新規ファイル作成時にfileencodingが未指定の場合にも使用される
"
" fileencoding
" 新規ファイル作成時またはバッファ保存時に使用される文字コード
" (ファイルの文字コードと言えばこの値を指す)
" バッファ毎に指定可能なバッファローカルオプション
" encodingと異なる場合は保存時にfileencodingへ変換される
" fileencodingを変更したい場合は setlocal にて変更する必要がある
" set にて変更した場合はグローバル値が変更されるため、以降に新規作成される
" バッファの保存時に適用される文字コードが変わってしまう
"
" fileencodings
" 文字コードの自動判別優先順位
" カンマ区切りで指定され、左側の設定が優先される
" 判別方法は左から順に変換を行い最初に成功した値が適用される
" 変換途中にencodingまたはfileencodingと同じ値を発見した場合は判定を中断し
" その値を適用する
" 自動判別に失敗した場合は encoding の値が適用される
"
" fileformat
" 改行コード(unix=LF, dos=CRLF, mac=CR)
"
" fileformats
" 改行コードの自動判別優先順位
" ============================================================================
" Setting of the encoding to use for a save and reading.
" Make it normal in UTF-8 in Unix.
if has('vim_starting') && &encoding !=# 'utf-8'
if s:is_windows && !has('gui_running')
set encoding=cp932
else
set encoding=utf-8
endif
endif
"Setting of terminal encoding.
if !has('gui_running')
if $ENV_ACCESS ==# 'linux'
set termencoding=euc-jp
elseif $ENV_ACCESS ==# 'colinux'
set termencoding=utf-8
else " fallback
set termencoding= " same as 'encoding'
endif
elseif s:is_windows
" For system.
set termencoding=cp932
endif
" The automatic recognition of the character code.
if has('kaoriya')
" For Kaoriya only.
set fileencodings=guess
elseif !exists('did_encoding_settings') && has('iconv')
" Build encodings.
let &fileencodings = join([
\ 'ucs-bom', 'iso-2022-jp-3', 'utf-8', 'euc-jp', 'cp932'])
let did_encoding_settings = 1
endif
" When do not include Japanese, use encoding for fileencoding.
function! s:ReCheck_FENC() abort
let is_multi_byte = search("[^\x01-\x7e]", 'n', 100, 100)
if &fileencoding =~# 'iso-2022-jp' && !is_multi_byte
let &fileencoding = &encoding
endif
endfunction
autocmd MyAutoCmd BufReadPost * call s:ReCheck_FENC()
" Default fileformat.
set fileformat=unix
" Automatic recognition of a new line cord.
set fileformats=unix,dos,mac
" For multi-byte sign: □ ,◯
" Use only 'auto' for Win-Kaoriya.
if &ambiwidth !=# 'auto'
set ambiwidth=double
endif
" IME OFF when leave insert mode.
" Mac('xim') : Use Karabiner.
" Win(multi_byte_ime) : http://d.hatena.ne.jp/r7kamura/20110217/1297910068
if has('multi_byte_ime')
" Enable IM.
set noimdisable
" IM(Input Method).
" 0: lmap:OFF IM:OFF
" 1: lmap:ON IM:OFF
" 2: lmap:OFF IM:ON
set iminsert=0
set imsearch=0
set noimcmdline
endif
" }}}
" === Backup ============================================================={{{1
" Backup on.
" set backup
" set swapfile
" set backupdir=~/backup
" Backup off.
set nobackup
set noswapfile
" Make a backup before overwriting a file.
" The backup is removed after the file was successfully written,
" unless the 'backup' option is also on.
set writebackup
set backupdir-=.
set directory-=.
" Restores undo history from the same file on buffer read.
if has('persistent_undo')
set undofile
let &g:undodir=&directory
endif
" }}}
" === Appearance ======================================================== {{{1
" Colors.
if &term =~ "xterm-256color" || &term=~"screen-256color"
" 256 colors.
set t_Co=256
set t_Sf=^[[3%dm
set t_Sb=^[[4%dm
" Change cursor shape.
" let &t_SI = "\<ESC>]12;lightgreen\x7"
" let &t_EI = "\<ESC>]12;white\x7"
" Enable true color.
if exists('+termguicolors')
set termguicolors
endif
" Source my color settings.
if $ITERM_PROFILE =~ "Magica.*"
source ~/.vim/colors/my-landscape.vim
elseif $ITERM_PROFILE =~ "Solarized.*"
source ~/.vim/colors/my-solarized.vim
else
source ~/.vim/colors/my-hybrid.vim
endif
elseif &term =~ "xterm-debian" || &term =~ "xterm-xfree86"
" 16 colors.
set t_Co=16
set t_Sf=^[[3%dm
set t_Sb=^[[4%dm
source ~/.vim/colors/my-solarized.vim
elseif &term =~ "xterm-color"
" 8 colors.
set t_Co=8
set t_Sf=^[[3%dm
set t_Sb=^[[4%dm
source ~/.vim/colors/my-solarized.vim
endif
" Disable italic/bold syntax (_*) on Markdown.
autocmd MyAutoCmd FileType markdown
\ highlight! def link htmlItalic Normal |
\ highlight! def link htmlBold Normal |
\ highlight! def link htmlBoldItalic Normal
" Enable colors for TeraTerm.
let s:is_teraterm = 0
if s:is_teraterm
set term=builtin_linux
set ttytype=builtin_linux
endif
" ------------------ * COLOR SETTINGS BEYOND THIS POINT. * ------------------
set ttyfast " Fast terminal connection.
set number " Print the line number in front of each line.
set scrolloff=7 " Minimal number of screen lines to keep above and below the cursor.
" Change the way text is displayed.
" lastline As much as possible of the last line in a window will be displayed.
" uhex Show unprintable characters hexadecimal as <xx> instead of using ^C and ~C.
set display& display+=uhex,lastline
" Window.
set splitbelow " Splitting a window will put the new window below the current one.
set splitright " Splitting a window will put the new window right of the current one.
set winwidth=20 " Minimal number of columns for the current window.
set winheight=1 " Minimal number of lines for the current window.
set previewheight=8 " Default height for a preview window.
set helpheight=12 " Minimal initial height of the help window when it is opened with the ':help' command.
" equalalways
" ON All the windows are automatically made the same size after
" splitting or closing a window.
" OFF Splitting a window will reduce the size of the current window
" and leave the other windows the same.
"set noequalalways
" The screen will not be redrawn while executing macros, registers
" and other commands that have not been typed.
set lazyredraw
" Ttile.
" The title of the window will be set to the value of
" 'titlestring' (if it is not empty), or to:
" filename [+=-] (path) - VIM
set title
set titlelen=95
let &g:titlestring="
\ %{expand('%:p:~:.')}%(%m%r%w%)
\ %<\(%{".s:SID_PREFIX()."strwidthpart(
\ fnamemodify(&filetype ==# 'vimfiler' ?
\ substitute(b:vimfiler.current_dir, '.\\zs/$', '', '') : getcwd(), ':~'),
\ &columns-len(expand('%:p:.:~')))}\) - VIM"
function! s:strwidthpart(str, width) abort
if a:width <= 0
return ''
endif
let ret = a:str
let width = s:wcswidth(a:str)
while width > a:width
let char = matchstr(ret, '.$')
let ret = ret[: -1 - len(char)]
let width -= s:wcswidth(char)
endwhile
return ret
endfunction
" Conceal/colorcolumn.
if v:version >= 703
set conceallevel=2 concealcursor=niv
" Show colorcolumn.
if exists('+colorcolumn')
set colorcolumn=80
endif
" Use builtin function.
function! s:wcswidth(str) abort
return strwidth(a:str)
endfunction
else
function! s:wcswidth(str) abort
return len(a:str)
endfunction
endif
" command-line.
set showcmd " Show command on statusline.
set showmode " Show mode on statusline.
set laststatus=2 " Display always statusline.
set cmdheight=2 " Number of screen lines to use for the command-line.
set cmdwinheight=7 " Maximum command-line window height.
set ruler " Show the line and column number of the cursor position.
" Invisible chars.
set list
if s:is_windows
set listchars=tab:>.,trail:_,extends:>,precedes:<,nbsp:%
else
set listchars=tab:▸\ ,trail:_,extends:»,precedes:«,nbsp:%
endif
" Soft wrap.
if exists('+breakindent')
set wrap
" Every wrapped line will continue visually indented (same amount of space
" as the beginning of that line), thus preserving horizontal blocks of text.
set breakindent
else
set nowrap
endif
" Specify keys that move the cursor left/right to move to the previous/next line
" when the cursor is on the first/last character in the line.
set whichwrap+=b,s,<,>,~,[,]
" Wrap long lines at a character in 'breakat' rather than at the last character
" that fits on the screen.
set linebreak
" Specify characters that might cause a line break.
set breakat=\ \ ;:,./!?
" String to put at the start of lines that have been wrapped.
let &showbreak = '> '
" Highlight current cursor line.
set cursorline
" Show onely cursor line on current window.
autocmd MyAutoCmd WinLeave * set nocursorline
autocmd MyAutoCmd BufEnter,WinEnter,BufRead * set cursorline
" Default statusline.
" (if lightline.vim is not installed)
" let &statusline="%{winnr('$')>1?'['.winnr().'/'.winnr('$')"
" \ . ".(winnr('#')==winnr()?'#':'').']':''}\ "
" \ . "%{expand('%:t:.')}"
" \ . "\ %=%m%y%{'['.(&fenc!=''?&fenc:&enc).','.&ff.']'}"
" \ . "%{printf(' %5d/%d',line('.'),line('$'))}"
" Folding.
" set foldenable
" set foldmethod=expr
set foldmethod=marker
set foldcolumn=3
set foldnestmax=3
set fillchars=vert:\|
set commentstring=%s
" tabline.
" When the line with tab page labels will be displayed:
" 0: never
" 1: only if there are at least two tab pages
" 2: always
set showtabline=2
" View setting (:mkview).
set viewdir=$CACHE/vim_view
set viewoptions& viewoptions-=options viewoptions+=slash,unix
" }}}
" === Edit ==============================================================={{{1
" No beep and bells.
set noerrorbells
set vb t_vb=
set belloff=all
set viminfo='50,<1000,s100,\"50 " Settings for .viminfo.
set isfname-== " The characters included in file names and path names.
set virtualedit=block " Allow virtual editing in Visual block mode.
set updatetime=1000 " CursorHold time.
set keywordprg=:help " Program to use for the |K| command.
set spelllang=en_us " Language(s) to do spell checking for.
set spelllang+=cjk " Not spell checking Chinese, Japanese and other East Asian characters.
set report=0 " Threshold for reporting number of lines changed. (0:always)
set nostartofline " The cursor is kept in the same column (if possible) when move the cursor.
set switchbuf=useopen " This option controls the behavior when switching between buffers.
" Each item allows a way to backspace over something:
" indent allow backspacing over autoindent
" eol allow backspacing over line breaks (join lines)
" start allow backspacing over the start of insert
set backspace=indent,eol,start
" Display another buffer when current buffer isn't saved.
set hidden
" Indent.
set autoindent
set smartindent
set cindent
" <Tab>/spaces.
set tabstop=2 " Number of spaces that a <Tab> in the file counts for.
set shiftwidth=2 " Number of spaces to use for each step of (auto)indent.
set softtabstop=2 " Number of spaces that <Tab>/<BS> uses while editing.
set smarttab " A <Tab> in front of a line inserts blanks according to 'shiftwidth'.
set expandtab " Use spaces when <Tab> is inserted.
set shiftround " Round indent to multiple of 'shiftwidth'.
" Bracket match paren.
set showmatch " When a bracket is inserted, briefly jump to the matching one.
set matchtime=3 " The time to show the match.
set cpoptions-=m " A showmatch will wait half a second or until a character is typed.
set matchpairs& matchpairs+=<:>
" Search.
set ignorecase
set smartcase
set wrapscan " Searches wrap around the end of the file.
set hlsearch " Highlight all matches.
set noincsearch " Disable incremental search.
" Grep(:grep).
" Program to use for the :grep command.
" -i Ignorecase
" -n Show line number.
" -H Show file name.
" -E Use extended regular expression.
" $* The placeholder.
set grepprg=grep\ -inHE\ $*\ /dev/null
" command-line completion
set infercase " Ignorecase of match for keyword completion.
set wildmenu " command-line completion operates in an enhanced mode.
set wildchar=<tab> " Character you have to type to start wildcard expansion.
set wildmode=list,list:longest,full " Completion mode.
set wildoptions=tagfile " Change how command line completion is done.
set complete& complete+=k " Scan targets for completion.(k:dictionary) (default: .,w,b,u,t,i)
set completeopt=menuone " Completion type. (menu/menuone/longest/preview)
set pumheight=20 " The maximum number of items to show in the popup menu.
set history=1000 " The number of command-line history.
" Set a priority between files with almost the same name.
" If there are multiple matches, those files with an extension
" that is in the 'suffixes' option are ignored.
set suffixes=.bk,.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
" Tags.
" Show both the tag name and a tidied-up form of the search pattern
" (if there is one) as possible matches.
set showfulltag
if v:version < 703 || (v:version == 7.3 && !has('patch336'))
" Vim's bug.
set notagbsearch
endif
" autoread
" When a file has been detected to have been changed outside of Vim and
" it has not been changed inside of Vim, automatically read it again.
set autoread
" Check more closely than autoread.
autocmd MyAutoCmd WinEnter * checktime
" modeline.
" 1.If not include extraneous chars at the end of line.
" # vim: ft=sh sw=4 sts=4 ts=4 et
" 2.If include extraneous chars at the end of line.
" /* vim: set ft=c sw=4 sts=4 ts=4 et: */
" (default: 5)
set modeline
" Enable clipboard.
if (!has('nvim') || $DISPLAY != '') && has('clipboard')
if has('unnamedplus')
set clipboard& clipboard+=unnamedplus
else
set clipboard& clipboard+=unnamed
endif
endif
" Enable the mouse on a terminal.
" http://yskwkzhr.blogspot.jp/2013/02/use-mouse-on-terminal-vim.html
if has('mouse')
set mouse=a
if has('mouse_sgr')
set ttymouse=sgr
elseif v:version > 703 || v:version is 703 && has('patch632')
set ttymouse=sgr
else
" Enable mouse on screen.
set ttymouse=xterm2
endif
endif
" Disable paste mode and update diff automatically.
autocmd MyAutoCmd InsertLeave *
\ if &paste | setlocal nopaste | echo 'nopaste' | endif |
\ if &l:diff | diffupdate | endif
" Use autofmt.
if exists('autofmt#japanese#formatexpr')
set formatexpr=autofmt#japanese#formatexpr()
endif
" }}}
" === Misc 1 ============================================================ {{{1
" Remove trailing whitespace when the buffer is saved.
autocmd MyAutoCmd BufWritePre * :%s/\s\+$//ge
" Convert tabs to spaces when the buffer is saved.
"autocmd MyAutoCmd BufWritePre * :%s/\t/ /ge
" Restore cursor position.
" vimrc_example.vim is enable by default on Kaoriya.
autocmd MyAutoCmd BufReadPost * call <SID>restore_cursor_position()
function! s:restore_cursor_position() abort
let bt = &buftype
let ft = &filetype
if bt ==# 'nofile'
\ || ft ==# 'gitcommit' || ft ==# 'git-status' || ft ==# 'git-log'
\ || ft ==# 'git-diff' || ft ==# 'qf' || ft ==# 'quickrun'
\ || ft ==# 'qfreplace' || ft ==# 'ref'
if has('kaoriya')
normal! gg
normal! 0
echom 'Reset cursor position...'
endif
return
elseif !has('kaoriya') && line("'\"") > 0 && line("'\"") <= line("$")
normal! g`"
endif
endfunction
" Restore search option when move windows.
" http://d.hatena.ne.jp/tyru/20140129/localize_search_options
autocmd MyAutoCmd WinLeave *
\ let b:vimrc_pattern = @/
\ | let b:vimrc_hlsearch = &hlsearch
autocmd MyAutoCmd WinEnter *
\ let @/ = get(b:, 'vimrc_pattern', @/)
\ | let &l:hlsearch = get(b:, 'vimrc_hlsearch', &l:hlsearch)
" Enable filetype detect/plugin/indent.
" filetype detection:ON plugin:ON indent:ON
autocmd MyAutoCmd FileType,Syntax,BufNewFile,BufNew,BufRead
\ * call s:my_on_filetype()
function! s:my_on_filetype() abort
if &l:filetype == '' && bufname('%') == ''
return
endif
redir => filetype_out
silent! filetype
redir END
if filetype_out =~# 'OFF'
" Lazy loading
silent! filetype plugin indent on
syntax enable
filetype detect
endif
endfunction
" Open Quickfix window automatically.
autocmd MyAutoCmd QuickfixCmdPost make,grep,grepadd,vimgrep,Sgrep call s:auto_qf_open()
function! s:auto_qf_open() abort
if len(getqflist()) != 0
execute 'HierUpdate'
execute 'QuickfixStatusEnable'
execute 'QuickfixsignsEnable'
execute 'cwindow'
execute 'redraw!'
endif
endfunction
" Close unnecessary windows automatically.
autocmd MyAutoCmd WinEnter * call s:auto_qf_close()
function! s:auto_qf_close() abort
if tabpagenr('$') > 1
return
endif
for winnr in range(1, winnr('$'))
let buftype = getwinvar(winnr, '&buftype')
let ft = getwinvar(winnr, '&filetype')
if buftype ==# 'quickfix' || ft ==# 'nerdtree' || ft ==# 'help'
\ || ft ==# 'vimfiler' || ft ==# 'quickrun'
else
return
endif
endfor
quitall
endfunction
" Show modeline immediately when input <ESC>.
" http://gajumaru.ddo.jp/wordpress/?p=1076
" http://gajumaru.ddo.jp/wordpress/?p=1101
" http://yakinikunotare.boo.jp/orebase2/vim/dont_work_arrow_keys_in_insert_mode
" https://sites.google.com/site/fudist/Home/vim-nihongo-ban/vim-japanese/ime-control/ibus
" https://sites.google.com/site/fudist/Home/vim-nihongo-ban/vim-japanese/ime-control/ctrl-hat
" set timeout timeoutlen=3000 ttimeoutlen=100
if !has('gui_running')
set ttimeoutlen=10
augroup MyFastEscapeAu
autocmd!
autocmd InsertEnter * set timeoutlen=500
autocmd InsertLeave * set timeoutlen=1000
augroup END
endif
" Set the default skeleton file.
augroup MySkeltonAu
autocmd!
autocmd BufNewFile .editorconfig 0r $HOME/.vim/my_templates/skel.editorconfig
autocmd BufNewFile *.html 0r $HOME/.vim/my_templates/skel.html
autocmd BufNewFile *.py 0r $HOME/.vim/my_templates/skel.py
autocmd BufNewFile *.sh 0r $HOME/.vim/my_templates/skel.sh
autocmd BufNewFile *.user.js 0r $HOME/.vim/my_templates/skel.user.js
augroup END
" }}}
" === Misc 2: FileType ==================================================={{{1
augroup MyAutoCmdEx
autocmd!
" TODO: .vim/ftplugin/after/xxx.vim
" Set sw/sts/ts/et/tx/etc.
" sw : shiftwidth (インデント時に使用されるスペースの数)
" sts : softtabstop (0でないなら、タブを入力時、その数値分だけ半角スペースを挿入)
" ts : tabstop (タブを画面で表示する際の幅)
" et : expandtab (有効時、タブを半角スペースとして挿入)
" tw : textwidth
autocmd FileType gitcommit setlocal tw=72
autocmd FileType make setlocal noet
autocmd FileType asp,html,jsp,perl,php,xml syntax sync minlines=500 maxlines=1000
autocmd FileType diff,qf,qfreplace,quickrun,
\git,gitv,gitcommit,git-status,git-log,git-diff
\ setlocal nofoldenable nomodeline foldcolumn=0 foldlevel=0
augroup END
" }}}
" === Mappings 1: Edit ================================================== {{{1
" Enclose easily.
vnoremap { "zdi<C-V>{<C-R>z}<ESC>
vnoremap } "zdi<C-V>{<C-R>z}<ESC>
vnoremap [ "zdi<C-V>[<C-R>z]<ESC>
vnoremap ] "zdi<C-V>[<C-R>z]<ESC>
vnoremap ( "zdi<C-V>(<C-R>z)<ESC>
vnoremap ) "zdi<C-V>(<C-R>z)<ESC>
vnoremap " "zdi<C-V>"<C-R>z<C-V>"<ESC>
vnoremap ' "zdi'<C-R>z'<ESC>
" Indent.
nnoremap > >>
nnoremap < <<
vnoremap < <gv
vnoremap > >gv
xnoremap <Tab> >
xnoremap <S-Tab> <
" }}}
" === Mappings 2: Move ================================================== {{{1
" Display lines downward/upward.
" Differs from j/k when lines wrap.
silent! nnoremap <unique> j gj
silent! nnoremap <unique> k gk
nnoremap <Down> j
nnoremap <Up> k
" Move fast!
nnoremap H ^
xnoremap H ^
nnoremap L $
xnoremap L $h
nnoremap 1 0
nnoremap 0 ^
nnoremap 9 $
nnoremap ( %
nnoremap ) %
" Go to [count] older/newer position in change list.
" g; <-> g,
nnoremap <C-g> g;
" To the position where the last change was made.
nnoremap gb `.zz
" To the position where the cursor was the last time when Insert mode was stopped.
nnoremap gB `^zz
" Select the last edit text.
nnoremap <silent> <Leader>gc :<C-u>normal! `[v`]<CR>
vnoremap <silent> <Leader>gc :<C-u>normal! `[v`]<CR>
onoremap <silent> <Leader>gc :<C-u>normal! `[v`]<CR>
" }}}
" === Mappings 3: Buffer/Window/Tab ===================================== {{{1
" --- Buffer. ---
" Previous buffer.
nnoremap <silent> <F2> :<C-u>bp<CR>
" Next buffer.
nnoremap <silent> <F3> :<C-u>bn<CR>
" Delete buffer.
nnoremap <silent> <F4> :<C-u>call <SID>delete_buf()<CR>
function! s:delete_buf() abort
let win_num = winnr('$')
let prebuf = bufnr('#')
bnext
if bufnr('#') > 0 && bufnr('#') != prebuf && bufnr('%') != bufnr('#')
bdelete #
else
echo 'Last buffer!'
endif
if win_num == 1 && tabpagenr('$') > 1
tabclose
endif
endfunction
" --- Window. ---
" Disable 'q' recording to prevent malfunction.
nnoremap <silent><expr> q &readonly \|\| !&modifiable ? <SID>smart_close() : ""
nnoremap Q q
" q/ESC close temporary window.
autocmd MyAutoCmd FileType help,gitcommit,git-status,git-log,git-diff,
\qf,quickrun,qfreplace,ref,vcs-commit,vcs-status
\ nnoremap <buffer><silent> q :<C-u>call <SID>smart_close()<CR>
autocmd MyAutoCmd FileType help,qf,quickrun,ref
\ nnoremap <buffer><silent> <ESC> :<C-u>call <SID>smart_close()<CR>
autocmd MyAutoCmd FileType *
\ if (&readonly || !&modifiable) && &ft !=# 'vimfiler' && &ft !=# 'unite' |
\ nnoremap <buffer><silent> Q :<C-u>call <SID>smart_close()<CR> |
\ endif
autocmd MyAutoCmd FileType *
\ if (&readonly || !&modifiable)
\ && &ft !=# 'vimfiler' && &ft !=# 'unite' && !hasmapto('<ESC>', 'n') |
\ nnoremap <buffer><silent> <ESC> :<C-u>call <SID>smart_close()<CR> |
\ endif
function! s:smart_close() abort
if winnr('$') != 1
close
elseif &readonly || !&modifiable
quitall
endif
endfunction
" --- Tab pages. ---
set <C-Right>=[1;5C
set <C-Left>=[1;5D
" map [1;5D <C-Left>
" map [1;5C <C-Right>
" map! [1;5D <C-left>
" map! [1;5C <C-Right>
nnoremap [Tab] <Nop>
nmap <C-t> [Tab]
nnoremap <silent> [Tab]n :<C-u>tabnew<CR>
nnoremap <silent> [Tab]c :<C-u>tabclose<CR>
nnoremap <silent> [Tab]o :<C-u>tabonly<CR>
nnoremap <silent> <C-Right> :<C-u>execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$')<CR>
nnoremap <silent> <C-Left> :<C-u>tabp<CR>
command! -nargs=* -complete=file E tabnew <args>
silent! nunmap <Tab><Tab>
nnoremap <silent> <Tab> :call <SID>NextTabWindowBuffer()<CR>
nnoremap <silent> <S-Tab> :call <SID>PreviousTabWindowBuffer()<CR>
function! s:NextWindow() abort
if winnr('$') == 1
silent! normal! ``z.
else
wincmd w
endif
endfunction
function! s:NextTabWindowBuffer() abort
if tabpagenr('$') > 1
tabnext
elseif winnr("$") > 1
wincmd w
else
bnext
endif
endfunction
function! s:PreviousTabWindowBuffer() abort
if tabpagenr('$') > 1
tabprevious
elseif winnr("$") > 1
wincmd W
else
bprevious
endif
endfunction
command! SplitNicely call s:split_nicely()
function! s:split_nicely() abort
if winwidth(0) > 2 * &winwidth
vsplit
else
split
endif
wincmd p
endfunction
" }}}
" === Mappings 4: Tags/Quickfix/Folding ================================= {{{1
" --- tags. ---
nnoremap [Tag] <Nop>
nmap <Leader>t [Tag]
" Jump to the definition of the keyword under the cursor.
nnoremap <silent> [Tag]t <C-]>
" Jump to newer entry in tag stack.
nnoremap <silent> [Tag]n :<C-u>tag<CR>
" Jump to older entry in tag stack.
nnoremap <silent> [Tag]p :<C-u>pop<CR>
" --- QuickFix. ---
" Toggle QuickFix window.
function! s:toggle_qf_window() abort
for bufnr in range(1, winnr('$'))
if getwinvar(bufnr, '&buftype') ==# 'quickfix'
execute 'ccl'
return
endif
endfor
execute 'botright cw'
endfunction
nnoremap <silent> cw :call <SID>toggle_qf_window()<CR>
" Quickfix next/previous.
nnoremap <buffer> ]q :cnext<CR>
nnoremap <buffer> [q :cprevious<CR>
" --- Folding. ---
" Move to the start/end of the current open fold.
nnoremap zh [z
nnoremap zl ]z
" If press 'l' on fold, fold open.
nnoremap <expr> l foldclosed(line('.')) != -1 ? 'zo0' : 'l'
" If press 'l' on fold, range fold open.
xnoremap <expr> l foldclosed(line('.')) != -1 ? 'zogv0' : 'l'
" Close foldings smartly.
nnoremap <silent> z<Space> :<C-u>call <SID>smart_foldcloser()<CR>
function! s:smart_foldcloser() abort
if foldlevel('.') == 0
norm! zM
return
endif
let foldc_lnum = foldclosed('.')
norm! zc
if foldc_lnum == -1
return