forked from yous/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
1134 lines (1013 loc) · 31.5 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
" vim: set foldmethod=marker:
" =============================================================================
" Requirement Checks: {{{
" =============================================================================
function! s:VersionRequirement(val, min)
for idx in range(0, len(a:min) - 1)
let v = get(a:val, idx, 0)
if v < a:min[idx]
return 0
elseif v > a:min[idx]
return 1
endif
endfor
return 1
endfunction
if has('python')
redir => s:pyv
silent python import platform; print(platform.python_version())
redir END
let s:python26 = s:VersionRequirement(
\ map(split(split(s:pyv)[0], '\.'), 'str2nr(v:val)'), [2, 6])
else
let s:python26 = 0
endif
if !empty(&rtp)
let s:vimfiles = split(&rtp, ',')[0]
else
echohl ErrorMsg
echomsg 'Unable to determine runtime path for Vim.'
echohl NONE
endif
" }}}
" =============================================================================
" Vim Plug: {{{
" =============================================================================
set nocompatible
filetype off
" Install vim-plug if it isn't installed and call plug#begin() out of box
function! s:DownloadVimPlug()
if !exists('s:vimfiles')
return
endif
if empty(glob(s:vimfiles . '/autoload/plug.vim'))
let plug_url = 'https://github.com/junegunn/vim-plug.git'
let tmp = tempname()
let new = tmp . '/plug.vim'
try
let out = system(printf('git clone --depth 1 %s %s', plug_url, tmp))
if v:shell_error
echohl ErrorMsg
echomsg 'Error downloading vim-plug: ' . out
echohl NONE
return
endif
if !isdirectory(s:vimfiles . '/autoload')
call mkdir(s:vimfiles . '/autoload', 'p')
endif
call rename(new, s:vimfiles . '/autoload/plug.vim')
" Install plugins at first
autocmd VimEnter * PlugInstall | quit
finally
if isdirectory(tmp)
let dir = '"' . escape(tmp, '"') . '"'
silent call system((has('win32') ? 'rmdir /S /Q ' : 'rm -rf ') . dir)
endif
endtry
endif
call plug#begin(s:vimfiles . '/plugged')
endfunction
call s:DownloadVimPlug()
" Colorscheme
Plug 'yous/vim-open-color'
" General
" Preserve missing EOL at the end of text files
Plug 'yous/PreserveNoEOL'
" EditorConfig
if executable('editorconfig') == 1 || has('python3') || s:python26
Plug 'editorconfig/editorconfig-vim'
endif
if !has('win32')
if !has('win32unix') &&
\ (v:version >= 704 || v:version == 703 && has('patch598')) &&
\ executable('cmake') && (has('python3') || s:python26)
function! s:BuildYCM(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.force
let options = []
let requirements = [['clang', '--clang-completer'],
\ ['go', '--gocode-completer'],
\ ['cargo', '--racer-completer']]
for r in requirements
if executable(r[0])
let options += [r[1]]
endif
endfor
execute '!./install.py ' . join(options, ' ')
endif
endfunction
" A code-completion engine for Vim
let BuildYCMRef = function('s:BuildYCM')
Plug 'Valloric/YouCompleteMe', { 'do': BuildYCMRef }
unlet BuildYCMRef
" Generates config files for YouCompleteMe
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
endif
" A command-line fuzzy finder written in Go
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" A Vim plugin for looking up words in an online thesaurus
Plug 'beloglazov/vim-online-thesaurus'
endif
" Enhancing in-buffer search experience
Plug 'junegunn/vim-slash'
" Directory viewer for Vim
Plug 'justinmk/vim-dirvish'
" Go to Terminal or File manager
Plug 'justinmk/vim-gtfo'
" Autocomplete if end
Plug 'tpope/vim-endwise'
" Vim sugar for the UNIX shell commands
Plug 'tpope/vim-eunuch'
" Syntax checking plugin
Plug 'scrooloose/syntastic'
" Automated tag file generation and syntax highlighting of tags
if executable('ctags')
Plug 'xolox/vim-misc' |
Plug 'xolox/vim-shell' |
Plug 'xolox/vim-easytags'
endif
" Vim Git runtime files
Plug 'tpope/vim-git'
" Git wrapper
Plug 'tpope/vim-fugitive'
" A git commit browser, requires tpope/vim-fugitive
Plug 'junegunn/gv.vim'
" Run interactive commands inside a Vim buffer
Plug 'yous/conque', { 'on': [
\ 'ConqueTerm',
\ 'ConqueTermSplit',
\ 'ConqueTermVSplit',
\ 'ConqueTermTab'] }
" Motions and text changing
" Provide CamelCase motion through words
Plug 'bkad/CamelCaseMotion'
" Vim motions on speed!
Plug 'easymotion/vim-easymotion'
" Extended % matching
Plug 'matchit.zip'
" Simplify the transition between multiline and single-line code
Plug 'AndrewRadev/splitjoin.vim'
" Easily delete, change and add surroundings in pairs
Plug 'tpope/vim-surround'
" Pairs of handy bracket mappings
Plug 'tpope/vim-unimpaired'
" Produce increasing/decreasing columns of numbers, dates, or daynames
Plug 'visincr'
" Switch between source files and header files
Plug 'a.vim'
" Enable repeating supported plugin maps with "."
Plug 'tpope/vim-repeat'
" Vim UI
" A light and configurable statusline/tabline for Vim
Plug 'itchyny/lightline.vim'
" Simpler Rainbow Parentheses
Plug 'junegunn/rainbow_parentheses.vim', { 'for': [
\ 'clojure',
\ 'lisp',
\ 'racket',
\ 'scheme'] }
if has('signs')
" Show a git diff in the gutter and stages/reverts hunks
Plug 'airblade/vim-gitgutter'
endif
" The fancy start screen for Vim
Plug 'mhinz/vim-startify'
" Distraction-free writing in Vim
Plug 'junegunn/goyo.vim', { 'on': 'Goyo' }
" Support file types
" AdBlock
Plug 'mojako/adblock-filter.vim', { 'for': 'adblockfilter' }
" Aheui
Plug 'yous/aheui.vim', { 'for': 'aheui' }
" CUP
Plug 'gcollura/cup.vim', { 'for': 'cup' }
" Jade
Plug 'digitaltoad/vim-jade', { 'for': 'jade' }
" JSON
Plug 'elzr/vim-json', { 'for': ['json', 'markdown'] }
" LaTeX
Plug 'lervag/vimtex', { 'for': ['bib', 'tex'] }
" Markdown
Plug 'godlygeek/tabular', { 'for': 'markdown' } |
Plug 'plasticboy/vim-markdown', { 'for': 'markdown' }
" PHP
Plug 'php.vim-html-enhanced', { 'for': ['html', 'php'] }
" Racket
Plug 'wlangstroth/vim-racket', { 'for': 'racket' }
" smali
Plug 'kelwin/vim-smali', { 'for': 'smali' }
" SMT-LIB
Plug 'raichoo/smt-vim', { 'for': 'smt' }
" Vader
Plug 'junegunn/vader.vim', { 'for': 'vader' }
" XML
Plug 'othree/xml.vim', { 'for': 'xml' }
" A solid language pack for Vim
Plug 'sheerun/vim-polyglot'
" Python
" A nicer Python indentation style for vim
Plug 'hynek/vim-python-pep8-indent', { 'for': 'python' }
" Ruby
" Rake
Plug 'tpope/vim-rake'
" RuboCop
Plug 'ngmy/vim-rubocop', { 'on': 'RuboCop' }
" Rails
Plug 'tpope/vim-rails'
" ANSI escape
Plug 'AnsiEsc.vim', { 'for': 'railslog' }
" TomDoc
Plug 'wellbredgrapefruit/tomdoc.vim', { 'for': 'ruby' }
" Mac OS
if has('mac') || has('macunix')
" Add plist editing support to Vim
Plug 'darfink/vim-plist'
" Launch queries for Dash.app from inside Vim
Plug 'rizzatti/dash.vim', { 'on': [
\ 'Dash',
\ 'DashKeywords',
\ '<Plug>DashSearch',
\ '<Plug>DashGlobalSearch'] }
endif
call plug#end()
" Followings are done by `plug#end()`:
" filetype plugin indent on
" syntax on
" }}}
" =============================================================================
" General: {{{
" =============================================================================
" Define the 'vimrc' autocmd group
augroup vimrc
autocmd!
augroup END
if &shell =~# 'fish$'
set shell=sh
endif
if has('gui_running')
language messages en
if has('multi_byte')
set encoding=utf-8
endif
endif
set autoread
set background=dark
set backspace=indent,eol,start
" Use the clipboard register '*'
set clipboard=unnamed
if has('multi_byte')
set fileencodings=ucs-bom,utf-8,cp949,latin1
endif
set fileformats=unix,mac,dos
if has('folding')
" Sets 'foldlevel' when starting to edit another buffer in a window
set foldlevelstart=99
endif
" Number of remembered ":" commands
set history=1000
" Ignore case in search
set ignorecase
if has('extra_search')
" Show where the pattern while typing a search command
set incsearch
endif
" Don't make a backup before overwriting a file
set nobackup
" Override the 'ignorecase' if the search pattern contains upper case
set smartcase
" Enable list mode
set list
" Strings to use in 'list' mode and for the :list command
try
set listchars=tab:>\ ,trail:·,extends:»,precedes:«,nbsp:+
catch /^Vim\%((\a\+)\)\=:E474/
set listchars=tab:>\ ,trail:_,extends:>,precedes:<,nbsp:+
endtry
" The key sequence that toggles the 'paste' option
set pastetoggle=<F2>
" Maximum number of changes that can be undone
set undolevels=1000
" Update swap file and trigger CursorHold after 1 second
set updatetime=1000
if has('wildignore')
" List of file patterns to ignore when expanding wildcards, completing file or
" directory names, and influences the result of expand(), glob() and
" globpath()
set wildignore+=.git,.hg,.svn
set wildignore+=*.bmp,*.gif,*.jpeg,*.jpg,*.png
set wildignore+=*.dll,*.exe,*.o,*.obj
set wildignore+=*.sw?
set wildignore+=*.DS_Store
set wildignore+=*.pyc
endif
if exists('+wildignorecase')
" Ignore case when completing file names and directories
set wildignorecase
endif
if has('wildmenu')
" Enhanced command-line completion
set wildmenu
endif
if has('win32')
" Directory names for the swap file
set directory=.,$TEMP
" Use a forward slash when expanding file names
set shellslash
endif
" }}}
" =============================================================================
" Vim UI: {{{
" =============================================================================
try
colorscheme open-color
catch /^Vim\%((\a\+)\)\=:E185/
colorscheme default
set background=dark
endtry
if has('syntax') && has('gui_running') && &t_Co > 16
" Highlight the screen line of the cursor
set cursorline
endif
" Show as much as possible of the last line
set display+=lastline
" Show unprintable characters as a hex number
set display+=uhex
" Always show a status line
set laststatus=2
set number
" Don't consider octal number when using the CTRL-A and CTRL-X commands
set nrformats-=octal
set scrolloff=3
if has('cmdline_info')
" Show command in the last line of the screen
set showcmd
endif
" Briefly jump to the matching one when a bracket is inserted
set showmatch
" The minimal number of columns to scroll horizontally
set sidescroll=1
set sidescrolloff=10
if has('windows')
set splitbelow
endif
if has('vertsplit')
set splitright
endif
if empty($TMUX) && empty($STY) && has('termguicolors') &&
\ exists('g:colors_name') && g:colors_name !=# 'default'
if !has('mac') || $TERM_PROGRAM ==# 'iTerm.app'
set termguicolors
endif
endif
augroup colorcolumn
autocmd!
if exists('+colorcolumn')
" Highlight column after 'textwidth'
set colorcolumn=+1
else
autocmd BufWinEnter *
\ let w:m2 = matchadd('ErrorMsg', '\%' . (&textwidth + 1) . 'v', -1)
endif
augroup END
" Highlight trailing whitespace
function! s:MatchExtraWhitespace(enabled)
if a:enabled && index(['conque_term', 'startify', 'vim-plug'], &filetype) < 0
match ExtraWhitespace /\s\+$/
else
match ExtraWhitespace //
endif
endfunction
highlight ExtraWhitespace ctermbg=red guibg=red
augroup ExtraWhitespace
autocmd!
autocmd BufWinEnter * call s:MatchExtraWhitespace(1)
autocmd FileType * call s:MatchExtraWhitespace(1)
autocmd InsertEnter * call s:MatchExtraWhitespace(0)
autocmd InsertLeave * call s:MatchExtraWhitespace(1)
if version >= 702
autocmd BufWinLeave * call clearmatches()
endif
augroup END
" }}}
" =============================================================================
" GUI: {{{
" =============================================================================
if has('gui_running')
set guifont=Consolas:h10:cANSI
set guioptions-=m " Menu bar
set guioptions-=T " Toolbar
set guioptions-=r " Right-hand scrollbar
set guioptions-=L " Left-hand scrollbar when window is vertically split
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
if has('win32')
set guifontwide=D2Coding:h10:cDEFAULT,
\NanumGothicCoding:h10:cDEFAULT,
\DotumChe:h10:cDEFAULT
endif
function! s:ScreenFilename()
if has('amiga')
return 's:.vimsize'
elseif has('win32')
return $HOME . '\_vimsize'
else
return $HOME . '/.vimsize'
endif
endfunction
function! s:ScreenRestore()
" Restore window size (columns and lines) and position
" from values stored in vimsize file.
" Must set font first so columns and lines are based on font size.
let f = s:ScreenFilename()
if has('gui_running') && g:screen_size_restore_pos && filereadable(f)
let vim_instance =
\ (g:screen_size_by_vim_instance == 1 ? (v:servername) : 'GVIM')
for line in readfile(f)
let sizepos = split(line)
if len(sizepos) == 5 && sizepos[0] == vim_instance
silent! execute 'set columns=' . sizepos[1] . ' lines=' . sizepos[2]
silent! execute 'winpos ' . sizepos[3] . ' ' . sizepos[4]
return
endif
endfor
endif
endfunction
function! s:ScreenSave()
" Save window size and position.
if has('gui_running') && g:screen_size_restore_pos
let vim_instance =
\ (g:screen_size_by_vim_instance == 1 ? (v:servername) : 'GVIM')
let data = vim_instance . ' ' . &columns . ' ' . &lines . ' ' .
\ (getwinposx() < 0 ? 0: getwinposx()) . ' ' .
\ (getwinposy() < 0 ? 0: getwinposy())
let f = s:ScreenFilename()
if filereadable(f)
let lines = readfile(f)
call filter(lines, "v:val !~ '^" . vim_instance . "\\>'")
call add(lines, data)
else
let lines = [data]
endif
call writefile(lines, f)
endif
endfunction
if !exists('g:screen_size_restore_pos')
let g:screen_size_restore_pos = 1
endif
if !exists('g:screen_size_by_vim_instance')
let g:screen_size_by_vim_instance = 1
endif
augroup ScreenRestore
autocmd!
autocmd VimEnter *
\ if g:screen_size_restore_pos == 1 |
\ call s:ScreenRestore() |
\ endif
autocmd VimLeavePre *
\ if g:screen_size_restore_pos == 1 |
\ call s:ScreenSave() |
\ endif
augroup END
endif
" }}}
" =============================================================================
" Text Formatting: {{{
" =============================================================================
set autoindent
if has('cindent')
set cindent
endif
set expandtab
" Insert only one space after a '.', '?' and '!' with a join command
set nojoinspaces
" Number of spaces that a <Tab> counts for while editing
set softtabstop=2
" Number of spaces to use for each setp of (auto)indent
set shiftwidth=2
" Number of spaces that a <Tab> in the file counts for
set tabstop=8
" Maximum width of text that is being inserted
set textwidth=80
autocmd vimrc FileType c,cpp,java,json,markdown,perl,python
\ setlocal softtabstop=4 shiftwidth=4
autocmd vimrc FileType gitconfig
\ setlocal noexpandtab softtabstop=8 shiftwidth=8
autocmd vimrc FileType go
\ setlocal noexpandtab softtabstop=4 shiftwidth=4 tabstop=4
" t: Auto-wrap text using textwidth
" c: Auto-wrap comments using textwidth
" r: Automatically insert the current comment leader after hitting <Enter> in
" Insert mode
" o: Automatically insert the current comment leader after hitting 'o' or 'O' in
" Normal mode
" q: Allow formatting of comments with "gq"
" l: Long lines are not broken in insert mode
" j: Remove a comment leader when joining lines
autocmd vimrc FileType *
\ setlocal formatoptions+=c
\ formatoptions+=r
\ formatoptions+=q
\ formatoptions+=l |
\ if &filetype ==# 'markdown' |
\ setlocal formatoptions+=o |
\ else |
\ setlocal formatoptions-=o |
\ endif |
\ if index(['gitcommit', 'markdown', 'tex'], &filetype) < 0 |
\ setlocal formatoptions-=t |
\ endif |
\ if v:version >= 704 || v:version == 703 && has('patch541') |
\ setlocal formatoptions+=j |
\ endif
" }}}
" =============================================================================
" Mappings: {{{
" =============================================================================
" Commander
nnoremap ; :
" We do line wrap
noremap j gj
noremap k gk
noremap <Down> gj
noremap <Up> gk
noremap gj j
noremap gk k
" Easy navigation on a line
noremap H ^
noremap L $
" Unix shell behavior
inoremap <C-A> <Esc>I
inoremap <C-E> <Esc>A
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
" Leave insert mode
function! s:CtrlL()
" Keep the original feature of Ctrl-l. See :help i_CTRL-L.
if exists('&insertmode') && &insertmode
call feedkeys("\<C-L>", 'n')
else
call feedkeys("\e", 't')
endif
endfunction
inoremap <silent> <C-L> <C-O>:call <SID>CtrlL()<CR>
" Make Y behave like C and D
nnoremap Y y$
" Delete without copying
vnoremap <BS> "_d
" Break the undo block when Ctrl-u
inoremap <C-U> <C-G>u<C-U>
if has('wildmenu')
" Move into subdirectory in wildmenu
function! s:WildmenuEnterSubdir()
call feedkeys("\<Down>", 't')
return ''
endfunction
cnoremap <expr> <C-J> <SID>WildmenuEnterSubdir()
endif
" Move cursor between splitted windows
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l
" Reselect visual block after shifting
vnoremap < <gv
vnoremap > >gv
" Search regex
" All ASCII characters except 0-9, a-z, A-Z and '_' have a special meaning
nnoremap / /\v
vnoremap / /\v
cnoremap %s/ %smagic/
cnoremap \>s/ \>smagic/
" Execute @q which is recorded by qq
nnoremap Q @q
" Zoom and restore window
function! s:ZoomToggle()
if exists('t:zoomed') && t:zoomed
execute t:zoom_winrestcmd
let t:zoomed = 0
elseif tabpagewinnr(tabpagenr('$'), '$') > 1
" Resize only when multiple windows are in the current tab page
let t:zoom_winrestcmd = winrestcmd()
resize
vertical resize
let t:zoomed = 1
endif
endfunction
nnoremap <silent> <Leader>z :call <SID>ZoomToggle()<CR>
augroup vimrc
" Quit help window
autocmd FileType help nnoremap <buffer> q :q<CR>
" Quit quickfix window
autocmd FileType qf nnoremap <buffer> q :q<CR>
" C, C++ compile
autocmd FileType c,cpp nnoremap <buffer> <F5> :w<CR>:make %<CR>
autocmd FileType c,cpp inoremap <buffer> <F5> <Esc>:w<CR>:make %<CR>
autocmd FileType c
\ if !filereadable('Makefile') && !filereadable('makefile') |
\ setlocal makeprg=gcc\ -o\ %< |
\ endif
autocmd FileType cpp
\ if !filereadable('Makefile') && !filereadable('makefile') |
\ setlocal makeprg=g++\ -o\ %< |
\ endif
" Markdown code snippets
autocmd FileType markdown inoremap <buffer> <LocalLeader>` ```
" Go
autocmd FileType go nnoremap <buffer> <F5> :w<CR>:!go run %<CR>
autocmd FileType go inoremap <buffer> <F5> <Esc>:w<CR>:!go run %<CR>
" Python
autocmd FileType python nnoremap <buffer> <F5> :w<CR>:!python %<CR>
autocmd FileType python inoremap <buffer> <F5> <Esc>:w<CR>:!python %<CR>
" Ruby
autocmd FileType ruby nnoremap <buffer> <F5> :w<CR>:!ruby %<CR>
autocmd FileType ruby inoremap <buffer> <F5> <Esc>:w<CR>:!ruby %<CR>
augroup END
" File execution
if has('win32')
nnoremap <F6> :!%<.exe<CR>
inoremap <F6> <Esc>:!%<.exe<CR>
elseif has('unix')
nnoremap <F6> :!./%<<CR>
inoremap <F6> <Esc>:!./%<<CR>
endif
" }}}
" =============================================================================
" Functions And Commands: {{{
" =============================================================================
" Auto quit Vim when actual files are closed
function! s:CheckLeftBuffers()
if tabpagenr('$') == 1
let i = 1
while i <= winnr('$')
let l:filetypes = ['help', 'quickfix', 'nerdtree', 'taglist']
if index(l:filetypes, getbufvar(winbufnr(i), '&filetype')) >= 0 ||
\ getwinvar(i, '&previewwindow')
let i += 1
else
break
endif
endwhile
if i == winnr('$') + 1
call feedkeys(":only\<CR>:q\<CR>", 'n')
endif
endif
endfunction
autocmd vimrc BufEnter * call s:CheckLeftBuffers()
command! Gdiffs cexpr system('git diff \| diff-hunk-list') |
\ cwindow | wincmd p
" }}}
" =============================================================================
" Autocmd: {{{
" =============================================================================
augroup vimrc
" Reload vimrc on the fly
autocmd BufWritePost $MYVIMRC nested source $MYVIMRC
" Exit Paste mode when leaving Insert mode
autocmd InsertLeave * set nopaste
" Keyword lookup program
autocmd FileType c,cpp setlocal keywordprg=man
autocmd FileType gitconfig
\ setlocal keywordprg=man\ git-config\ \|\ less\ -i\ -p
autocmd FileType help,vim setlocal keywordprg=:help
autocmd FileType ruby setlocal keywordprg=ri
" Plain view for plugins
autocmd FileType conque_term,startify,vim-plug
\ setlocal colorcolumn= nolist textwidth=0
" Ruby configuration files view
autocmd BufNewFile,BufRead Gemfile,Guardfile setlocal filetype=ruby
" Gradle view
autocmd BufNewFile,BufRead *.gradle setlocal filetype=groovy
" Json view
autocmd BufNewFile,BufRead *.json setlocal filetype=json
" Markdown view
autocmd BufNewFile,BufRead *.md setfiletype markdown
" mobile.erb view
autocmd BufNewFile,BufRead *.mobile.erb let b:eruby_subtype = 'html'
autocmd BufNewFile,BufRead *.mobile.erb setfiletype eruby
" zsh-theme view
autocmd BufNewFile,BufRead *.zsh-theme setlocal filetype=zsh
augroup END
" Reload symlink of vimrc on the fly
let resolved_vimrc = resolve(expand($MYVIMRC))
if expand($MYVIMRC) !=# resolved_vimrc
execute 'autocmd vimrc BufWritePost ' . resolved_vimrc .
\ ' nested source $MYVIMRC'
endif
unlet resolved_vimrc
" }}}
" =============================================================================
" Plugins: {{{
" =============================================================================
" PreserveNoEOL
let g:PreserveNoEOL = 1
" EditorConfig
if executable('editorconfig')
let g:EditorConfig_core_mode = 'external_command'
endif
" YouCompleteMe
let g:ycm_filetype_blacklist = {
\ 'diff': 1,
\ 'infolog': 1,
\ 'mail': 1,
\ 'markdown': 1,
\ 'netrw': 1,
\ 'notes': 1,
\ 'pandoc': 1,
\ 'qf': 1,
\ 'tagbar': 1,
\ 'text': 1,
\ 'unite': 1,
\ 'vimwiki': 1 }
let g:ycm_enable_diagnostic_highlighting = 0
let g:ycm_autoclose_preview_window_after_insertion = 1
if exists('s:vimfiles')
let g:ycm_global_ycm_extra_conf = s:vimfiles .
\ '/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
endif
let g:ycm_confirm_extra_conf = 0
" vim-slash
" Center display after searching
noremap <Plug>(slash-after) zz
" Syntastic
" Skip checks when you issue :wq, :x and :ZZ
let g:syntastic_check_on_wq = 0
" Display all of the errors from all of the checkers together
let g:syntastic_aggregate_errors = 1
" Sort errors by file, line number, type, column number
let g:syntastic_sort_aggregated_errors = 1
" Turn off highlighting for marking errors
let g:syntastic_enable_highlighting = 0
" Always stick any detected errors into the location-list
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_mode_map = { 'mode': 'passive' }
" Check header files
let g:syntastic_c_check_header = 1
let g:syntastic_cpp_check_header = 1
" Enable JSCS for JavaScript files
let g:syntastic_javascript_checkers = ['jshint', 'jslint', 'jscs']
" Extend max error count for JSLint
let g:syntastic_javascript_jslint_args = '--white --nomen --regexp --plusplus
\ --bitwise --newcap --sloppy --vars --maxerr=1000'
" vim-shell
let g:shell_hl_exclude = '^.*$'
let g:shell_mappings_enabled = 0
" vim-easytags
let g:easytags_auto_highlight = 0
let g:easytags_async = 1
" Fugitive
let s:fugitive_insert = 0
augroup Fugitive
autocmd!
autocmd FileType gitcommit
\ if byte2line(2) == 2 |
\ let s:fugitive_insert = 1 |
\ endif
autocmd VimEnter *
\ if (s:fugitive_insert) |
\ startinsert |
\ endif
augroup END
" ConqueTerm
let g:ConqueTerm_InsertOnEnter = 1
let g:ConqueTerm_CWInsert = 1
let g:ConqueTerm_ReadUnfocused = 1
command! -nargs=* Sh ConqueTerm <args>
command! -nargs=* Shsp ConqueTermSplit <args>
command! -nargs=* Shtab ConqueTermTab <args>
command! -nargs=* Shvs ConqueTermVSplit <args>
" CamelCaseMotion
function! s:CreateCamelCaseMotionMappings()
for l:mode in ['n', 'o', 'x']
for l:motion in ['w', 'b', 'e']
let l:target_mapping = '<Plug>CamelCaseMotion_' . l:motion
execute l:mode . 'map <silent> <Leader><Leader>' . l:motion . ' '
\ . l:target_mapping
endfor
endfor
endfunction
call s:CreateCamelCaseMotionMappings()
" EasyMotion
map <Leader> <Plug>(easymotion-prefix)
" unimpaired.vim
" Center display on move between SCM conflicts
nnoremap [n [nzz
nnoremap ]n ]nzz
" lightline.vim
let g:lightline = {
\ 'colorscheme': 'jellybeans',
\ 'active': {
\ 'left': [
\ ['mode', 'paste'],
\ ['filename', 'readonly', 'eol', 'modified']],
\ 'right': [
\ ['syntastic', 'lineinfo'],
\ ['percent'],
\ ['filetype', 'fileencoding', 'fileformat']] },
\ 'tabline': { 'left': [['tabs']], 'right': [[]] },
\ 'tab': {
\ 'active': ['tabfilename', 'tabmodified'],
\ 'inactive': ['tabfilename', 'tabmodified'] },
\ 'component_function': {},
\ 'tab_component_function': {},
\ 'component_expand': {
\ 'readonly': 'LightLineReadonly',
\ 'eol': 'LightLineEol',
\ 'syntastic': 'SyntasticStatuslineFlag' },
\ 'component_type': {
\ 'readonly': 'warning',
\ 'eol': 'warning',
\ 'syntastic': 'error' },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '', 'right': '|' } }
for k in ['mode', 'filename', 'modified', 'filetype', 'fileencoding',
\ 'fileformat', 'percent', 'lineinfo']
let g:lightline.component_function[k] = 'LightLine' . toupper(k[0]) . k[1:]
endfor
for k in ['filename', 'modified']
let g:lightline.tab_component_function['tab' . k] =
\ 'LightLineTab' . toupper(k[0]) . k[1:]
endfor
function! LightLineWide(component)
let component_visible_width = {
\ 'mode': 60,
\ 'fileencoding': 70,
\ 'fileformat': 70,
\ 'filetype': 70,
\ 'percent': 50 }
return winwidth(0) >= get(component_visible_width, a:component, 0)
endfunction
function! LightLineVisible(component)
let fname = expand('%:t')
return fname != '__Tag_List__' &&
\ fname != 'ControlP' &&
\ fname !~ 'NERD_tree' &&
\ LightLineWide(a:component)
endfunction
function! LightLineMode()
let short_mode_map = {
\ 'n': 'N',
\ 'i': 'I',
\ 'R': 'R',
\ 'v': 'V',
\ 'V': 'V',
\ 'c': 'C',
\ "\<C-v>": 'V',
\ 's': 'S',
\ 'S': 'S',
\ "\<C-s>": 'S',
\ 't': 'T',
\ '?': ' ' }
let fname = expand('%:t')
return fname == '__Tag_List__' ? 'TagList' :
\ fname == 'ControlP' ? 'CtrlP' :
\ fname =~ 'NERD_tree' ? '' :
\ LightLineWide('mode') ? lightline#mode() :
\ get(short_mode_map, mode(), short_mode_map['?'])
endfunction
function! LightLineFilename()
let fname = expand('%:t')
return fname == '__Tag_List__' ? '' :
\ fname == 'ControlP' ? '' :
\ fname =~ 'NERD_tree' ?
\ (index(['" Press ? for help', '.. (up a dir)'], getline('.')) < 0 ?
\ matchstr(getline('.'), '[0-9A-Za-z_/].*') : '') :
\ '' != fname ? fname : '[No Name]'
endfunction
function! LightLineReadonly()
return &readonly ? 'RO' : ''
endfunction
function! LightLineEol()
return &eol ? '' : 'NOEOL'
endfunction
function! LightLineModified()
return &modified ? '+' : ''
endfunction
function! LightLineFiletype()
return LightLineVisible('filetype') ?
\ (strlen(&filetype) ? &filetype : 'no ft') : ''
endfunction
function! LightLineFileencoding()
return LightLineVisible('fileencoding') ? (strlen(&fenc) ? &fenc : &enc) : ''
endfunction
function! LightLineFileformat()
return LightLineVisible('fileformat') ? &fileformat : ''
endfunction
function! LightLinePercent()