/
.vimrc
2794 lines (2490 loc) · 77.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
" haya14busa's vimrc
" Author: haya14busa
" URL: http://haya14busa.com
" Source: https://github.com/haya14busa/dotfiles/
" Last Modified: 15 Feb 2014.
"=============================================================
" __ _____ __ __
" / /_ ____ ___ ______ < / // / / /_ __ ___________ _
" / __ \/ __ `/ / / / __ `/ / // /_/ __ \/ / / / ___/ __ `/
" / / / / /_/ / /_/ / /_/ / /__ __/ /_/ / /_/ (__ ) /_/ /
" /_/ /_/\__,_/\__, /\__,_/_/ /_/ /_.___/\__,_/____/\__,_/
" /____/
"
"=============================================================
" Startup {{{======================
" Note: Skip initialization for vim-tiny or vim-small.
if !1 | finish | endif
" release autogroup in MyVimrc {{{
augroup MyVimrc
autocmd!
augroup END
" https://github.com/rhysd/dotfiles/blob/master/vimrc
command! -nargs=* Autocmd autocmd MyVimrc <args>
command! -nargs=* AutocmdFT autocmd MyVimrc FileType <args>
function! s:hl_my_autocmd()
highlight def link myVimAutocmd vimAutoCmd
syntax match vimAutoCmd /\<\(Autocmd\|AutocmdFT\)\>/
endfunction
Autocmd BufWinEnter,ColorScheme *vimrc call s:hl_my_autocmd()
"}}}
" Echo startup time on start {{{
if has('vim_starting') && has('reltime')
" Shell: vim --startuptime filename -q; vim filename
" vim --cmd 'profile start profile.txt' --cmd 'profile file $HOME/.vimrc' +q && vim profile.txt
let s:startuptime = reltime()
Autocmd VimEnter * let s:startuptime = reltime(s:startuptime) | redraw
\ | echomsg 'startuptime: ' . reltimestr(s:startuptime)
endif
"}}}
"}}}
" NeoBundle {{{====================
if has('vim_starting')
set nocompatible
set runtimepath& runtimepath+=~/.vim/bundle/neobundle.vim/
endif
call neobundle#rc(expand('~/.vim/bundle/'))
" Let NeoBundle manage NeoBundle
NeoBundleFetch 'Shougo/neobundle.vim'
" NeoBundle Function {{{
" MyNeoBundle {{{
command! -nargs=1
\ MyNeoBundle
\ NeoBundle <args>, {
\ "base" : "~/.vim/myplugin/",
\ "type" : "nosync",
\ }
command! -nargs=1
\ MyNeoBundleLazy
\ NeoBundle <args>, {
\ "base" : "~/.vim/myplugin/",
\ "type" : "nosync",
\ "lazy" : 1,
\ }
"}}}
"}}}
" Synthesis {{{
" Unite {{{
NeoBundleLazy 'Shougo/unite.vim'
" NeoBundleLazy 'tsukkee/unite-help'
NeoBundleLazy 'Shougo/unite-help'
NeoBundleLazy 'ujihisa/unite-colorscheme'
NeoBundleLazy 'Shougo/unite-outline'
NeoBundleLazy 'osyo-manga/unite-fold'
NeoBundleLazy 'kmnk/vim-unite-giti'
NeoBundleLazy 'thinca/vim-unite-history'
NeoBundleLazy 'osyo-manga/unite-quickfix'
"}}}
NeoBundleLazy 'Shougo/vimfiler.vim'
NeoBundleLazy 'Shougo/vimshell.vim'
"}}}
" Writing {{{
" Shougo/neocomplete {{{
if has('lua') && v:version >= 703
NeoBundleLazy 'Shougo/neocomplete.vim'
else
NeoBundleLazy 'Shougo/neocomplcache.vim'
endif
"}}}
NeoBundleLazy 'Shougo/neosnippet.vim'
MyNeoBundle 'haya14busa-snippets'
NeoBundleLazy 'mattn/emmet-vim'
NeoBundleLazy 'deris/vim-rengbang' " vim plugin for sequencial numbering with pattern
NeoBundleLazy 'h1mesuke/vim-alignta'
NeoBundleLazy 'autodate.vim'
NeoBundleLazy 'tyru/caw.vim' " sophisticated comment plugin
"}}}
" Development {{{
NeoBundleLazy 'thinca/vim-quickrun'
NeoBundleLazy 'scrooloose/syntastic'
NeoBundleLazy 'koron/codic-vim' " Codic vim plugin
NeoBundleLazy 'rhysd/unite-codic.vim' " A unite.vim source for codic-vim.
"}}}
" Library {{{
NeoBundle 'Shougo/vimproc'
NeoBundle 'mattn/webapi-vim'
NeoBundleLazy 'vim-jp/vital.vim' " A comprehensive Vim utility functions for Vim plugins
NeoBundle 'osyo-manga/vital-over'
"}}}
" Document {{{
NeoBundleLazy 'thinca/vim-ref'
NeoBundle 'mojako/ref-sources.vim'
NeoBundle 'tokuhirom/jsref'
NeoBundle 'mustardamus/jqapi'
NeoBundle 'soh335/vim-ref-jquery'
"}}}
" Extend Basic Vim Commands {{{
" Matching
NeoBundle 'matchit.zip'
" Yank
NeoBundleLazy 'LeafCage/yankround.vim'
" Undo
NeoBundleLazy 'sjl/gundo.vim'
" Visual mode
NeoBundleLazy 'kana/vim-niceblock'
" Search
NeoBundleLazy 'thinca/vim-visualstar'
NeoBundleLazy 'osyo-manga/vim-anzu'
NeoBundleLazy 'osyo-manga/vim-over' " :substitute preview
"}}}
" Motion {{{
MyNeoBundleLazy 'vim-easymotion'
MyNeoBundleLazy 'vim-easyoperator-line'
MyNeoBundleLazy 'vim-easyoperator-phrase'
MyNeoBundleLazy 'vim-lazy-lines'
NeoBundleLazy 'rhysd/clever-f.vim' " Extended f, F, t and T key mappings for Vim.
NeoBundleLazy 'rhysd/accelerated-jk'
"}}}
" Text Object {{{
NeoBundleLazy 'kana/vim-textobj-user'
NeoBundleLazy 'kana/vim-textobj-entire' " ae, ie
NeoBundleLazy 'kana/vim-textobj-fold' " az, iz
NeoBundleLazy 'kana/vim-textobj-indent' " ai, ii
NeoBundleLazy 'kana/vim-textobj-line' " al, il
NeoBundleLazy 'kana/vim-textobj-syntax' " ay, iy
NeoBundleLazy 'kana/vim-textobj-django-template' " adb, idb
NeoBundleLazy 'thinca/vim-textobj-between' " af{char}, if{char}
NeoBundleLazy 'mattn/vim-textobj-url' " au, iu
NeoBundleLazy 'osyo-manga/vim-textobj-multiblock' " ab, ib
NeoBundleLazy 'lucapette/vim-textobj-underscore' " a_, i_
NeoBundleLazy 'h1mesuke/textobj-wiw' " a,w a,e
" to surround vim objects with a pair of identical chars
" TODO: Make it lazy or use vim-operator-surround
NeoBundle 'tpope/vim-surround'
NeoBundle 'tpope/vim-repeat'
" Operator
NeoBundleLazy 'kana/vim-operator-user'
NeoBundleLazy 'kana/vim-operator-replace'
"NeoBundle 'rhysd/vim-operator-surround'
"}}}
" Git {{{
NeoBundle 'tpope/vim-fugitive'
NeoBundleLazy 'gregsexton/gitv'
NeoBundle 'mhinz/vim-signify'
NeoBundleLazy 'thinca/vim-openbuf'
NeoBundleLazy 'Shougo/vim-vcs', {
\ 'depends' : 'thinca/vim-openbuf',
\ 'autoload' : {'commands' : 'Vcs'},
\ }
"}}}
" UI {{{
NeoBundle 'itchyny/lightline.vim'
NeoBundleLazy 'nathanaelkane/vim-indent-guides'
NeoBundleLazy 't9md/vim-quickhl' " quickly highlight <cword> or visually selected word
"TODO
NeoBundleLazy 'osyo-manga/vim-automatic', {
\ 'depends' : [ 'osyo-manga/vim-gift', 'osyo-manga/vim-reunions' ] }
" }}}
" Utility {{{
" NeoBundle 'kana/vim-submode' " Vim plugin: Create your own submodes
NeoBundle 'thinca/vim-submode', {
\ 'rev' : 'my-master',
\ 'name' : 'vim-submode',
\ }
NeoBundleLazy 'tyru/open-browser.vim'
"}}}
" Application {{{
NeoBundleLazy 'itchyny/calendar.vim' " A calendar application for Vim
"}}}
" Memo {{{
NeoBundleLazy 'mattn/gist-vim'
NeoBundleLazy 'Shougo/junkfile.vim' " Create temporary file for memo, testing, ...
"}}}
" Filetype {{{
NeoBundle 'pangloss/vim-javascript'
NeoBundle 'wavded/vim-stylus'
NeoBundle 'hail2u/vim-css3-syntax'
NeoBundle 'kchmck/vim-coffee-script'
NeoBundle 'othree/html5.vim'
NeoBundle 'plasticboy/vim-markdown'
" Python {{{
NeoBundleLazy 'davidhalter/jedi-vim'
NeoBundleLazy 'heavenshell/vim-pydocstring'
NeoBundleLazy 'tell-k/vim-autopep8'
NeoBundleLazy 'hynek/vim-python-pep8-indent'
"}}}
" Scheme {{{
NeoBundleLazy 'aharisu/vim_goshrepl'
NeoBundleLazy 'kien/rainbow_parentheses.vim'
" }}}
"}}}
" Fold {{{
NeoBundle 'LeafCage/foldCC'
NeoBundleLazy 'tmhedberg/SimpylFold' "for Python
NeoBundleLazy 'vim-scripts/CSS-one-line--multi-line-folding'
"}}}
" Japanese {{{
" NeoBundleLazy 'haya14busa/vim-migemo' "use migemo of easymotion
NeoBundle 'vim-jp/vimdoc-ja' " A project which translate Vim documents into Japanese.
" NeoBundle 'tyru/skk.vim'
"}}}
" ColorScheme {{{
NeoBundle 'tomasr/molokai'
NeoBundle 'vim-scripts/Wombat'
NeoBundle 'altercation/vim-colors-solarized'
NeoBundle 'nanotech/jellybeans.vim'
NeoBundle 'w0ng/vim-hybrid'
NeoBundle 'vim-scripts/twilight'
NeoBundle 'jonathanfilip/vim-lucius'
NeoBundle 'jpo/vim-railscasts-theme'
NeoBundle 'vim-scripts/rdark'
NeoBundle 'djjcast/mirodark'
NeoBundle 'sjl/badwolf'
NeoBundle 'cocopon/iceberg.vim' " A dark color scheme for Vim, came from Antarctica
NeoBundle 'reedes/vim-colors-pencil'
"}}}
" Vim script {{{
NeoBundle 'mattn/learn-vimscript'
NeoBundleLazy 'thinca/vim-prettyprint'
NeoBundleLazy 'tyru/capture.vim' " Show Ex command output in buffer
NeoBundleLazy 'kana/vim-vspec' " Vim plugin: Testing framework for Vim script
NeoBundleLazy 'thinca/vim-editvar' " Edits vim variable in buffer.
NeoBundleLazy 'tyru/restart.vim' " Restart your gVim
NeoBundleLazy 'thinca/vim-ft-help_fold', {
\ 'filetypes' : 'help'
\ }
"}}}
" Others {{{
NeoBundleLazy 'pentie/VimRepress' "WordPress
NeoBundleLazy 'basyura/TweetVim' " twitter client for vim
NeoBundleLazy 'basyura/twibill.vim' " twitter api wrapper like a Rubytter.rb ... maybe
NeoBundleLazy 'basyura/J6uil.vim'
NeoBundle 'bohrshaw/vim-vimperator-syntax'
NeoBundleLazy 'supermomonga/thingspast.vim'
NeoBundleLazy 'rbtnn/puyo.vim'
NeoBundleLazy 'thinca/vim-scouter'
"}}}
filetype plugin indent on
" END NeoBundle}}}
" Vim Setup {{{====================
" Basic Options {{{
if exists('&ambiwidth')
" For Ubuntu: gnome-terminal, terminator, guake
" /bin/sh -c "VTE_CJK_WIDTH=1 terminator -m"
" /bin/sh -c "VTE_CJK_WIDTH=1 gnome-terminal --disable-factory"
" /bin/sh -c "VTE_CJK_WIDTH=1 guake"
" https://gist.github.com/sgk/5991138
set ambiwidth=double "Use twice the width of ASCII characters for Multibyte
endif
set autoread "Automatically read file again which has been changed outside of Vim
set backspace=indent,eol,start "Working of <BS>,<Del>,CTRL-W,CTRL-U
if has('unnamedplus')
set clipboard& clipboard=unnamedplus "uses the clipboard register '+'
else
set clipboard& clipboard+=unnamed,autoselect
endif
set cmdheight=1 "Number of screen lines to use for the command-line
set cmdwinheight=5 "Number of screen lines to use for the command-line window
set display=lastline "Display as much as possible of the last line
set encoding=utf-8 "Sets the character encoding used inside Vim
set fileencodings=utf-8,iso-2022-jp,euc-jp,sjis "A list of character encodings
set fileformats=unix,dos,mac "This gives the end-of-line (<EOL>) formats
set formatoptions-=r,o " Turn off Automatically comment out when line break
set grepprg=internal "Program to use for the :grep command
set helpheight=12 " Minimal initial height of the help window
set hidden "Display another buffer when current buffer isn't saved.
set history=1024 "Amount of Command history
set infercase "Ignore case on insert completion.
set keywordprg=:help " Open Vim internal help by K command
set laststatus=2 "Always display statusline
set matchpairs& matchpairs+=<:> "Characters that form pairs
set matchtime=3 "Tenths of a second to show the matching paren
set modeline "Set Vim local buffer option to specific file
set noerrorbells "Don't ring the bell for error messages
set novisualbell "Don't use visual bell instead of beeping
set nrformats-=octal "Bases Vim will consider for numbers(Ctrl-a,Ctrl-x)
set number "Print the line number in front of each line
set ruler "Show the line and column number of the cursor position
set shortmess& shortmess+=I "Don't give the message when starting Vim :intro
set showcmd "Show (partial) command in the last line of the screen
set showmatch "Briefly jump to the matching one
set spelllang=en,cjk "Spell checking language
set textwidth=0 "Maximum width of text that is being inserted
set viewoptions=cursor,folds "Changes the effect of the :mkview command
set viminfo+=! "Store information when you exit Vim for later
set virtualedit=block "Cursor can be positioned virtually when Visual-block mode
set whichwrap=b,s,h,l,[,],<,> "Allow specified keys to move to the previous/next line
set wrap "Lines longer than the width of the window will wrap
set wrapscan "Searches wrap around the end of the file
" Tab Basic Settings {{{
set autoindent "Copy indent from current line when starting a new line
set expandtab "Use the appropriate number of spaces to insert a <Tab>
set shiftround "Round indent to multiple of 'shiftwidth'
set shiftwidth=4 "Number of spaces to use for each step of (auto)indent
set softtabstop=4 "Number of spaces that a <Tab> counts for while editing operations
set tabstop=4 "Number of spaces that a <Tab> in the file counts for
"}}}
" Search Basic Settings {{{
set incsearch "Incremental searching
set ignorecase "Ignore case in search patterns
set smartcase "Override the ignorecase option if the pattern contains upper case
set hlsearch | nohlsearch "Highlight search patterns, support reloading
"}}}
" Backup Settings {{{
"Don't create backup
set nobackup "Don't make a backup before overwriting a file
set nowritebackup "Don't make a backup before overwriting a file
set backupdir-=. "List of directories for the backup file
"}}}
" Swap Settings {{{
set swapfile "Use a swapfile for the buffer
set directory-=. "List of directory names for the swap file
"}}}
" Undo Basic {{{
if has('persistent_undo')
set undofile "Automatically saves undo history
set undoreload=1000 "Save the whole buffer for undo when reloading it
let &undodir=&directory "List of directory names for undo files
endif
"}}}
" Wildmenu {{{
set wildmenu " Command line autocompletion
set wildmode=list:longest,full "Shows all the options
set wildignore& " A file that matches with one of these patterns is ignored
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.bak,*.?~,*.??~,*.???~,*.~ " Backup files
set wildignore+=*.luac " Lua byte code
set wildignore+=*.jar " Java archives
set wildignore+=*.pyc " Python byte code
set wildignore+=*.stats " Pylint stats
" }}}
" Fold Basic Settings "{{{
set foldenable "Enable fold
set foldlevel=100 "Folds with a higher level will be closed
"}}}
" Colorscheme {{{
if has('vim_starting')
syntax enable
set background=dark
set t_Co=256
if &t_Co < 256
colorscheme default
else
try
colorscheme molokai
catch
colorscheme desert
endtry
endif
endif
"}}}
"}}}
" Open & AutoReload .vimrc {{{
command! EVimrc e $MYVIMRC
command! ETabVimrc tabnew $MYVIMRC
command! SoVimrc source $MYVIMRC
Autocmd BufWritePost *vimrc source $MYVIMRC
Autocmd BufWritePost *gvimrc if has('gui_running') source $MYGVIMRC
"}}}
" Close Vim help by q {{{
AutocmdFT help nnoremap <buffer> q <C-w>c
AutocmdFT help nnoremap <buffer> ;q q
AutocmdFT help nnoremap <buffer> Q q
"}}}
" Useful Keymaps{{{
" Escape Keymaps {{{
inoremap <silent> jj <ESC>
inoremap <silent> <C-c> <ESC>
"}}}
" Breakline with Enter {{{
nnoremap <CR> o<ESC>
"}}}
" For Undo Revision, Break Undo Sequence "{{{
inoremap <CR> <C-]><C-G>u<CR>
inoremap <C-h> <C-g>u<C-h>
inoremap <BS> <C-g>u<BS>
inoremap <Del> <C-g>u<Del>
inoremap <C-d> <C-g>u<Del>
inoremap <C-w> <C-g>u<C-w>
inoremap <C-u> <C-g>u<C-u>
"}}}
" Motion {{{
" Normal Mode {{{
nnoremap j gj
vnoremap j gj
nnoremap gj j
vnoremap gj j
nnoremap k gk
vnoremap k gk
nnoremap gk k
vnoremap gk k
nnoremap - $
"}}}
" Insert & Comandline Mode "{{{
inoremap <C-b> <Left>
inoremap <C-f> <Right>
inoremap <C-a> <Home>
inoremap <C-e> <End>
cnoremap <C-b> <Left>
cnoremap <C-f> <Right>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
" Word Motion in Insert Mode
inoremap <M-w> <S-Right>
inoremap <M-b> <S-Left>
"}}}
" Scroll {{{
nnoremap <C-e> <C-e>j
nnoremap <C-y> <C-y>k
nnoremap <C-f> <C-f>zz
nnoremap <C-b> <C-b>zz
nnoremap <Down> <C-e><C-e><C-e><C-e><C-e><C-e><C-e><C-e><C-e><C-e>
nnoremap <Up> <C-y><C-y><C-y><C-y><C-y><C-y><C-y><C-y><C-y><C-y>
vnoremap <Down> <C-e><C-e><C-e><C-e><C-e><C-e><C-e><C-e><C-e><C-e>
vnoremap <Up> <C-y><C-y><C-y><C-y><C-y><C-y><C-y><C-y><C-y><C-y>
nnoremap <Space>j <C-f>zz
nnoremap <Space>k <C-b>zz
vnoremap <Space>j <C-f>zz
vnoremap <Space>k <C-b>zz
"}}}
"}}}
" Paste in insert and Command-line mode"{{{
inoremap <C-y><C-y> <C-r>+
cnoremap <C-y><C-y> <C-r>+
"}}}
" Vertical Paste"{{{
vnoremap <C-p> I<C-r>+<ESC><ESC>
"}}}
" Select pasted text {{{
nnoremap <expr>gp '`['.strpart(getregtype(),0,1).'`]'
"}}}
" Command line History {{{
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
"}}}
" Save as root"{{{
cnoremap w!! w !sudo tee > /dev/null %
"}}}
" From the cursor to the end of line {{{
" Select from cursor position to end of line
" vnoremap v $h " -> D,C,Y
" Yank from cursor position to end of line
nnoremap Y y$
"}}}
" Spelling Keymaps {{{
" turn on the spell checking and set the English language
nnoremap <Leader>sp :set spell!<CR>
" }}}
" Get info"{{{
" get the total of lines, words, chars and bytes (and for the current position)
nnoremap <Leader>gi g<C-G>
"}}}
" Relative Number "{{{
nnoremap <Leader><Leader>r :<C-u>set relativenumber!<CR>
"}}}
" Repeat on every line {{{
" repeat last command for each line of a visual selection
vnoremap . :normal .<CR>
" replay @q macro for each line of a visual selection
vnoremap @q :normal @q<CR>
"}}}
" Search {{{
" always 'very magic'
nnoremap / /\v
" search within visual block
vnoremap / <esc>/\v%V
" clear status
nnoremap <silent><Esc><Esc>
\ :<C-u>nohlsearch<CR>
" Automatically escape '/'
cnoremap <expr>/ getcmdtype() == '/' ? '\/' : '/'
nnoremap & :&&<CR>
xnoremap & :&&<CR>
"}}}
" select last inserted text
nnoremap gV `[v`]
" Don't use register by x
nnoremap x "_x
" Keymap candidate
" n
" ---
" U
" S
" X
"}}}
" set nopaste when Insertleave"{{{
Autocmd InsertLeave * set nopaste
"}}}
" Show invisibles {{{
" Shortcut to rapidly toggle `set list`
nnoremap <silent> <Leader>l :<C-u>set list!<CR>
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
"Invisible character colors
hi NonText guifg=#4a4a59
hi SpecialKey guifg=#4a4a59
" Highlight End-of-Line & Zenkaku Whitespace {{{
function! s:hl_trailing_spaces() "{{{
" Test
highlight! link TrailingSpaces Error
syntax match TrailingSpaces containedin=ALL /\s\+$/
endfunction "}}}
function! s:hl_zenkaku() "{{{
highlight link ZenkakuSpace Error
syntax match ZenkakuSpace containedin=ALL / /
endfunction "}}}
Autocmd BufWinEnter,ColorScheme * call s:hl_trailing_spaces()
Autocmd BufWinEnter,ColorScheme * call s:hl_zenkaku()
"}}}
"}}}
" Restore last cursor position when open a file {{{
Autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
"}}}
" Add Endtagcomment function {{{
" Description"{{{
" Before
" <div id="hoge" class="fuga">
" ...
" </div>
"
" After
" <div id="hoge" class="fuga">
" ...
" </div><!-- /div#hoge.fuga -->
"}}}
function! Endtagcomment() "{{{
let reg_save = @@
try
silent normal! vaty
catch
execute "normal! \<Esc>"
echohl ErrorMsg
echo 'no match html tags'
echohl None
return
endtry
let html = @@
let start_tag = matchstr(html, '\v(\<.{-}\>)')
let tag_name = matchstr(start_tag, '\v([a-zA-Z]+)')
let id = ''
let id_match = matchlist(start_tag, '\vid\=["'']([^"'']+)["'']')
if exists('id_match[1]')
let id = '#' . id_match[1]
endif
let class = ''
let class_match = matchlist(start_tag, '\vclass\=["'']([^"'']+)["'']')
if exists('class_match[1]')
let class = '.' . join(split(class_match[1], '\v\s+'), '.')
endif
execute "normal! `>va<\<Esc>`<"
let comment = s:endtagcommentFormat
let comment = substitute(comment, '{%tag_name}', tag_name, 'g')
let comment = substitute(comment, '{%id}', id, 'g')
let comment = substitute(comment, '{%class}', class, 'g')
let @@ = comment
normal! %""p
let @@ = reg_save
endfunction "}}}
let s:endtagcommentFormat = '<!-- /{%tag_name}{%id}{%class} -->'
nnoremap ,t :<C-u>call Endtagcomment()<CR>
"}}}
" Fold {{{
" Change Keymap for Fold {{{
noremap [fold] <nop>
nmap <Space> [fold]
vmap <Space> [fold]
noremap [fold]j zj
noremap [fold]k zk
noremap [fold]n ]z
noremap [fold]p [z
noremap <silent>[fold]h :<C-u>call <SID>smart_foldcloser()<CR>
noremap [fold]l zo
noremap [fold]L zO
noremap [fold]a za
noremap [fold]m zM
noremap [fold]i zMzvzz
noremap [fold]r zR
noremap [fold]f zf
noremap [fold]d zd
nnoremap <expr>l foldclosed('.') != -1 ? 'zo' : 'l'
nnoremap [fold][ :<C-u>call <SID>put_foldmarker(0)<CR>
nnoremap [fold]] :<C-u>call <SID>put_foldmarker(1)<CR>
"}}}
" Leafcage/foldCC {{{
if neobundle#tap('foldCC')
call neobundle#config({})
set foldmethod=marker
set foldtext=FoldCCtext()
set foldcolumn=0
set fillchars=vert:\|
noremap [fold]g :<C-u>echo FoldCCnavi()<CR>
call neobundle#untap()
endif " }}}
"}}}
" smart_foldcloser {{{
function! s:smart_foldcloser()
if foldlevel('.') == 0
norm! zM
return
endif
let foldc_lnum = foldclosed('.')
norm! zc
if foldc_lnum == -1
return
endif
if foldclosed('.') != foldc_lnum
return
endif
norm! zM
endfunction
"}}}
" put foldmarker {{{
function! s:put_foldmarker(foldclose_p)
let crrstr = getline('.')
let padding = crrstr=='' ? '' : crrstr=~'\s$' ? '' : ' '
let [cms_start, cms_end] = ['', '']
let outside_a_comment_p = synIDattr(synID(line('.'), col('$')-1, 1), 'name') !~? 'comment'
if outside_a_comment_p
let cms_start = matchstr(&cms,'\V\s\*\zs\.\+\ze%s')
let cms_end = matchstr(&cms,'\V%s\zs\.\+')
endif
let fmr = split(&fmr, ',')[a:foldclose_p]. (v:count ? v:count : '')
exe 'norm! A'. padding. cms_start. fmr. cms_end
endfunction
"}}}
" Tab {{{
" Tab KeyMaps {{{
nnoremap t; t
nmap t <nop>
nnoremap tl gt
nnoremap th gT
nnoremap to :<C-u>edit<Space>
nnoremap tt :<C-u>tabnew<Space>
nnoremap <silent> td :<C-u>tabclose<CR>
nnoremap <silent> t] :<C-u>buffer<CR>
nnoremap <silent> tn :<C-u>bnext<CR>
nnoremap <silent> tp :<C-u>bprevious<CR>
nnoremap <silent> tD :<C-u>bdelete<CR>
nnoremap <silent> tL :<C-u>buffers<CR>
"}}}
" Tab jump {{{
for n in range(1, 9)
execute 'nnoremap <silent> t'.n ':<C-u>tabnext'.n.'<CR>'
endfor
"}}}
" MoveToNewTab {{{
" http://www.sopht.jp/blog/index.php?/archives/445-vim.html
nnoremap <silent> tm :<C-u>call <SID>MoveToNewTab()<CR>
function! s:MoveToNewTab()
tab split
tabprevious
if winnr('$') > 1
close
elseif bufnr('$') > 1
buffer #
endif
tabnext
endfunction
"}}}
" Tab Help {{{
command! -nargs=? Ht tab help <args>
command! -nargs=? Hv vertical belowright help <args>
nnoremap <Space>t :<C-u>tab help<Space>
nnoremap <Space>v :<C-u>vertical belowright help<Space>
"}}}
" TabLine {{{
set tabline=%!MakeTabLine()
function! MakeTabLine()
let s = ''
for n in range(1, tabpagenr('$'))
if n == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
endif
let s .= '%' . n . 'T'
let s .= ' %{MakeTabLabel(' . n . ')} '
let s .= '%#TabLineFill#%T'
let s .= '|'
endfor
let s .= '%#TabLineFill#%T'
let s .= '%=%#TabLine#'
let s .= '%{fnamemodify(getcwd(), ":~:h")}%<'
return s
endfunction
function! MakeTabLabel(n)
let bufnrs = tabpagebuflist(a:n)
let bufnr = bufnrs[tabpagewinnr(a:n) - 1]
let bufname = bufname(bufnr)
if bufname == ''
let bufname = '[No Name]'
else
let bufname = fnamemodify(bufname, ":t")
endif
let no = len(bufnrs)
if no == 1
let no = ''
endif
let mod = len(filter(bufnrs, 'getbufvar(v:val, "&modified")')) ? '+' : ''
let sp = (no . mod) == '' ? '' : ' '
let s = no . mod . sp . bufname
return s
endfunction"}}}
"}}}
" Use command-line window {{{
nnoremap : q:
vnoremap : q:
Autocmd CmdwinEnter * call s:init_cmdwin()
function! s:init_cmdwin() "{{{
silent! 1,$-20 delete _ | call cursor('$', 0)
let b:neocomplete_sources_list = ['vim_complete']
nnoremap <silent><buffer>q :<C-u>quit<CR>
nnoremap <silent><buffer><CR> <CR>
inoremap <silent><buffer><expr><CR> pumvisible() ? "\<C-y>\<CR>" : "\<CR>"
nnoremap <silent><buffer><TAB> :<C-u>quit<CR>
nnoremap <silent><buffer><Space> <CR>q:
nnoremap <silent><buffer>;; <CR>q:
inoremap <silent><buffer>;; <CR>q:
" Completion.
inoremap <silent><buffer><expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
inoremap <silent><buffer><expr><C-p> pumvisible() ? "\<C-p>" : "\<C-o>0\<UP>"
inoremap <silent><buffer><expr><C-n> pumvisible() ? "\<C-n>" : "\<C-o>0\<DOWN>"
startinsert!
endfunction "}}}
"}}}
" Create Directory Automatically {{{
Autocmd BufWritePre * call s:auto_mkdir(expand('<afile>:p:h'), v:cmdbang)
function! s:auto_mkdir(dir, force) " {{{
if !isdirectory(a:dir) && (a:force ||
\ input(printf('"%s" does not exist. Create? [y/N]', a:dir)) =~? '^y\%[es]$')
call mkdir(iconv(a:dir, &encoding, &termencoding), 'p')
endif
endfunction " }}}
"}}}
" Git Setting {{{
" for git mergetool
if &diff
noremap <Leader>1 :diffget LOCAL<CR>
noremap <Leader>2 :diffget BASE<CR>
noremap <Leader>3 :diffget REMOTE<CR>
noremap <Leader>u :<C-u>diffupdate<CR>
noremap u u:<C-u>diffupdate<CR>
endif
" Update diff
Autocmd InsertLeave * if &l:diff | diffupdate | endif
" Spell check in git commit
AutocmdFT gitcommit setlocal nofoldenable spell
" Set textwidth
AutocmdFT gitcommit setlocal textwidth=72
" Enter Insert mode in git commit
Autocmd VimEnter COMMIT_EDITMSG if getline(1) == '' | execute 1 | startinsert | endif
" git blame {{{
function! s:git_blame(fname, ...)
execute 'lcd' fnamemodify(a:fname, ':p:h')
let range = (a:0==0 ? line('.') : a:1.','.a:2)
let errfmt = &errorformat
set errorformat=.*
cgetexpr system('git blame -L '.range.' '.fnamemodify(a:fname, ':p'))
let &errorformat = errfmt
Unite quickfix -no-start-insert
endfunction
command! -nargs=0 GitBlameThisLine call <SID>git_blame(expand('%'))
command! -range GitBlameRange call <SID>git_blame(expand('%'), <line1>, <line2>)
nnoremap <silent><Leader>gb :<C-u>GitBlameThisLine<CR>
vnoremap <silent><Leader>gb :GitBlameRange<CR>
"}}}
"}}}
" Filetypes "{{{====================
" Stylus {{{
Autocmd BufRead,BufNewFile,BufReadPre *.styl setlocal filetype=sass
AutocmdFT sass setlocal sw=2 sts=2 ts=2 et
Autocmd BufWritePost,FileWritePost *.styl silent !stylus <afile> -u nib >/dev/null
"}}}
" CoffeeScript {{{
Autocmd BufRead,BufNewFile,BufReadPre *.coffee setlocal filetype=coffee
AutocmdFT coffee setlocal sw=2 sts=2 ts=2 et
Autocmd BufWritePost,FileWritePost *.coffee silent CoffeeMake! -cb | cwindow | redraw!
"}}}
" Sass {{{
function! Sass_convert()
let scss = expand('%:p')
let css = substitute(scss, 'scss$', 'css', '')
let cmd = printf('sass --compass -i /usr/local/lib/ruby/gems/1.9.1/gems/compass-0.12.2/frameworks/compass/stylesheets/compass %s %s', scss, css)
let res = system(cmd)
if res != ''
echo res
endif
endfunction
Autocmd BufWritePost *.scss call Sass_convert()
"}}}
" Markdown {{{
Autocmd BufRead,BufNewFile *.md set filetype=markdown
AutocmdFT markdown setlocal sw=2 sts=2 ts=2 et
"}}}
"}}}
" end vim setup}}}
" Secret {{{=======================
if filereadable(expand('~/.secret_vimrc'))
execute 'source' expand('~/.secret_vimrc')
endif
" }}}
" Plugin settings {{{==============
" " author/sample {{{
" if neobundle#tap('plugin-name')
" " Config {{{
" call neobundle#config({
" \ 'autoload' : {
" \ 'unite_sources' : [
" \ 'help',
" \ ],
" \ }
" \ })
" " }}}
" function! neobundle#tapped.hooks.on_source(bundle) "{{{
" endfunction "}}}
" " Setting {{{
" "}}}
" call neobundle#untap()
" endif
" " }}}