-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
591 lines (480 loc) · 18 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
" This file is came from http://www.derekwyatt.org/vim/the-vimrc-file/my-vimrc-file/
" I also got a copy of this page in my ronhng dropbox account
"-----------------------------------------------------------------------------
" Global Stuff
"-----------------------------------------------------------------------------
" Set filetype stuff to on
filetype on
filetype plugin on
filetype indent on
" Tabstops are 4 spaces
set tabstop=4
set shiftwidth=4
" Set file encodings: encoding(enc) vim尝试转换到这种编码显示(默认读取locale)
" fileencodings(fencs)
" 编码列表,读取文件时根据这个顺序检测文件的编码,如果没有转换成功?
" fileencoding(fenc)文件当前使用的编码(扩展:转换编码的插件),新建文件
" 设置文件编码
set fenc=utf-8
" 设置文件编码检测类型及支持格式
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
" 高亮当前行
set cursorline
" 修改颜色
colorscheme ir_black
" set the search scan to wrap lines
set wrapscan
" set the search scan so that it ignores case when the search is all lower
" case but recognizes uppercase if it's specified
set ignorecase
set smartcase
" set the forward slash to be the slash of note. Backslashes suck
set shellslash
" Show line numbers
set number
" Make command line two lines high
" set ch=2
" set visual bell -- i hate that damned beeping
set vb
" Allow backspacing over indent, eol, and the start of an insert
set backspace=2
" Set to autoindent
set autoindent
" Make sure that unsaved buffers that are to be put in the background are
" allowed to go in there (ie. the "must save first" error doesn't come up)
set hidden
" Make the 'cw' and like commands put a $ at the end instead of just deleting
" the text and replacing it
set cpoptions=ces$
" Set the status line the way i like it
set stl=%f\ %m\ %r\ Line:%l/%L[%p%%]\ Col:%c\ Buf:%n\ [%b][0x%B]\ %=[%{GitBranch()}]
" tell VIM to always put a status line in, even if there is only one window
set laststatus=2
" Don't update the display while executing macros
set lazyredraw
" Show the current command in the lower right corner
set showcmd
" Show the current mode
set showmode
" Switch on syntax highlighting.
syntax on
" Hide the mouse pointer while typing
set mousehide
" Set up the gui cursor to look nice
set guicursor=n-v-c:block-Cursor-blinkon0
set guicursor+=ve:ver35-Cursor
set guicursor+=o:hor50-Cursor
set guicursor+=i-ci:ver25-Cursor
set guicursor+=r-cr:hor20-Cursor
set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
" set the gui options the way I like
set guioptions=ac
" This is the timeout used while waiting for user input on a multi-keyed macro
" or while just sitting and waiting for another key to be pressed measured
" in milliseconds.
"
" i.e. for the ",d" command, there is a "timeoutlen" wait period between the
" "," key and the "d" key. If the "d" key isn't pressed before the
" timeout expires, one of two things happens: The "," command is executed
" if there is one (which there isn't) or the command aborts.
set timeoutlen=500
" Keep some stuff in the history
set history=100
" These commands open folds
set foldopen=block,insert,jump,mark,percent,quickfix,search,tag,undo
" When the page starts to scroll, keep the cursor 8 lines from the top and 8
" lines from the bottom
set scrolloff=3
" Allow the cursor to go in to "invalid" places
set virtualedit=all
" These things start comment lines
set comments=sl:/*,mb:\ *,ex:\ */,O://,b:#,:%,:XCOMM,n:>,fb:-
" Disable encryption (:X)
set key=
" Make the command-line completion better
set wildmenu
" Same as default except that I remove the 'u' option
set complete=.,w,b,t
" When completing by tag, show the whole tag, not just the function name
set showfulltag
" Set the textwidth to be 120 chars
set textwidth=120
" get rid of the silly characters in window separators
set fillchars=""
" Turn tabs into spaces
set expandtab
" Add ignorance of whitespace to diff
set diffopt+=iwhite
" Enable search highlighting
set hlsearch
" Incrementally match the search
set incsearch
" Initial path seeding
set path=
set path+=/usr/local/include/**
set path+=/usr/include/**
set path+=~/code/**
" Set the tags files to be the following
set tags=./tags,tags
" Let the syntax highlighting for Java files allow cpp keywords
let java_allow_cpp_keywords = 1
" Toggle paste mode
nmap <silent> ,p :set invpaste<CR>:set paste?<CR>
" cd to the directory containing the file in the buffer
nmap <silent> ,cd :lcd %:h<CR>
nmap <silent> ,md :!mkdir -p %:p:h<CR>
" Turn off that stupid highlight search
nmap <silent> ,n :set invhls<CR>:set hls?<CR>
" put the vim directives for my file editing settings in
nmap <silent> ,vi
\ ovim:set ts=4 sts=4 sw=4:<CR>vim600:fdm=marker fdl=1 fdc=0:<ESC>
" Show all available VIM servers
nmap <silent> ,ss :echo serverlist()<CR>
" The following beast is something i didn't write... it will return the
" syntax highlighting group that the current "thing" under the cursor
" belongs to -- very useful for figuring out what to change as far as
" syntax highlighting goes.
nmap <silent> <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name")
\ . '> trans<' . synIDattr(synID(line("."),col("."),0),"name")
\ . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name")
\ . ">"<CR>
" set text wrapping toggles
nmap <silent> ,w :set invwrap<CR>:set wrap?<CR>
" Run the command that was just yanked
nmap <silent> ,rc :@"<cr>
" allow command line editing like emacs
cnoremap <C-A> <Home>
cnoremap <C-B> <Left>
cnoremap <C-E> <End>
cnoremap <C-F> <Right>
cnoremap <C-N> <End>
cnoremap <C-P> <Up>
cnoremap <ESC>b <S-Left>
cnoremap <ESC><C-B> <S-Left>
cnoremap <ESC>f <S-Right>
cnoremap <ESC><C-F> <S-Right>
cnoremap <ESC><C-H> <C-W>
" Maps to make handling windows a bit easier
noremap <silent> ,h :wincmd h<CR>
noremap <silent> ,j :wincmd j<CR>
noremap <silent> ,k :wincmd k<CR>
noremap <silent> ,l :wincmd l<CR>
noremap <silent> ,sb :wincmd p<CR>
noremap <silent> <C-F9> :vertical resize -10<CR>
noremap <silent> <C-F10> :resize -10<CR>
noremap <silent> <C-F11> :resize +10<CR>
noremap <silent> <C-F12> :vertical resize +10<CR>
noremap <silent> ,s8 :vertical resize 83<CR>
noremap <silent> ,cj :wincmd j<CR>:close<CR>
noremap <silent> ,ck :wincmd k<CR>:close<CR>
noremap <silent> ,ch :wincmd h<CR>:close<CR>
noremap <silent> ,cl :wincmd l<CR>:close<CR>
noremap <silent> ,cc :close<CR>
noremap <silent> ,cw :cclose<CR>
noremap <silent> ,ml <C-W>L
noremap <silent> ,mk <C-W>K
noremap <silent> ,mh <C-W>H
noremap <silent> ,mj <C-W>J
noremap <silent> <C-7> <C-W>>
noremap <silent> <C-8> <C-W>+
noremap <silent> <C-9> <C-W>+
noremap <silent> <C-0> <C-W>>
" Map CTRL-E to do what ',' used to do
nnoremap <c-e> ,
vnoremap <c-e> ,
" Buffer commands
noremap <silent> ,bd :bd<CR>
" Edit the vimrc file
nmap <silent> ,ev :e $MYVIMRC<CR>
nmap <silent> ,sv :so $MYVIMRC<CR>
" map keys to jump
nmap j gj
nmap k gk
" The value of 'showbreak' is used to put in front of wrapped lines.
" Dealing with sudo
cmap w!! w !sudo tee %
" Line break a word
set linebreak
" Make horizontal scrolling easier
" nmap <silent> <C-o> 10zl
" nmap <silent> <C-i> 10zh
" Highlight all instances of the current word under the cursor
" nmap <silent> ^ :setl hls<CR>:let @/="<C-r><C-w>"<CR>
" Search the current file for what's currently in the search
" register and display matches
nmap <silent> ,gs
\ :vimgrep /<C-r>// %<CR>:ccl<CR>:cwin<CR><C-W>J:set nohls<CR>
" Search the current file for the word under the cursor and display matches
nmap <silent> ,gw
\ :vimgrep /<C-r><C-w>/ %<CR>:ccl<CR>:cwin<CR><C-W>J:set nohls<CR>
" Search the current file for the WORD under the cursor and display matches
nmap <silent> ,gW
\ :vimgrep /<C-r><C-a>/ %<CR>:ccl<CR>:cwin<CR><C-W>J:set nohls<CR>
" Swap two words
nmap <silent> gw :s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<CR>`'
" Underline the current line with '='
nmap <silent> ,ul :t.\|s/./=/g\|set nohls<cr>
" Delete all buffers
nmap <silent> ,da :exec "1," . bufnr('$') . "bd"<cr>
" Syntax coloring lines that are too long just slows down the world
set synmaxcol=2048
" I don't like it when the matching parens are automatically highlighted
let loaded_matchparen = 1
"-----------------------------------------------------------------------------
" MiniBufExplorer Plugin Settings
"-----------------------------------------------------------------------------
" Yup, I don't like this one either
let loaded_minibufexplorer = 1
"-----------------------------------------------------------------------------
" ShowMarks Plugin Stuff
"-----------------------------------------------------------------------------
" I don't think I like this
let g:loaded_showmarks = 1
"-----------------------------------------------------------------------------
" Source Explorer Plugin Settings
"-----------------------------------------------------------------------------
" The switch of the Source Explorer
nmap <silent> <F8> :SrcExplToggle<CR>
" Set the height of Source Explorer window
let g:SrcExpl_winHeight = 16
" Set 10 ms for refreshing the Source Explorer
let g:SrcExpl_refreshTime = 10
" In order to Avoid conflicts, the Source Explorer should know what plugins
" are using buffers. And you need add their bufname into the list below
" according to the command ":buffers!"
let g:SrcExpl_pluginList = [
\ "_NERD_tree_",
\ "Source_Explorer"
\ ]
" Enable/Disable the local definition searching, and note that this is not
" guaranteed to work, the Source Explorer doesn't check the syntax for now.
" It only searches for a match with the keyword according to command 'gd'
let g:SrcExpl_searchLocalDef = 1
" Do not let the Source Explorer update the tags file when opening
let g:SrcExpl_isUpdateTags = 0
" Use program 'ctags' with argument '--sort=foldcase -R' to create or
" update a tags file
let g:SrcExpl_updateTagsCmd = "retag.ksh"
" Set "<F9>" key for updating the tags file artificially
let g:SrcExpl_updateTagsKey = "<F9>"
"-----------------------------------------------------------------------------
" NERD Tree Plugin Settings
"-----------------------------------------------------------------------------
" Toggle the NERD Tree on an off with F7
nmap <F7> :NERDTreeToggle<CR>
" Close the NERD Tree with Shift-F7
nmap <S-F7> :NERDTreeClose<CR>
" Store the bookmarks file in perforce
let NERDTreeBookmarksFile="~/.vim/NERDTreeBookmarks"
" Show the bookmarks table on startup
let NERDTreeShowBookmarks=1
" Don't display these kinds of files
let NERDTreeIgnore=[ '\.ncb$', '\.suo$', '\.vcproj\.RIMNET', '\.obj$',
\ '\.ilk$', '^BuildLog.htm$', '\.pdb$', '\.idb$',
\ '\.embed\.manifest$', '\.embed\.manifest.res$',
\ '\.intermediate\.manifest$', '^mt.dep$' ]
"-----------------------------------------------------------------------------
" FSwitch Settings
"-----------------------------------------------------------------------------
nmap <silent> ,of :FSHere<CR>
nmap <silent> ,ol :FSRight<CR>
nmap <silent> ,oL :FSSplitRight<CR>
nmap <silent> ,oh :FSLeft<CR>
nmap <silent> ,oH :FSSplitLeft<CR>
nmap <silent> ,ok :FSAbove<CR>
nmap <silent> ,oK :FSSplitAbove<CR>
nmap <silent> ,oj :FSBelow<CR>
nmap <silent> ,oJ :FSSplitBelow<CR>
"-----------------------------------------------------------------------------
" SnipMate Settings
"-----------------------------------------------------------------------------
"source ~/.vim/snippets/support_functions.vim
"source ~/.vim/snippets/support_functions_derek.vim
function! ListKnownSnippetLanguageTypes(A, L, P)
let filesanddirs = split(globpath(g:snippets_dir, a:A . "*"), "\n")
let dirsonly = []
for f in filesanddirs
if isdirectory(f)
let each = split(f, '/')
let dirsonly = add(dirsonly, each[-1])
end
endfor
return dirsonly
endfunction
function! ReloadSnippets(type)
call ResetSnippets()
if a:type != ""
call ExtractSnips(g:snippets_dir . a:type, a:type)
else
let alltypes = ListKnownSnippetLanguageTypes("", "", "")
for type in alltypes
call ExtractSnips(g:snippets_dir . type, type)
endfor
endif
endfunction
command! -complete=customlist,ListKnownSnippetLanguageTypes
\ -nargs=? RS call ReloadSnippets("<args>")
"-----------------------------------------------------------------------------
" FuzzyFinder Settings
"-----------------------------------------------------------------------------
nmap ,fb :FuzzyFinderBuffer<CR>
nmap ,ff :FuzzyFinderFile<CR>
nmap ,ft :FuzzyFinderTag<CR>
"-----------------------------------------------------------------------------
" UltiSnips Settings
"-----------------------------------------------------------------------------
"set runtimepath+=~/.vim/ultisnips
"let g:UltiSnipsExpandTrigger="<c-9>"
"let g:UltiSnipsJumpForwardTrigger="<c-j>"
"let g:UltiSnipsJumpBackwardTrigger="<c-k>"
"-----------------------------------------------------------------------------
" Functions
"-----------------------------------------------------------------------------
function! RunSystemCall(systemcall)
let output = system(a:systemcall)
let output = substitute(output, "\n", '', 'g')
return output
endfunction
"-----------------------------------------------------------------------------
" Auto commands
"-----------------------------------------------------------------------------
augroup derek_scons
au!
au BufNewFile,BufRead SCons* setf scons
augroup END
augroup derek_xsd
au!
au BufEnter *.xsd,*.wsdl,*.xml setl tabstop=4 | setl shiftwidth=4
au BufEnter *.xsd,*.wsdl,*.xml setl formatoptions=crq | setl textwidth=80
augroup END
augroup Binary
au!
au BufReadPre *.bin let &bin=1
au BufReadPost *.bin if &bin | %!xxd
au BufReadPost *.bin set filetype=xxd | endif
au BufWritePre *.bin if &bin | %!xxd -r
au BufWritePre *.bin endif
au BufWritePost *.bin if &bin | %!xxd
au BufWritePost *.bin set nomod | endif
augroup END
"-----------------------------------------------------------------------------
" Fix constant spelling mistakes
"-----------------------------------------------------------------------------
iab teh the
iab Teh The
iab taht that
iab Taht That
iab alos also
iab Alos Also
iab aslo also
iab Aslo Also
iab becuase because
iab Becuase Because
iab bianry binary
iab Bianry Binary
iab bianries binaries
iab Bianries Binaries
iab charcter character
iab Charcter Character
iab charcters characters
iab Charcters Characters
iab exmaple example
iab Exmaple Example
iab exmaples examples
iab Exmaples Examples
iab shoudl should
iab Shoudl Should
iab seperate separate
iab Seperate Separate
iab fone phone
iab Fone Phone
"-----------------------------------------------------------------------------
" Set up the window colors and size
"-----------------------------------------------------------------------------
if has("gui_running")
set guifont=Monaco:h12
colorscheme xoria256
set macmeta
if !exists("g:vimrcloaded")
winpos 0 0
if ! &diff
winsize 88 30
else
winsize 180 40
endif
let g:vimrcloaded = 1
endif
endif
:nohls
"-----------------------------------------------------------------------------
" Auto-configs my on tips file
" From: http://djcraven5.blogspot.com/2006/10/mastering-vim-help-system.html
"-----------------------------------------------------------------------------
autocmd BufWrite mytips.txt :helptags ~/.vim/doc/
nmap <leader>h :tabnew ~/.vim/doc/mytips.txt<CR>
"-----------------------------------------------------------------------------
" Restore cursor in previous eiting seesion
" From: http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session
"-----------------------------------------------------------------------------
" Tell vim to remember certain things when we exit
" '10 : marks will be remembered for up to 10 previously edited files
" "100 : will save up to 100 lines for each register
" :20 : up to 20 lines of command-line history will be remembered
" % : saves and restores the buffer list
" n... : where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo
" when we reload, tell vim to restore the cursor to the saved position
augroup JumpCursorOnEdit
au!
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
" 修复Terminal.app 的 Meta key
" http://vim.wikia.com/wiki/Fix_meta-keys_that_break_out_of_Insert_mode
for i in range(65,90) + range(97,122)
let c = nr2char(i)
exec "map \e".c." <M-".c.">"
exec "map! \e".c." <M-".c.">"
endfor
" VIM Tip: 上下移动一行或多行代码并自动调整缩进_drdr_xp_百度空间 http://goo.gl/3wt0
nnoremap <C-k> mz:m-2<cr>`z==
nnoremap <C-j> mz:m+<cr>`z==
" 一下是在Visual下的情况
xnoremap <C-k> :m'<-2<cr>gv=gv
xnoremap <C-j> :m'>+<cr>gv=gv
" 在当前位置的上(下)方增加,删除一行
"nnoremap <silent><M-j> :set paste<CR>m`o<Esc>``:set nopaste<CR>
"nnoremap <silent><M-k> :set paste<CR>m`O<Esc>``:set nopaste<CR>
:set <M-j>=^]j
nnoremap <M-j> :set paste<CR>m`o<Esc>``:set nopaste<CR>
nnoremap <M-k> :set paste<CR>m`O<Esc>``:set nopaste<CR>
" Command Line Stuff (to match bash behavior) 模仿bash的行为
" 用 p: 调出历史菜单
:cnoremap <M-b> <S-Left>
:cnoremap <M-f> <S-Right>
:cnoremap <C-d> <Del>
:cnoremap <M-d> <C-Del>
:cnoremap <M-BS> <C-W>
" Create new tab with specific buffer
command -nargs=1 -complete=buffer Tb :tab sb <args>
noremap <silent> ,ct :tabc<CR>
" Test Section