-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_vimrc
2333 lines (2002 loc) · 83 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
" Linsong's vimrc comes from official vimrc example
" vim: foldmethod=marker expandtab ts=2 sw=2
"
" Maintainer: Linsong linsong dot qizi at gmail dot com
" Last change: Fri Dec 9 17:58:24 CST 2005
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
"## General Setting {{{1
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" set up neovundle
if has('vim_starting')
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
call neobundle#rc(expand('~/.vim/bundle/'))
source ~/.vim/VundleFile
" end
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set history=300 " keep 300 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" set wildmenu on
set wildmenu
" enable mouse
set mouse-=a
" set search ignorecase
set ignorecase
" when If both ignorecase and smartcase are set, Vim will ignore the case
" of the search only if the search pattern is all in lower-case. But if
" there are any upper-case characters in the search pattern, Vim will
" assume you really want to do a case-sensitive search and will do
" its matching accordingly
set smartcase
set sessionoptions+=unix,slash
" set tabstop value and shift width
set ts=2
set sw=2
set expandtab
set smarttab
"setting about indent
" autoindent is not very convenient especially when editing mail text,
" use filetype indent script instead
set noautoindent
" It seems smartindent make things bad instead of smart:
" > You're probably setting 'smartindent' in your .vimrc. 'smartindent'
" > is worse than cindent for C/C++/Java, and much worse than filetype
" > indent scripts for other languages; I'd definitely recommend against
" > using it.
set nosmartindent
" always want at least two lines of context visible around the cursor at
" all times
" the drawback is: H/L will not arrive the real top/bottom of the buffer
"set scrolloff=2
"setting about old window resizing behavior when open a new window
set winfixheight
" not let all windows keep the same height/width
set noequalalways
" set autochdir to true,so whenever u open a window or switch to a buffer,the
" path is set
if exists("&autochdir")
""disable autochdir for now, since fuzzyfinder does not support it well
":set autochdir
endif
" set the path to find as many file as we can :)
" add the vim plugin search path
:set path+=./**,../,../*,../..,../../*,$HOME/.vim/*
" set buffer is hidden when it is not displayed on the screen
" this is for MultiSearch.vim to work
" but for now, I use mark.vim instead of MultiSearch.vim, so this is not
" useful, but keep it for now
:set hidden
set statusline=%<%f\ [%{&ff}]%{StatusInfo()}\ %h%m%r%=%-14.(%l,%c%V%)\ %P
" setting for completion
if v:version >= 700
:set completeopt=longest,menuone
endif
" search all the include files for a large project is deadly slow
:set complete-=i
:set wildmode=longest,full
" always display the statusline
:set laststatus=2
" In shell scripts, there should be no spaces around "=".
" progname=/usr/local/txserver
" to open files in a shell script with gf command:
" TODO: this setting should only work when we are editing a shell
" script, but for now, just leave it here and see how it works
:set isfname -==
" save screen estate as much as possible
:set numberwidth=1
:set nobackup writebackup
" set tags
:set tags+=../tags,../../tags,ftags,../*.tags
:set number
:let g:mapleader='['
if has("gui_macvim")
:set transparency=5
endif
:set previewheight=25
:set listchars=tab:»-,trail:·,extends:»,precedes:«
:set showmatch "set show matching parenthesis
:set viminfo^=!
:set lazyredraw
:set modelines=5
"## }}}1
"## Encodings {{{1
"for more details, read help usr_45.txt
" encodings configure
:let $LANG="en_US.UTF-8"
" set the encoding of menu text
:set langmenu=en_us.utf-8
" set what is the encoding of inputted text
if ! has("gui_running")
:let &termencoding = &encoding
endif
:set encoding=utf-8
:set fileencodings=ucs-bom,utf-8,gb2312,cp936
:set splitbelow
:set splitright
"## }}}1
"## General Mapping {{{1
" Use Q for formatting the current paragraph (or selection)
xmap Q gq
xmap Q gqap
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
xnoremap p "_dp
xnoremap P "_dP
" when leave insert mode by pressing <ESC>, turn off
" the input method, but for now it does not work for SCIM :(
:inoremap <silent> <ESC> <ESC>:set iminsert=0<CR>
" remap builtin shift command
:xnoremap < <gv
:xnoremap > >gv
" general key maps
"### got following tip from http://www.vim.org/tips/tip.php?tip_id=1
" Search for selected text in visual mode with */#
" effect: overrides unnamed register
" Simplest version: vnoremap * y/<C-R>"<CR>
" Better one: vnoremap * y/\V<C-R>=escape(@@,"/\\")<CR><CR>
" This is so far the best, allowing all selected characters and multiline selection:
" Atom \V sets following pattern to "very nomagic", i.e. only the backslash has special meaning.
" As a search pattern we insert an expression (= register) that
" calls the 'escape()' function on the unnamed register content '@@',
" and escapes the backslash and the character that still has a special
" meaning in the search command (/|?, respectively).
" This works well even with <Tab> (no need to change ^I into \t),
" but not with a linebreak, which must be changed from ^M to \n.
" This is done with the substitute() function.
xnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
xnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
" setting about specific plugins
" a vim script that can preview a function or variables
":map <C-Q> :call PreviewWord1()<CR>
:map <C-Q> :A<CR>
" the following map to make move between windows more easy!
set winminheight=0
nmap <C-j> <C-W>j
nmap <C-k> <C-W>k
nmap <C-h> <c-w>h
nmap <C-l> <c-w>l
" following key maps will make input mode's navigation easier
imap <C-j> <down>
imap <C-k> <up>
imap <C-B> <Left>
imap <C-F> <Right>
imap <C-D> <Del>
imap <C-A> <Home>
imap <C-BS> <C-O>B<C-O>dE
inoremap <C-E> <C-R>=col('.') == col('$') ? "\<lt>C-E>" : "\<lt>End>"<CR>
"" insert omnicompletion mode mappings
"if exists('*pumvisible')
"inoremap <C-h> <C-R>=pumvisible() ? "\<lt>BS>" : "\<lt>left>"<CR>
"else
"imap <C-h> <left>
"endif
" Make Enter less confusing under omnicompletion
if exists('*pumvisible')
"inoremap <Enter> <C-R>=pumvisible() ? "\<lt>C-y>" : "\<lt>Enter>"<CR>
":inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>"
"** These two mappings are probably the most rare, yet most valuable: **
":inoremap <expr> <c-n> pumvisible() ? "\<lt>c-n>" : "\<lt>c-n>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\ <lt>cr>"
":inoremap <expr> <m-;> pumvisible() ? "\<lt>c-n>" : "\<lt>c-x>\<lt>c-o>\<lt>c-n>\<lt>c-p>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>"
endif
" following key maps will make command mode's navigation easier
" when input path name, use the '/' to stop a completion
cnoremap <C-A> <Home>
cnoremap <C-B> <left>
cnoremap <C-F> <right>
cnoremap <C-X> <Del>
" following key maps will make increase/decrease the width/height of window
" easier
nmap - <C-W>-
nmap = <C-W>+
nmap _ 5<C-W><
nmap + 5<C-W>>
" use enter to unhighlighted searched-for text
"nnoremap <CR> :nohlsearch<CR><CR>
"nnoremap <CR> :set invhlsearch<CR><CR>
nnoremap <silent> ,<space> :nohlsearch<CR>
nnoremap <leader>q :close<CR>
" mappings for quickfix mode
nnoremap <xF4> :cnext \| norm zz<CR>
nnoremap <S-xF4> :cprev \| norm zz<CR>
nnoremap <C-F4> :cnfile <CR>
nnoremap <S-C-F4> :cpfile <CR>
" MAKE IT EASY TO UPDATE/RELOAD_vimrc
" I am short of shortcut keys, below key mapping is kind of waste, I
" recycle them now
"if has("gui_running")
":nmap ,s :source $HOME/.vimrc \| source $HOME/.gvimrc<CR>
"else
":nmap ,s :source $HOME/.vimrc<CR>
"endif
":nmap ,v :e $HOME/.vimrc<CR>
" Make navigate tabs easier
:nnoremap <silent> <M-.> gt
:nnoremap <silent> <M-,> gT
":nnoremap <silent> <M-n> :tabnew<CR>
:nnoremap <silent> <M-q> :tabclose<CR>
:nnoremap <silent> <M->> :if tabpagenr() == tabpagenr("$")\|tabm 0\|else\|exe "tabm ".tabpagenr()\|endif<CR>
:nnoremap <silent> <M-<> :if tabpagenr() == 1\|exe "tabm ".tabpagenr("$")\|else\|exe "tabm ".(tabpagenr()-2)\|endif<CR>
if has("xterm_clipboard")
nmap <S-Insert> :set paste<CR>"+p:set nopaste<CR>
imap <S-Insert> <ESC>:set paste<CR>"+p:set nopaste<CR>i
endif
"nnoremap <expr> <silent> <2-LeftMouse> HandleDbClick()
"function! HandleDbClick()
"let cur_line_number = line('.')
"if foldlevel(cur_line_number)!=0 && foldclosed(cur_line_number)!=-1
":norm zo
"endif
"endfunction
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
nmap <leader>ff :RedoFoldOnRegex<CR>
nmap <leader>fu :FoldEndFolding<CR>
nmap <leader>wf :WinFullScreen <CR>
" VIM-Shell
" Ctrl_W e opens up a vimshell in a horizontally split window
" Ctrl_W E opens up a vimshell in a vertically split window
" The shell window will be auto closed after termination
nmap <C-W>e :new \| vimshell bash<CR>
nmap <C-W>E :vnew \| vimshell bash<CR>
" it can copy texts to last edited place continuously
:xmap gy y:call CopyToLastEditPos()<CR>
:nmap gy yy:call CopyToLastEditPos()<CR>
function! CopyToLastEditPos()
let cmd = 'gigp'
if visualmode()==# 'V'
let cmd = cmd . 'k'
endif
let cmd = cmd . '`>'
:exec 'norm ' . cmd
endfunction
:map <F9> @q
:nmap ,o :only<CR>
" I want to exchange the meaning of following shortcuts:
:noremap <C-]> g<C-]>
:noremap g<C-]> <C-]>
if has("gui_macvim")
:map <silent> <D-.> gt
:map <silent> <D-1> :tabnext 1<CR>
:map <silent> <D-2> :tabnext 2<CR>
:map <silent> <D-3> :tabnext 3<CR>
:map <silent> <D-4> :tabnext 4<CR>
:map <silent> <D-5> :tabnext 5<CR>
:map <silent> <D-6> :tabnext 6<CR>
:map <silent> <D-7> :tabnext 7<CR>
:map <silent> <D-8> :tabnext 8<CR>
:map <silent> <D-9> :tabnext 9<CR>
:map <silent> <D-0> :tabnext 10<CR>
:nnoremap <silent> <D->> :if tabpagenr() == tabpagenr("$")\|tabm 0\|else\|exe "tabm ".tabpagenr()\|endif<CR>
:nnoremap <silent> <D-<> :if tabpagenr() == 1\|exe "tabm ".tabpagenr("$")\|else\|exe "tabm ".(tabpagenr()-2)\|endif<CR>
endif
:map <silent> ,1 :tabnext 1<CR>
:map <silent> ,2 :tabnext 2<CR>
:map <silent> ,3 :tabnext 3<CR>
:map <silent> ,4 :tabnext 4<CR>
:map <silent> ,5 :tabnext 5<CR>
:map <silent> ,6 :tabnext 6<CR>
:map <silent> ,7 :tabnext 7<CR>
:map <silent> ,8 :tabnext 8<CR>
:map <silent> ,9 :tabnext 9<CR>
:map <silent> ,0 :tabnext 10<CR>
":nnoremap <silent> <M-C-n> :tabnext<CR>
":nnoremap <silent> <M-C-p> :tabprevious<CR>
" tip from http://vim.wikia.com/wiki/Creating_new_text_objects
:vnoremap af :<C-U>silent! normal! [zV]z<CR>
:omap af :normal Vaf<CR>
" http://vim.wikia.com/wiki/Toggle_auto-indenting_for_code_paste
nnoremap <F1> :set invpaste paste?<CR>
imap <F1> <C-O><F1>
set pastetoggle=<F1>
" http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file
map ,cd :cd %:p:h<CR>
" use :w!! to write to a file using sudo if you forgot to 'sudo vim file'
" (it will prompt for sudo password when writing)
cmap w!! %!sudo tee > /dev/null %
" Center screen on next/previous selection.
nnoremap n nzz
nnoremap N Nzz
" Last and next jump should center too.
"nnoremap <C-o> <C-o>zz
"nnoremap <C-i> <C-i>zz
" use < and > to turn a half page horizontally
nnoremap } zL
nnoremap { zH
" use two windows to view a long file
" from vim tip wiki: http://vim.wikia.com/wiki/View_text_file_in_two_columns
:noremap <silent> <leader>vs :<C-u>let @z=&so<CR>:set so=0 noscb<CR>:bo vs<CR>Ljzt:setl scb<CR><C-w>p:setl scb<CR>:let &so=@z<CR>
nnoremap <silent> ;; :w<CR>
nnoremap <silent> ,, :wa<CR>
"imap <silent> ;; <Esc>:w<CR>a
"imap <silent> ,, <Esc>:wa<CR>a
nnoremap <silent> <f5> :make<CR>
imap <silent> <f5> <Esc>:w<CR>:make<CR>i
map <silent> <leader>ss :syntax sync fromstart<CR>
"## }}}1
"## Mappings for vim keycodes {{{1
" mappings for keycodes
" for more details about keycode mapping, read
" http://groups.yahoo.com/group/vim/message/69148
" http://groups.yahoo.com/group/vim/message/66451
" http://groups.yahoo.com/group/vim/message/66414
" http://vim.sourceforge.net/tips/tip.php?tip_id=1272
"
set timeout timeoutlen=3000 ttimeoutlen=100
if !has("gui_running")
if &term == "win32"
else
"following setting does not work after I update my system
" (from ubuntu 7.04 to 7.10)
" set <F13>=O5Q
" set <F14>=O2Q
" set <F15>=[3;2~
" "set <F16>=
" set <F17>=n
" set <F18>=q
" set <F19>=.
" set <F20>=,
" set <F21>=>
" set <F22>=<
" set <F23>=[2~;*~
" set <S-xF4>=O2S
set <F13>=O1;5Q
set <F14>=O1;2Q
set <F15>=[3;2~
set <F17>=n
set <F18>=q
set <F19>=.
set <F20>=,
set <F21>=>
set <F22>=<
set <F23>=[2~;*~
set <S-xF4>=O1;2S
set <F24>=O1;5S
set <F25>=O1;6S
set <F26>=OF
nmap <F13> <C-F2>
nmap <F14> <S-F2>
imap <F15> <S-Del> " this map does not work, don't know why
map <F17> <M-n>
map <F18> <M-q>
map <F19> <M-.>
map <F20> <M-,>
map <F21> <M->>
map <F22> <M-<>
map <F23> <S-Insert>
map <F24> <C-F4>
map <F25> <C-S-F4>
map <F26> <end>
endif
endif
"if !has("gui_running")
":set term=builtin_ansi
"endif
if has('clipboard')
:nmap ,cp :let @*=expand('%:p')<CR>
:nmap ,cpd :let @*=expand('%:p:h')<CR>
:nmap ,cpf :let @*=expand('%:t')<CR>
endif
"## }}}1
"## General function defination {{{1
function! MyFoldText()
let line = getline(v:foldstart)
let nnum = nextnonblank(v:foldstart + 1)
let nextline = getline(nnum)
if nextline =~ '^\s\+"""$'
let line = line . getline(nnum + 1)
elseif nextline =~ '^\s\+"""'
let line = line . ' ' . matchstr(nextline, '"""\zs.\{-}\ze\("""\)\?$')
elseif nextline =~ '^\s\+"[^"]\+"$'
let line = line . ' ' . matchstr(nextline, '"\zs.*\ze"')
elseif nextline =~ '^\s\+pass\s*$'
let line = line . ' pass'
endif
let size = 1 + v:foldend - v:foldstart
if size < 10
let size = " " . size
endif
if size < 100
let size = " " . size
endif
if size < 1000
let size = " " . size
endif
return "[" . size . "] " . line
endfunction
" [Modified by me] define indent block text object
" Changes to allow blank lines in blocks, and double
" blank lines as block delimiter
" Press: vai, vii to select outer/inner python blocks by indetation.
" Press: vii, yii, dii, cii to select/yank/delete/change an indented block.
onoremap <silent>ai :<C-u>call IndTxtObj(0)<CR>
onoremap <silent>ii :<C-u>call IndTxtObj(1)<CR>
vnoremap <silent>ai :<C-u>call IndTxtObj(0)<CR><Esc>gv
vnoremap <silent>ii :<C-u>call IndTxtObj(1)<CR><Esc>gv
function! IndTxtObj(inner)
let curcol = col(".")
let curline = line(".")
let lastline = line("$")
let i = indent(line(".")) - &shiftwidth * (v:count1 - 1)
let i = i < 0 ? 0 : i
if getline(".") =~ "^\\s*$"
return
endif
let p = line(".") - 1
let pp = line(".") - 2
let nextblank = getline(p) =~ "^\\s*$"
let nextnextblank = getline(pp) =~ "^\\s*$"
while p > 0 && !(nextblank && nextnextblank) && ( nextblank || indent(p) >= i )
-
let p = line(".") - 1
let pp = line(".") - 2
let nextblank = getline(p) =~ "^\\s*$"
let nextnextblank = getline(pp) =~ "^\\s*$"
endwhile
if (!a:inner)
-
endif
normal! 0V
call cursor(curline, curcol)
let p = line(".") + 1
let pp = line(".") + 2
let nextblank = getline(p) =~ "^\\s*$"
let nextnextblank = getline(pp) =~ "^\\s*$"
while p <=lastline && !(nextblank && nextnextblank) && ( nextblank || indent(p) >= i )
+
let p = line(".") + 1
let pp = line(".") + 2
let nextblank = getline(p) =~ "^\\s*$"
let nextnextblank = getline(pp) =~ "^\\s*$"
endwhile
if (!a:inner)
+
endif
normal! $
endfunction
onoremap <silent>aI :<C-u>call IndTxtObj2(0)<CR>
onoremap <silent>iI :<C-u>call IndTxtObj2(1)<CR>
vnoremap <silent>aI :<C-u>call IndTxtObj2(0)<CR><Esc>gv
vnoremap <silent>iI :<C-u>call IndTxtObj2(1)<CR><Esc>gv
function! IndTxtObj2(inner)
let curcol = col(".")
let curline = line(".")
let lastline = line("$")
let i = indent(line(".")) - &shiftwidth * (v:count1 - 1)
let i = i < 0 ? 0 : i
if getline(".") =~ "^\\s*$"
return
endif
let p = line(".") - 1
let nextblank = getline(p) =~ "^\\s*$"
while p > 0 && ( nextblank || indent(p) >= i )
-
let p = line(".") - 1
let nextblank = getline(p) =~ "^\\s*$"
endwhile
if (!a:inner)
-
endif
normal! 0V
call cursor(curline, curcol)
let p = line(".") + 1
let nextblank = getline(p) =~ "^\\s*$"
while p <=lastline && ( nextblank || indent(p) >= i )
+
let p = line(".") + 1
let nextblank = getline(p) =~ "^\\s*$"
endwhile
if (!a:inner)
+
endif
normal! $
endfunction
" }}}2
" http://vim.wikia.com/wiki/Quickly_switch_between_pager-like_and_editor-like_scroll {{{2
function! LessMode()
if g:lessmode == 0
let g:lessmode = 1
let onoff = 'on'
" Scroll half a page down
noremap <script> d <C-D>
" Scroll one line down
noremap <script> j <C-E>
" Scroll half a page up
noremap <script> u <C-U>
" Scroll one line up
noremap <script> k <C-Y>
else
let g:lessmode = 0
let onoff = 'off'
unmap d
unmap j
unmap u
unmap k
endif
echohl Label | echo "Less mode" onoff | echohl None
endfunction
let g:lessmode = 0
nnoremap <F6> :call LessMode()<CR>
inoremap <F6> <Esc>:call LessMode()<CR>
" }}}2
"}}}1
"## Platform dependent Setting {{{1
"if has("vms")
"set nobackup " do not keep a backup file, use versions instead
"else
"set backup " keep a backup file
"endif
let $VIMCFG = '$HOME/.vim'
"set clipboard=unnamed " for pbcopy and pbpast to work on macosx
" how to check different systems
"if has("unix")
" " code common to Cygwin and Linux
" if has("win32unix")
" " code for Cygwin but not Linux
" else
" " code for Linux but not Cygwin
" endif
"elseif has("win32")
" " code for windows-native Vim
"else
" echoerr "Unknown OS"
"endif
if has('win32') " windows specific setting{{{2
set runtimepath=~/.vim,$VIMRUNTIME
"setting about word complete
:set complete+=k$VIM/vimfiles/dictionary/*
" run any program and open any files in windows just like the exporler
:nmap <LEADER>go :silent !c:/WINDOWS/COMMAND/start <cWORD><CR>
:vmap <LEADER>go y:silent !c:/WINDOWS/COMMAND/start <C-R>"<CR>
" let vim to use ctags to generate tags file"
let Tlist_Ctags_Cmd = 'C:\unzipped\ctags\ctags552\ctags.exe'
" grep use the UnixUtils that port to Win32 by GNU,this can be imply by set
" path environment,so the following is useless
"
" if (expand('$VIM/vimtools') != '')
" let Grep_Path = expand('$VIM/vimtools/grep')
" " Location of the fgrep utility
" let Fgrep_Path = expand('$VIM/vimtools/fgrep')
" " Location of the egrep utility
" let Egrep_Path = expand('$VIM/vimtools/egrep')
" " Location of the agrep utility
" let Agrep_Path = expand('$VIM/vimtools/agrep')
" " Location of the find utility
" let Grep_Find_Path = expand('$VIM/vimtools/find')
" " Location of the xargs utility
" let Grep_Xargs_Path = expand('$VIM/vimtools/xargs')
" endif
" settings for Vim Intellisense
let $VIM_INTELLISNESE=expand('$VIM\Intellisense')
" settings for pydoc.vim to find pydoc command in windows
let g:pydoc_cmd = 'C:\Python24\Lib\pydoc.pyc'"
"the following option will always yank to * register
"this is very helpful under Windows
:set clipboard=unamed
" windows setting end }}}2
elseif has('macunix') "macosx specific settings {{{2
"set guifont=Monaco:h13
" set guifont=Source\ Code\ Pro:h18
set guifont=Anonymous\ Pro:h18
let Grep_Xargs_Options = '-0'
" macosx specific settings end}}}2
else " linux like platform specific setting {{{2
" put some untested or untrusted plugin into .vim-experiment folder,
" don't mess up .vim
"set runtimepath+=~/.vim-experiment
"setting about word complete
:set complete+=U,k/usr/dict/*,k$VIM/vimfiles/dictionary/*
":set complete+=k/usr/dict/*,k$VIM/vimfiles/dictionary/*
" set grep program
":set grepprg=grep\ -n
:set grepprg=/opt/local/bin/grep\ -n
" extends manpageview to support reading pydoc in vim
" manpageview is very extensible especially for man like
" doc utilities(perldoc, pydoc etc)
let g:manpageview_pgm_py = "/opt/local/bin/pydoc"
" linux setting end
endif "}}}2
"### console mode setting {{{2
"TODO: need to set wildmode, for more details, :help 'wildmode'
" use menu in console mode
if !has("gui_running")
"### color scheme settings {{{3
" to enable 256 colors, you need to put following lines into .vimrc.local file
:set t_Co=256 " enable 256 colors refs: http://vim.wikia.com/wiki/256_colors_in_vim
""" NOTE: to make 256 colors work in GNU screen, screen need to be
""" configured with ./configure --enable-colors256
" if terminal support 256 colors, inkpot seems very nice
:colorscheme jellybeans
":colorscheme xoria256
":colorscheme inkpot
":colorscheme koehler
":colorscheme desert " use desert since 256 colors does not work from my macbox
":colorscheme sienna " use sienna since 256 colors does not work from my macbox
" xterm16 color scheme setting
let xterm16_brightness = 'default' " Change if needed
let xterm16_colormap = 'allblue' " Change if needed
"### }}}3
:source $VIMRUNTIME/menu.vim
:set cpo-=<
:set wcm=<C-Z>
:map <M-e> :emenu <C-Z>
" don't clear vim text in terminal when exit
:set t_ti= t_te=
endif
"### }}}2
"## }}}1
"## Autocmds {{{1
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" for details about how to define a augroup, :help augroup
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
autocmd FileType svnlog :call FoldOnRegex('^r\d\{1,\}\>', -1)
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" turn off the bell and visual flash
autocmd VimEnter * set vb t_vb=
" automate save the latest work to a session
" for now, I don't always need this
":au VimEnter * source ~/Session.vim
":au VimLeave * mksession!
" display the status line in different ways based on the current
" editing mode
if version >= 700
au InsertEnter * hi StatusLine term=reverse ctermbg=5 gui=undercurl guisp=Magenta
au InsertLeave * hi StatusLine term=reverse ctermfg=0 ctermbg=2 gui=bold,reverse
endif
" highlight current word under cursor
"autocmd CursorMoved * silent! exe printf('match IncSearch /\<%s\>/', expand('<cword>'))
augroup END
" settings related to specified file type. but checkings for file type
" should be put into ~/.vim/ftdetect/mine.vim
augroup ft_augroup
au!
:au BufRead /etc/network/interfaces :set syntax=interfaces
:au BufNewFile,BufRead *.as set suffixesadd=.as
:au BufNewFile,BufRead *.html let b:snip_start_tag = "@"
:au BufNewFile,BufRead *.html let b:snip_end_tag = "@"
:au BufNewFile,BufRead *.lzx let g:snip_start_tag = "@"
:au BufNewFile,BufRead *.lzx let g:snip_end_tag = "@"
:au BufEnter *.lzx :call FoldOnRegex('^\s*<\w\+', 0)
":au BufEnter *.py :call FoldOnRegex('^\s*\(\<def\>\|\<class\>\)', 0)
" remove trailing whitespace automatically
:au BufWritePre *.py :%s/\s\+$//e
" settting for fcshtools
":au BufNewFile,BufRead *.mxml,*.as :nmap <C-B> :!bash ~/bin/fcshcmp.sh %:p
":au BufNewFile,BufRead *.mxml,*.as :nmap <C-A> :!bash ~/bin/fcshcmp.sh %:p run
" following config will let vim to read non-plain-text file format
"
" autocmd for read MS Word document
" Vim Tip 790 - view word documents in Vim (good for diff'ing)
:autocmd BufReadPre *.doc set ro
:autocmd BufReadPre *.doc set hlsearch
:autocmd BufReadPost *.doc %!antiword "%"
" read pdf in vim
if has('unix')
:au BufReadPre *.pdf set ro
:au BufReadPost *.pdf silent %!pdftotext -nopgbrk "%" - | fmt -csw78
elseif has('win32')
"use pdftotext that comes cygwin
endif
":autocmd User Rails colorschem vividchalk
:autocmd User Rails.controller* set ft=railscontroller.ruby
:autocmd User Rails.model.arb* set ft=railsmodel.ruby
:autocmd User Rails.test* set ft=railstest.ruby
:autocmd User Rails.migration* set ft=railsmigration.ruby
:autocmd User Rails.view.erb* set ft=railsview.eruby
:autocmd User Rails let g:Grep_Skip_Dirs = join(['log', 'vender', 'index', 'tmp', 'wireframes', 'graphs', 'documents', 'pdf_forms', 'performance'] + Grep_Skip_Dirs_List, ' ')
" add the current extension to the grep file list
":autocmd BufNewFile,BufRead * let g:Grep_Default_Filelist = join(["*." . expand("%:e")] + Grep_Default_Filelist_List, ' ')
autocmd FileType html setlocal ts=2
autocmd FileType html setlocal sw=2
augroup END
"}}}4
" syntax omnicomplete {{{2
if has("autocmd") && exists("+omnifunc")
augroup omniFunc_augroup
autocmd Filetype *
\ if &omnifunc == "" |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif
augroup END
endif
"}}}2
" comment the following code since it does not work well
" when switching buffers, preserve window view {{{2
" visit http://vim.sourceforge.net/tips/tip.php?tip_id=1375 for details
"if v:version >= 700
"au BufLeave * let b:winview = winsaveview()
"au BufEnter * if(exists('b:winview')) | call winrestview(b:winview) | endif
"endif
"}}}2
"{{{2
"augroup JumpCursorOnEdit
"au!
"" From Bram:
"" When editing a file, always jump to the last known cursor position.
"" Don't do it when the position is invalid or when inside an event handler
"" (happens when dropping a file on gvim).
"" DF - Also do not do this if the file resides in the $TEMP directory,
"" chances are it is a different file with the same name.
"" This comes from the $VIMRUNTIME/vimrc_example.vim file
"" for more details, http://vim.sourceforge.net/tips/tip.php?tip_id=80
"autocmd BufReadPost *
"\ if expand("<afile>:p:h") !=? $TEMP |
"\ if line("'\"") > 1 && line("'\"") <= line("$") |
"\ let JumpCursorOnEdit_foo = line("'\"") |
"\ let b:doopenfold = 1 |
"\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
"\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
"\ let b:doopenfold = 2 |
"\ endif |
"\ exe JumpCursorOnEdit_foo |
"\ endif |
"\ endif
"" Need to postpone using "zv" until after reading the modelines.
"autocmd BufWinEnter *
"\ if exists("b:doopenfold") |
"\ exe "normal zv" |
"\ if(b:doopenfold > 1) |
"\ exe "+".1 |
"\ endif |
"\ unlet b:doopenfold |
"\ endif
"augroup END
"}}}2
endif " has("autocmd")
"## }}}1
"## Abbreviations {{{1
"normal abbreviations
abbr teh the
abbr widht width
abbr rigth right
"## }}}1
"## HighLighting {{{1
" highlight the leading and trailing whitespace
"highlight WhiteSpaceEOL ctermbg=darkgreen guibg=lightgreen
"match WhiteSpaceEOL /^\s*\ \s*\|\s\+$/
"autocmd WinEnter * match WhiteSpaceEOL /^\s*\ \s*\|\s\+$/
"## }}}1
"## Global variable definations {{{1
"## }}}1
"## Commands & Functions {{{1
" ### enhance the find command }}}2
" with the following command, we can use :find ~/path/test*.py<TAB> to
" get the file name completion, it's really good!
" NOTE: to use this command, we need genutils.vim
"command! -nargs=1 -bang -complete=custom,<SID>PathComplete FindInPath
"\ :find<bang> <args>
"function! s:PathComplete(ArgLead, CmdLine, CursorPos)
"return UserFileComplete(a:ArgLead, a:CmdLine, a:CursorPos, 1, &path)
"endfunction
" }}}2
" ### setting/command/function for diff {{{2
if exists(":diffoff")!=2
command! DiffOff :call CleanDiffOptions()
endif
" functions write by myself
function! s:my_InitDiffMapKey()
vmap dp :diffput<CR>
vmap do :diffget<CR>
" setting for DirDiff.vim
map <F8> :normal [c\|zz<CR>
map <F9> :normal ]c\|zz<CR>
map <F6> zh
map <F7> zl
endfunction
" Command to init the diff mode keymaps
command! -nargs=0 InitDMap call s:my_InitDiffMapKey()
" }}}2
"### String Object defination {{{2
" customized string object from http://vim.sourceforge.net/tips/tip.php?tip_id=901
" with this, we can use commands: da", yi' etc
function! StringObject(delim,mode)
if a:mode == 'i'
let c = 'normal T' . a:delim . 'vt' . a:delim
elseif a:mode == 'a'
let c = 'normal F' . a:delim . 'vf' . a:delim
endif
execute c
endfunction