-
Notifications
You must be signed in to change notification settings - Fork 5
/
vimrc
executable file
·1497 lines (1274 loc) · 47.2 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
scriptencoding utf-8
" Author: Felix Yuan
" Email: [email protected]
" Last Modified Date: Jul 5, 2015
" Source: https://github.com/yyscamper/vimconfig
"
" Reference:
" (1) http://amix.dk/vim/vimrc.html
" (2) https://github.com/amix/vimrc
" (3) https://github.com/wklken/k-vim
" Vundle Setting & Plugins {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Vundle Setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" set nocompatible
filetype off
set shell=/bin/bash
" set the runtime path to include Vundle and initialize
" set rtp+=~/.vim/bundle/Vundle.vim
" call vundle#begin()
call plug#begin('~/.vim/plugged')
" let Vundle manage Vundle, required
Plug 'gmarik/Vundle.vim'
" Color scheme
" Plug 'xolox/vim-colorscheme-switcher'
" Plug 'xolox/vim-misc'
Plug 'altercation/vim-colors-solarized'
" Plug 'crusoexia/vim-monokai'
" Plug 'zenorocha/dracula-theme', {'rtp': 'vim/'}
" General plugins
"Plug 'Lokaltog/powerline'
"Plug 'ashwin/vim-powerline'
Plug 'bling/vim-airline'
" Plug 'scrooloose/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeTabsToggle'] }
Plug 'scrooloose/nerdtree'
Plug 'jistr/vim-nerdtree-tabs'
Plug 'Xuyuanp/nerdtree-git-plugin'
"Plug 'bufexplorer.zip'
Plug 'jeetsukumaran/vim-buffergator'
"Plug 'rking/ag.vim'
Plug 'dyng/ctrlsf.vim'
Plug 'terryma/vim-multiple-cursors'
" Plug 'kshenoy/vim-signature'
Plug 'ntpeters/vim-better-whitespace'
Plug 'terryma/vim-expand-region'
Plug 'easymotion/vim-easymotion'
Plug 'matze/vim-move'
Plug 'wincent/command-t'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'tacahiroy/ctrlp-funky'
Plug 'jasoncodes/ctrlp-modified.vim'
Plug 'mhinz/vim-grepper'
Plug 'wellle/targets.vim'
Plug 'michaeljsmith/vim-indent-object'
" Plug 'xolox/vim-session'
Plug 'yssl/QFEnter'
Plug 'tpope/vim-unimpaired'
Plug 'justinmk/vim-sneak'
Plug 'svermeulen/vim-easyclip'
Plug 'tpope/vim-repeat'
" Plug 'Shougo/neocomplete.vim'
"Plug 'Shougo/neosnippet.vim'
"Plug 'Shougo/vimshell.vim'
"Plug 'Shougo/neosnippet-snippets'
"Plug 'Shougo/vimproc.vim'
Plug 'SirVer/ultisnips'
" Plug 'honza/vim-snippets'
" Common plugins for source codes
Plug 'w0rp/ale'
" Plug 'vim-syntastic/syntastic', { 'on': 'SyntasticCheck' }
" Plug 'vim-syntastic/syntastic'
Plug 'Chiel92/vim-autoformat', { 'on': 'Autoformat' }
" Plug 'Valloric/YouCompleteMe'
" Plug 'rdnetto/YCM-Generator', { 'branch': 'stable', 'on': ['YcmGenerateConfig', 'CCGenerateConfig'] }
Plug 'tomtom/tComment_vim'
"Plug 'Yggdroot/indentLine'
Plug 'nathanaelkane/vim-indent-guides'
"Plug 'junegunn/vim-easy-align'
Plug 'godlygeek/tabular', { 'on': 'Tabularize' }
Plug 'tpope/vim-surround'
Plug 'majutsushi/tagbar', { 'on': 'TagbarToggle' }
Plug 'liuchengxu/vista.vim'
" Plug 'thinca/vim-quickrun', { 'on': 'QuickRun' }
Plug 'janko-m/vim-test'
Plug 'skywind3000/asyncrun.vim'
Plug 'kien/rainbow_parentheses.vim'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'Raimondi/delimitMate'
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
Plug 'ncm2/ncm2-bufword'
Plug 'ncm2/ncm2-path'
Plug 'ncm2/ncm2-jedi'
Plug 'ncm2/ncm2-vim'
Plug 'Shougo/neco-vim'
if has('nvim')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
" Javascript/Node.js
Plug 'moll/vim-node', { 'for': 'javascript'}
"Plug 'walm/jshint.vim', { 'for': 'javascript'}
" Plug 'marijnh/tern_for_vim', { 'for': 'javascript'}
Plug 'pangloss/vim-javascript', { 'for': 'javascript'}
Plug 'crusoexia/vim-javascript-lib', { 'for': 'javascript'}
Plug 'jiangmiao/simple-javascript-indenter', { 'for': 'javascript'}
Plug 'ramitos/jsctags', { 'for': 'javascript'}
" Python
Plug 'python-mode/python-mode', { 'for': 'python'}
Plug 'davidhalter/jedi-vim'
Plug 'davidhalter/jedi'
" Plug 'jmcantrell/vim-virtualenv'
" JSON
Plug 'elzr/vim-json'
" golang
Plug 'fatih/vim-go', { 'for': 'go'}
" Misc
" Plug 'vim-scripts/Nibble'
" Plug 'vim-scripts/genutils'
" Plug 'powerman/vim-plugin-AnsiEsc'
Plug 'cespare/vim-toml', { 'for': 'toml' }
Plug 'CodeFalling/fcitx-vim-osx'
Plug 'kurkale6ka/vim-swap'
" SQL
Plug 'lifepillar/pgsql.vim'
" All of your Plugins must be added before the following line
call plug#end()
" call vundle#end() " required
filetype plugin indent on " required
" }}}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Setup separate virutla environment for Neovim
if has('nvim')
let g:python_host_prog = '/Users/yuany/envs/neovim2/bin/python'
let g:python3_host_prog = '/Users/yuany/envs/neovim3/bin/python'
" Make escape work in the Neovim terminal.
tnoremap <Esc> <C-\><C-n>
" Make navigation into and out of Neovim terminal splits nicer.
tnoremap <C-h> <C-\><C-N><C-w>h
tnoremap <C-j> <C-\><C-N><C-w>j
tnoremap <C-k> <C-\><C-N><C-w>k
tnoremap <C-l> <C-\><C-N><C-w>l
endif
" during insert mode, remap the ESC to avoid long finger keystroke
" `^ is to let the cursor doesn't when back to normal mode
inoremap jk <Esc>`^
" imap <Esc> <Esc>`^
" unmap Esc so that force me to use the jk
" inoremap <Esc> <Nop>
" Sets how many lines of history VIM has to remember
set history=700
" Enable filetype plugins
filetype plugin on
filetype indent on
" Set to auto read when a file is changed from the outside
set autoread
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ','
let g:mapleader = ','
" Fast saving
nmap <leader>w :w!<cr>
map <C-s> <Esc>:w!<cr>
" Quickly close the current window
nnoremap <leader>q :q<CR>
" Map F12 to toggle Paste mode
set pastetoggle=<F12>
" Disbale paste mode when leaving insert mode
au InsertLeave * set nopaste
" Map ; to : to quickly enter command line, this will save a million keystrokes
nnoremap ; :
" Map space to page down
nnoremap <space> <C-D>
:map <A-Space> <PageUp>
" let textwidth=80
" let colorcolumn=+1
" let &colorcolumn=join(range(101,999),",")
" let &colorcolumn="100,".join(range(120,999),",")
highlight ColorColumn ctermbg=grey guibg=#2c2d27
autocmd BufEnter *.py,*.js,*.json,*.sh,*.c,*.h,*.java,.vimrc,vimrc,_vimrc
\ exec ":call AutoSetFileLineLimit()"
" create a new line in the end of file and jump to it
nnoremap 'e <ESC>G$a<CR>
" move to last cursor position
nnoremap '' <C-O>
nnoremap 'b <C-O>
" move to previous cursor position
nnoremap 'f <C-I>
" start to replace the current word
nnoremap <leader>s :%s/<C-r><C-w>/
function! ConfigForLargeFile()
" no syntax highlighting etc
set eventignore+=FileType
" save memory when other file is viewed
setlocal bufhidden=unload
" is read-only (write with :w new_filename)
setlocal buftype=nowrite
" no undo possible
setlocal undolevels=-1
" display message
autocmd VimEnter * echo "The file is larger than " . (g:MyLargeFile / 1024 / 1024) . " MB, so some options are changed (see .vimrc for details)."
endfunction
" speed up opening large file
let g:MyLargeFile = 64 * 1024 * 1024
augroup auLargeFile
autocmd BufReadPre * let f=getfsize(expand("<afile>")) | if f > g:MyLargeFile || f == -2 | call ConfigForLargeFile() | endif
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn on the WiLd menu
set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,*.pyc,*.swp,*.bak,*.class,*.svn,*.git
" Make vim do normal (bash like) tab completion
set wildmode=longest:list,full
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Search instantly, makes search act like search in modern browsers
set incsearch
" Don't redraw while executing macros (good performance config)
set lazyredraw
" For regular expressions turn magic on
set magic
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
"set whichwrap+=<,>,h,l
" Set how many lines will be kept visible when move cursor up and down
set scrolloff=7
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs
" Insert tabs on the start of a line according to shiftwidth
" Press backspace once will remove 4 spaces
set smarttab
" 1 tab == 4 spaces
set tabstop=4
set softtabstop=4
set shiftwidth=4
" Auto indent, same with set autoindent
set autoindent "Auto indent
" Smart indent, same with set smartindent
set smartindent "Smart indent
" Don't wrap lines
set nowrap
set number " show line numbers
" set relativenumber " show relative numbers
" highlight current line
set cursorline
" set cursorcolumn
" set foldenable
nnoremap B ^
nnoremap E $
" jump to the middle of line
" nnoremap m call cursor(0, len(getline('.'))/2)
nnoremap gV `[v`] " highlight last inserted text
"Open vim configuration file
nnoremap <leader>vo :vsp ~/.vimrc<CR>
"source vim configuration file
nnoremap <leader>vs :source ~/.vimrc<CR>
" Stay in visual mode when indenting. You will never have to run gv after
" performing an indentation.
vnoremap < <gv
vnoremap > >gv
" Make Y yank everything from the cursor to the end of the line. This makes Y
" act more like C or D because by default, Y yanks the current line (i.e. the
" same as yy).
noremap Y y$
" Make Ctrl-e jump to the end of the current line in the insert mode. This is
" handy when you are in the middle of a line and would like to go to its end
" without switching to the normal mode.
inoremap <C-e> <C-o>$
inoremap <C-b> <C-o>^
" Allows you to easily replace the current word and all its occurrences.
nnoremap <Leader>rc :%s/\<<C-r><C-w>\>/
vnoremap <Leader>rc y:%s/<C-r>"/
noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
" In the quickfix window, <CR> is used to jump to the error under the
" cursor, so undefine the mapping there.
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>:cw<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => File encoding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Try following encoding in following defined order in auto mode
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileencoding=utf-8
" Set new file's encoding
set encoding=utf-8
" set termencoding=
" Use Unix as the standard file type
set ffs=unix,dos,mac
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Backup file to another location, currently disable this
"set backup
"set backext=.bak
"set backupdir=/tmp/vimbackup/
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile
" Create undo file
if has('persistent_undo')
set undolevels=1000 " How many undos
set undoreload=10000 " number of lines to save for undo
set undofile " So is persistent undo ...
set undodir=/tmp/vimundo/
endif
" Automatically reload the vim configure file if has modification
"autocmd! bufwritepost _vimrc source % " windows
autocmd! bufwritepost .vimrc source % " linux
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax on
" Enable syntax highlighting
syntax enable
set background=dark
" Configure for solarized
let g:solarized_termtrans=0
let g:solarized_degrade=0
let g:solarized_termcolors=256
let g:solarized_contrast='normal'
let g:solarized_visibility='normal'
set t_Co=256
colorscheme solarized
set guifont=Monaco\ for\ Powerline:h14
"highlight Normal ctermfg=grey ctermbg=base03
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Visual mode related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs, windows and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Useful mappings for managing tabs
map <leader>tt :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tq :tabclose<cr>
map <leader>tm :tabmove
map <leader>tp :tabp<cr>
map <leader>tn :tabn<cr>
" Quickly switch to the specified tab
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<cr>
" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" Quickly open a buffer for scripbble
map <leader>bb :e ~/buffer<cr>
" Specify the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
" useful mappings for managing windows
map <leader>wh :wincmd h<cr>
map <leader>wj :wincmd j<cr>
map <leader>wk :wincmd k<cr>
map <leader>wl :wincmd l<cr>
map <leader>wq :wincmd q<cr>
map <leader>ww :wincmd w<cr>
" nnoremap ww :wincmd w<cr>
command! ZoomToggle call s:ZoomToggle()
nnoremap <silent> <leader>wz :ZoomToggle<CR>
" Puts new vsplit windows to the right of the current
set splitright
" Puts new split windows to the bottom of the current
set splitbelow
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Status line
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
" Format the status line
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h%{fugitive#statusline()}\ \ \ Line:\ %l
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editing mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Select whole line
map Y y$
" Select block
nnoremap <leader>v V`}
" Press w!! to sudo & write a file
cmap w!! w !sudo tee % > /dev/null
" Press U for easier redo
nnoremap U <C-r>
" Remove highlight
noremap <silent>'/ :nohls<CR>
"Keep search pattern at the center of the screen."
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * #zz
nnoremap <silent> # *zz
nnoremap <silent> g* g*zz
" Move a line of text
nmap <leader>lj mz:m+<cr>`z
nmap <leader>lk mz:m-2<cr>`z
vmap <leader>lj :m'>+<cr>`<my`>mzgv`yo`z
vmap <leader>lk :m'<-2<cr>`>my`<mzgv`yo`z
" The opened content will still keep in screen after close vim
" This doesn't work well in SSH console
"set t_ti= t_te=
" Delete trailing white space on save
" autocmd BufWrite *.py :call DeleteTrailingWS()
" autocmd BufWrite *.c :call DeleteTrailingWS()
" autocmd BufWrite *.cpp :call DeleteTrailingWS()
" autocmd BufWrite *.js :call DeleteTrailingWS()
" autocmd BufWrite *.java :call DeleteTrailingWS()
" autocmd BufWrite *.xml :call DeleteTrailingWS()
" set list
" set listchars=tab:›\ ,extends:#,nbsp:. " Highlight problematic whitespace
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-colorscheme-swicher
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:colorscheme_switcher_define_mappings = 0
map <silent> <F8> :NextColorScheme<CR>
map <silent> <C-F8> :PrevColorScheme<CR>
let g:colorscheme_switcher_exclude = ['default', 'blue', 'evening', 'morning',
\ 'pablo', 'darkblue', 'zellner', 'torte', 'peachpuff']
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-multiple-cursors
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Automatically add the file header for the new file
autocmd BufNewFile *.sh,*.py exec ":call AutoSetFileHead()"
autocmd Filetype python setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Misc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>~m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" Format JSON by json.tool
"nmap <C-J> :%!python -m json.tool<CR>:setfiletype json<CR>
" nmap <F6> :!mocha -R spec --require spec/helper.js %:p<CR>
" nmap <F7> :!./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --require spec/helper.js %:p<CR>
nmap <F6> :!pytest -x %:p<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: NERDTree
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" map <leader>x :set number!<CR>:set relativenumber!<CR>
let NERDTreeHighlightCursorline=1
let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.obj$', '\.o$', '\.so$', '\.egg$', '^\.git$', '^\.svn$', '^\.hg$' ]
"close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | end
" s/v to open file in different screen
let g:NERDTreeMapOpenSplit = 's'
let g:NERDTreeMapOpenVSplit = 'v'
let g:NERDTreeWinPos = 'right'
let NERDTreeChDirMode = 2
nmap <Leader>N :NERDTreeFind<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: NERDTree-tab
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <Leader>n <plug>NERDTreeTabsToggle<CR>
let g:nerdtree_tabs_synchronize_view=0
let g:nerdtree_tabs_synchronize_focus=0
let g:nerdtree_tabs_open_on_console_startup=0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: command-t
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"nnoremap <silent> <Leader>t :CommandT<CR>
map <C-t> :CommandT<CR>
let g:CommandTSmartCase = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: ctrlp
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:ctrlp_match_window = 'bottom,order:ttb,min:1,max:20'
let g:ctrlp_map = '<C-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 0
let g:ctrlp_match_window_bottom=1
let g:ctrlp_mruf_max=500
let g:ctrlp_follow_symlinks=1
" default by searching by filename, can be toggled to full-path mode by <C-d>
let g:ctrlp_by_filename = 0
nmap <leader>f :CtrlP<CR>
nmap <leader>fr :CtrlPMRU<CR>
map <C-p>r :CtrlPMRU<CR>
nmap <leader>fx :CtrlPMixed<CR>
map <C-p>x :CtrlPMixed<CR>
nmap <leader>fb :CtrlPBuffer<CR>
map <C-p>b :CtrlPBuffer<CR>
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$',
\ 'file': '\.exe$\|\.so$\|\.dll$\|\.pyc$\|\.o$\|\.obj$\|\.d$' }
" On Windows use "dir" as fallback command.
if executable('ag')
let s:ctrlp_fallback = 'ag %s --nocolor -l -g ""'
elseif executable('ack-grep')
let s:ctrlp_fallback = 'ack-grep %s --nocolor -f'
elseif executable('ack')
let s:ctrlp_fallback = 'ack %s --nocolor -f'
else
let s:ctrlp_fallback = 'find %s -type f'
endif
if exists("g:ctrlp_user_command")
unlet g:ctrlp_user_command
endif
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'],
\ 2: ['.hg', 'hg --cwd %s locate -I .'],
\ },
\ 'fallback': s:ctrlp_fallback
\ }
" CtrlP extensions
let g:ctrlp_extensions = ['funky', 'modified']
let g:ctrlp_funky_syntax_highlight = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: buffergator
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" New Buffergator window will be opened in horizontal top
" "L" : vertical left (full screen height)
" "R" : vertical right (full screen height)
" "T" : horizontal top (full screen width)
" "B" : horizontal bottom (full screen width)
let g:buffergator_viewport_split_policy = "T"
" Don't use default key mapping
let g:buffergator_suppress_keymaps = 0
let g:buffergator_suppress_mru_switch_into_splits_keymaps = 0
nnoremap <silent> <Leader>b :BuffergatorToggle<CR>
"nnoremap <silent> <Leader>B :BuffergatorClose<CR>
nnoremap <silent> <Leader>bp :BuffergatorMruCyclePre<CR>
nnoremap <silent> <Leader>bn :BuffergatorMruCycleNext<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-grepper
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:grepper={}
" Use the quickfix window.
let g:grepper.quickfix=1
" Open the quickfix window after the search finishes.
let g:grepper.open=1
" Switch to the quickfix window after the search finishes.
let g:grepper.switch=1
" Show the prompt by default.
let g:grepper.prompt=1
" Supported tools (use 'git' before 'ag').
let g:grepper.tools=['git', 'ag', 'ack', 'grep', 'findstr', 'sift', 'pt']
" Works like /, but uses vim-grepper to do the searching.
nnoremap <Leader>/ :Grepper<CR>
" Works like *, but uses vim-grepper to do the searching.
nnoremap <Leader>* :Grepper -cword -noprompt<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: ctrlsf.vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap \ <Plug>CtrlSFCwordExec
vmap <C-F> <Plug>CtrlSFVwordExec
vmap <C-F>p <Plug>CtrlSFVwordPath
nmap <C-F> <Plug>CtrlSFCwordExec
nmap <C-F>p <Plug>CtrlSFCwordPath
nmap <leader>fv <Esc>:CtrlSFToggle<CR>
nmap <leader>fp <Plug>CtrlSFCwordPath
" let g:ctrlsf_position = 'below'
" let g:ctrlsf_winsize = '30%'
let g:ctrlsf_auto_close = 0
let g:ctrlsf_confirm_save = 0
let g:ctrlsf_default_root = 'cwd'
let g:ctrlsf_context = '-C 2'
let g:ctrlsf_position = 'bottom'
" Note: cannot use <CR> or <C-m> for open
" Use : <sapce> or <tab>
let g:ctrlsf_mapping = {
\ "open" : "<Enter>",
\ "openb" : "O",
\ "tab" : "t",
\ "tabb" : "T",
\ "prevw" : "p",
\ "quit" : "q",
\ "next" : "n",
\ "prev" : "N",
\ "pquit" : "q",
\ }
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-signature
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Toggle the visible of mark and marker
nnoremap <silent> <Leader>mv :SignatureToggleSigns<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-move
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:move_key_modifier = 'C'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-multiple-cursors
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Don't use plugin's default key mapping
let g:multi_cursor_use_default_mapping=0
let g:multi_cursor_next_key='<C-m>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: neocomplete
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable AutoComplPop.
" let g:acp_enableAtStartup = 0
" " Use neocomplete.
" let g:neocomplete#enable_at_startup = 1
" " Use smartcase.
" let g:neocomplete#enable_smart_case = 1
" " Set minimum syntax keyword length.
" let g:neocomplete#sources#syntax#min_keyword_length = 3
" let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
"
" Define dictionary.
" let g:neocomplete#sources#dictionary#dictionaries = {
" \ 'default' : '',
" \ 'vimshell' : $HOME.'/.vimshell_hist',
" \ 'scheme' : $HOME.'/.gosh_completions'
" \ }
"
" " Define keyword.
" if !exists('g:neocomplete#keyword_patterns')
" let g:neocomplete#keyword_patterns = {}
" endif
" let g:neocomplete#keyword_patterns['default'] = '\h\w*'
"
" " Plugin key-mappings.
" inoremap <expr><C-g> neocomplete#undo_completion()
" inoremap <expr><C-l> neocomplete#complete_common_string()
"
" " Recommended key-mappings.
" " <CR>: close popup and save indent.
" inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
" function! s:my_cr_function()
" return neocomplete#close_popup() . "\<CR>"
" " For no inserting <CR> key.
" "return pumvisible() ? neocomplete#close_popup() : "\<CR>"
" endfunction
" " <TAB>: completion.
" inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" " <C-h>, <BS>: close popup and delete backword char.
" inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
" inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
" inoremap <expr><C-y> neocomplete#close_popup()
" inoremap <expr><C-e> neocomplete#cancel_popup()
" " Close popup by <Space>.
" "inoremap <expr><Space> pumvisible() ? neocomplete#close_popup() : "\<Space>"
"
" " For cursor moving in insert mode(Not recommended)
" "inoremap <expr><Left> neocomplete#close_popup() . "\<Left>"
" "inoremap <expr><Right> neocomplete#close_popup() . "\<Right>"
" "inoremap <expr><Up> neocomplete#close_popup() . "\<Up>"
" "inoremap <expr><Down> neocomplete#close_popup() . "\<Down>"
" " Or set this.
" "let g:neocomplete#enable_cursor_hold_i = 1
" " Or set this.
" "let g:neocomplete#enable_insert_char_pre = 1
"
" " AutoComplPop like behavior.
" "let g:neocomplete#enable_auto_select = 1
"
" " Shell like behavior(not recommended).
" "set completeopt+=longest
" "let g:neocomplete#enable_auto_select = 1
" "let g:neocomplete#disable_auto_complete = 1
" "inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"
"
" " Enable omni completion.
" autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
" autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
" autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
" autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
" autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
"
" " Enable heavy omni completion.
" if !exists('g:neocomplete#sources#omni#input_patterns')
" let g:neocomplete#sources#omni#input_patterns = {}
" endif
" "let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
" "let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
" "let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
"
" " For perlomni.vim setting.
" " https://github.com/c9s/perlomni.vim
" let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-better-whitespace
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap <leader>d<space> :StripWhitespace<CR>
"nmap <leader><space>t :ToggleWhitespace<CR>
"
" autocmd FileType javascript,python,c,cpp,java,html,xml,json autocmd BufWritePre <buffer> StripWhitespace
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: airline
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set t_Co=256
set laststatus=2
let g:Powerline_symbols = 'fancy'
set fillchars+=stl:\ ,stlnc:\
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#ale#enabled = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: YouCompleteMe
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" let g:ycm_complete_in_comments=1
" let g:ycm_confirm_extra_conf=0
" let g:ycm_collect_identifiers_from_tags_files=1
" inoremap <leader>; <C-x><C-o>
" set completeopt-=preview
" let g:ycm_min_num_of_chars_for_completion=1
" let g:ycm_cache_omnifunc=0
" let g:ycm_seed_identifiers_with_syntax=1
" let g:ycm_key_invoke_completion = '<M-;>'
" Python use its own completion tool python-mode
let ycmFileToIgnore = ['python']
autocmd FileType * if index(ycmFileToIgnore, &ft) < 0 | nnoremap gd :YcmCompleter GoToDefinitionElseDeclaration <C-R>=expand("<cword>")<CR><CR> | endif
"
" " Enable omni completion.
" autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
" autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
" autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
" autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
" autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
" autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
" autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc
let g:ycm_python_binary_path = 'python'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-json
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:vim_json_syntax_conceal = 0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-autoformat
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
noremap <F5> :Autoformat<CR>
" autocmd BufWrite *.py,*.js,*.json :Autoformat
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-indent-guide
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:indent_guides_start_level = 2
let g:indent_guides_guide_size = 1
let g:indent_guides_enable_on_vim_startup = 1
if has("gui_running")
let g:indent_guides_auto_colors = 1
else
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=234
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=235
endif
:noremap <C-F11> :IndentGuidesToggle<CR>:set number!<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: tComment
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:tcomment_maps = 0
" Comment one line
nnoremap <leader>cl :TComment<cr>
vnoremap <leader>cl :TComment<cr>
" Comment block, only useful on visual mode
vnoremap <leader>cb :TCommentBlock<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: tabular
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap <Leader>a& :Tabularize /&<CR>
vmap <Leader>a& :Tabularize /&<CR>
nmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
vmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
nmap <Leader>a=> :Tabularize /=><CR>
vmap <Leader>a=> :Tabularize /=><CR>
nmap <Leader>a: :Tabularize /:<CR>
vmap <Leader>a: :Tabularize /:<CR>
nmap <Leader>a:: :Tabularize /:\zs<CR>
vmap <Leader>a:: :Tabularize /:\zs<CR>
nmap <Leader>a, :Tabularize /,<CR>
vmap <Leader>a, :Tabularize /,<CR>
nmap <Leader>a,, :Tabularize /,\zs<CR>
vmap <Leader>a,, :Tabularize /,\zs<CR>
nmap <Leader>a( :Tabularize /(<CR>
vmap <Leader>a( :Tabularize /(<CR>
nmap <Leader>a[ :Tabularize /[<CR>
vmap <Leader>a[ :Tabularize /[<CR>
nmap <Leader>a{ :Tabularize /{<CR>
vmap <Leader>a{ :Tabularize /{<CR>
nmap <Leader>a- :Tabularize /-<CR>
vmap <Leader>a- :Tabularize /-<CR>
nmap <Leader>a* :Tabularize /*<CR>
vmap <Leader>a* :Tabularize /*<CR>
nmap <Leader>a< :Tabularize /<<CR>
vmap <Leader>a< :Tabularize /<<CR>
nmap <Leader>a" :Tabularize /"<CR>
vmap <Leader>a" :Tabularize /"<CR>
nmap <Leader>a' :Tabularize /'<CR>
vmap <Leader>a' :Tabularize /'<CR>
nmap <Leader>a<Bar> :Tabularize /<Bar><CR>
vmap <Leader>a<Bar> :Tabularize /<Bar><CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-gitgutter
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
nmap <Leader>vv :GitGutterToggle<CR>
nmap <Leader>vn <Plug>GitGutterNextHunk
nmap <Leader>vp <Plug>GitGutterPrevHunk
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: vim-fugitive
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gb :Gblame<CR>
nnoremap <leader>gv :Gvsplit<CR>
nnoremap <leader>gt :Gtabedit<CR>
nnoremap <leader>gl :Glog<CR>
nnoremap <leader>gd :Gdiff<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin: tagbar
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""