-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvimrc
More file actions
525 lines (450 loc) · 15.2 KB
/
vimrc
File metadata and controls
525 lines (450 loc) · 15.2 KB
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
" VIM main configuration file
"=============Built-in settings=============
" Basic {
set nocompatible " ignore vi compatibility
set visualbell " no beep
set history=100
"override the default leader '\'
let mapleader = ','
"swap comma and backslash to avoid delay caused by the above setting
nn , \
nn \ ,
" load utils.vim to perform some initialization
call utils#init(expand('<sfile>:p'))
" run shell
nmap <Leader>R :sh<CR>
" }
" Format {
" autowrap comments using textwidth and insert the current comment leader
set formatoptions+=c
" automatically insert a comment leader after an enter
set formatoptions+=r
" automatically insert the current comment leader after 'o' or 'O'
set formatoptions+=o
" allow formatting of comments with 'gq'
set formatoptions+=q
" long lines are not broken in insert mode
set formatoptions+=l
" do no auto-wrap text using textwidth (does not apply to comments)
set formatoptions-=t
" }
" Indentation/Tab {
" turn off C indentation, and set the comments option to the default.
"c/c++ type will override this in ftplugin
au FileType * set nocindent comments&
set autoindent
set shiftwidth=4 " set shift width or the size of an indentation.
" disable auto indentation
nn <Leader>I :setl noai nocin nosi inde=<CR>
set tabstop=4
set softtabstop=4
" insert tabs as spaces
set expandtab
" in front of a line inserts blanks according to 'shiftwidth', a <BS>
" will delete a 'shiftwidth' worth of space at the start of the line.
set smarttab
filetype plugin indent on
" }
" Fold {
set nofoldenable " don't fold by default
set foldnestmax=4 " deepest fold
set foldlevel=2 "not work?
nmap <Leader>f0 :setl foldlevel=0<CR>
nmap <Leader>f1 :setl foldlevel=1<CR>
nmap <Leader>f2 :setl foldlevel=2<CR>
nmap <Leader>f3 :setl foldlevel=3<CR>
nmap <Leader>f4 :setl foldlevel=4<CR>
nmap <Leader>f5 :setl foldlevel=5<CR>
nmap <Leader>f6 :setl foldlevel=6<CR>
nmap <Leader>f7 :setl foldlevel=7<CR>
nmap <Leader>f8 :setl foldlevel=8<CR>
nmap <Leader>f9 :setl foldlevel=9<CR>
" }
" Search {
set hlsearch " highlight the target of a search.
set incsearch " incremental search
set ignorecase " Ignore case when search
" toggle case ignore
nmap <Leader>C :set ignorecase! ignorecase?<CR>
set smartcase
set nowrapscan " No wrap scan when search
" toggle search highlighting
nmap <silent> <Leader>/ :set hls!<bar>set hls?<CR>
" }
" Move/Jump {
" facilitate screen move
nmap <Space> <C-F>
nmap <S-Space> <C-B>
"nmap <CR> <C-D>
nmap <BS> <C-U>
nmap <down> <C-E>
nmap <up> <C-Y>
" go to older jump position(constrast with Tab or C-I)
nmap <S-Tab> <C-O>
" }
" Edit {
set showmode
set linebreak " avoid wrapping a word
set showmatch " show parentheses matching
" allow BS to delete newlines and beyond the start of the insertion point
set backspace=2
set whichwrap=b,s,h,l,<,>,[,] " allow the cursor to wrap on anything
set nojoinspaces " don't add two spaces after ., ?, !
set report=0 " report all line change
set pastetoggle=<F2> " paste toggle (sane indentation on pastes)
set gdefault " set g as default when substitute
set nrformats+=alpha
" auto complete {
"set complete=.,w,b,u,t,i,k,s
set complete=.,w,b,u,t,i
"set completeopt=longest,menu
set completeopt=menuone,longest,preview
set omnifunc=syntaxcomplete#Complete
" Omni completion
ino <S-Space> <C-X><C-O>
" }
" block editing {
vmap <Tab> >gv
vmap <S-Tab> <gv
" }
" Spell {
set dictionary+=/usr/share/dict/words
set thesaurus+=/usr/share/dict/mthesaur.txt
exe 'set spellfile=' . g:VIMFILES . '/spell/en.utf-8.add'
" toggle spell checking
nmap <F3> :setl spell! spelllang=en_gb<CR>
" }
" Encoding {
set encoding=utf-8
" for MacVim
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
" }
" Whitespace {
" toggle highlighting problematic whitespace
nmap <F4> :setl list! list?<CR>
set listchars=tab:>.,trail:.,extends:#,nbsp:.
" }
" }
" File {
" automatically read outside change
set autoread
" automatically write files as needed.
set autowrite
" automatically save when focus is lost
au BufLeave,FocusLost * silent! wa
" hide buffer instead of closing
set hidden
set wildmode=longest,full
" suffixes to put to the end of the list when completing file names
set suffixes=.bak,~,.o,.class,.info,.swp
" patterns to put to ignore when completing file names
set wildignore=*.bak,~,*.o,*.info,*.swp,*.class,*.pyc,.git,.svn
" swap directory(double slash means keep full path)
exe 'set dir='. g:VIMTMP . '/swap//'
set backup " turn on backup
set writebackup " turn on write backup
" backup directory
exe 'set backupdir='. g:VIMTMP . '/backup//'
set backupext=~
if exists('&undofile')
set undofile
" set max number of changes that can be undone
set undolevels=1000
" set max number lines to save for undo on a buffer reload
set undoreload=10000
exe 'set undodir='. g:VIMTMP . '/undo'
endif
" set a stronger encryption
if version >= 703
set cryptmethod=blowfish
endif
" }
" Save state {
" do not store global and local values in a session
set sessionoptions-=options
"set sessionoptions-=curdir
"set sessionoptions+=sesdir
" do not store empty windows(avoid nerdtree problem)
set sessionoptions-=blank
if has('gui_running') && g:LOAD_PLUGIN " auto change session in heavy GUI
au VimEnter * nested :call utils#loadSession()
au VimLeave * :call utils#updateSession()
endif
nmap <Leader>ss :call utils#saveSession()<CR>
" save viminfo
exe 'set viminfo+=n' . g:VIMTMP . '/viminfo'
" save view records
exe 'set viewdir='. g:VIMTMP . '/view'
au BufWinLeave * silent! mkview
au BufWinEnter * silent! loadview
" make 'crontab -e' work
if $VIM_CRONTAB == 'true'
set nobackup
set nowritebackup
endif
" }
" Window/Tab/Buffer {
" window
"nmap <Tab> <c-w>w
"nmap <Leader>P <c-w>p
nmap <Leader>V <c-w>v
"nmap <Leader>V :vs<SPACE>
nmap <Leader>S <c-w>s
"nmap <Leader>S :sp<SPACE>
"nmap <ESC>q <c-w>q
"nmap <down> <c-w>j
"nmap <up> <c-w>k
nmap <left> <c-w>h
nmap <right> <c-w>l
"nmap <Leader>N <c-w>n
"nmap <Leader>O <c-w>o
" Tab
"nmap <S-Tab> :tabnew<CR>
nmap <C-M-left> :tabprevious<CR>
imap <C-M-left> <ESC>:tabprevious<CR>
nmap <C-M-right> :tabnext<CR>
imap <C-M-right> <ESC>:tabnext<CR>
nmap <C-M-up> :tabfirst<CR>
imap <C-M-up> <ESC>:tabfirst<CR>
nmap <C-M-down> :tablast<CR>
imap <C-M-down> <ESC>:tablast<CR>
" Buffer navigation
nmap <C-BS> :bd<CR>
nmap <C-left> :bp<CR>
imap <C-left> <ESC>:bp<CR>
nmap <C-right> :bn<CR>
imap <C-right> <ESC>:bn<CR>
nmap <C-up> :bf<CR>
imap <C-up> <ESC>:bf<CR>
nmap <C-down> :bl<CR>
imap <C-down> <ESC>:bl<CR>
"map <F5> :prev<CR>
"map <F6> :n<CR>
"map <S-F5> :fir<CR>
"map <S-F6> :la<CR>
" Buffer manipulation
" avoid conflicting with 'q' command(for recording)
" all the following use single letter not only for quick type, but also
" for quick response(same prefix will delay vim)
nmap <Leader><Leader> :q<CR>
nmap <Leader>q :q!<CR>
nmap <Leader>x :qa<CR>
nmap <Leader>X :qa!<CR>
imap <F5> <Esc>:up<cr>
nmap <F5> :up<cr>
" save with root's permission
"cmap w!! w !sudo tee % >/dev/null
nmap <Leader>w :w !sudo tee % >/dev/null<CR><CR>
"map <S-CR> :w<CR>
"map <F4> :w<CR>
"map! <F4> <ESC>:w<CR>
"map! <S-F4> <ESC>ZZ
" display messages
nmap <F11> :messages<CR>
imap <F11> <ESC>:messages<CR>
" show the full path of the current buffer
nmap <C-F10> :echo expand('%:p')<CR>
" }
" External {
nn <silent> <S-CR> :call utils#openUrl()<CR><CR>
nn <silent> <S-leftmouse> :call utils#openUrl()<CR><CR>
" }
" GUI {
syntax on " turn on syntax highlighting
set mouse=a
set ttyfast
"set selection=exclusive
"set selectmode=mouse,key
"behave xterm
set term=$TERM " default
if has('gui_running')
" mostly are put into .gvimrc
color hui
"color solarized
else
if g:LOAD_PLUGIN " make sure color plugin is loaded
color spring
endif
"set term=builtin_ansi " make arrow and other keys work
" tab
set tabline=%!utils#tabLine()
hi TabLineSel ctermfg=red ctermbg=gray cterm=NONE
hi TabLineFill ctermfg=darkgray ctermbg=NONE cterm=underline
hi TabLine ctermfg=darkgray ctermbg=NONE cterm=underline
" cursor
set cursorline
"hi CursorLine ctermbg=lightgray cterm=NONE
set cursorcolumn
"hi CursorColumn ctermbg=lightgray
" highlight cursor
endif
set showcmd " show partially typed commands
set ruler " show the ruler
" set ruler format: length, column, percentage, total lines,
" chop position, middle position, filename, modification and read-only flag
set rulerformat=%40(%4l,%2v(%p%%\ of\ \%L)%<%=%8.20t%m%R%)
if has('statusline')
set laststatus=2 " always show status
set statusline=%<%f\ " filename
set statusline+=%w%h%m%r " options
set statusline+=\ [%{&ff}/%Y] " filetype
"set statusline+=\ [%{getcwd()}] " current dir
"set statusline+=\ [A=\%03.3b/H=\%02.2B] " ASCII/Hex value of char
" show right aligned file nav info
set statusline+=%=%-14.(%l,%c%V%)\ %p%%\ of\ \%L
endif
" line {
nmap <Leader>CC :call utils#toggleColorColumn()<cr>
setl number
"if exists('&relativenumber') && &modifiable
"setl relativenumber
"else
"setl number
"endif
nmap <F6> :call utils#toggleNumber()<cr>
imap <F6> <Esc>:call utils#toggleNumber()<cr>
" }
" }
"=============External programs=============
" read/write PDF
" warning: writing PDF will lose format
if executable('pdftotext')
augroup Pdf
au!
au BufReadPre *.pdf set readonly nowrap
au BufReadPost *.pdf silent %!pdftotext "%" -nopgbrk -layout -q -eol unix -
"au BufReadPost *.pdf silent %!pdftotext -nopgbrk "%" - |fmt -csw78
au BufWritePost *.pdf call utils#savePdf()
augroup END
endif
" read Word
if executable('antiword')
augroup Word
au!
au BufReadPre *.doc set readonly
au BufReadPost *.doc %!antiword "%"
augroup END
endif
"=============Plugin settings=============
if utils#enabledPlugin('nerdtree') > 0
"load NERDTree on startup, but command line alias is prefered
"au VimEnter * NERDTree
"highlight main window
au VimEnter * silent! wincmd p
"map :NERDTreeToggle
nmap <silent> <Leader>E :NERDTreeToggle<CR>:NERDTreeMirror<CR>
"nmap <ESC>e :NERDTreeToggle<CR><C-W><C-S><C-W><C-J>:BufExplorer<CR>
let NERDTreeIgnore = ['\.o', '\.class', '\.pyc',
\ '\~$', '\.swo$', '\.swp$',
\ '\.git', '\.hg', '\.svn']
"set autochdir
let NERDTreeChDirMode = 2
nn <Leader>. :NERDTree .<CR>
ca nt NERDTree
ca bm Bookmark
endif
if utils#enabledPlugin('bufexplorer') > 0
"built-in <Leader>be
"nmap <Leader>b :BufExplorer<CR>
let g:bufExplorerSplitVertical = 1
let g:bufExplorerSortBy = 'mru'
let g:bufExplorerUseCurrentWindow = 1
let g:bufExplorerShowRelativePath = 1
let g:bufExplorerDefaultHelp = 0
endif
if utils#enabledPlugin('fuzzyfinder') > 0
nmap <Leader><Space> :FufBuffer<CR>
nmap <Leader>e :FufFile<CR>
"nmap <Leader>g :FufTaggedFile<CR>
"nmap <Leader>d :FufDir<CR>
"nmap <Leader>t :FufTag<CR>
endif
if utils#enabledPlugin('command-t') > 0
nmap <Leader><Space> :CommandTBuffer<CR>
nmap <Leader>e :CommandT<CR>
nmap <Leader>y :CommandTFlush<CR>
"let g:CommandTSearchPath = $HOME . '$HOME/Projects'
let g:CommandTMatchWindowAtTop = 1
let g:CommandTMaxFiles = 20000
endif
if utils#enabledPlugin('supertab') > 0
let g:SuperTabDefaultCompletionType = 'context'
"let g:SuperTabMappingTabLiteral = '<c-tab>' " default
"let g:SuperTabCrMapping = 0
endif
if utils#enabledPlugin('snipmate') > 0
let g:snips_author = expand($USER_FULLNAME)
let g:author = expand($USER_FULLNAME)
let g:snips_email = expand($USER_EMAIL)
let g:email = expand($USER_EMAIL)
let g:snips_github = expand($USER_GITHUB)
let g:github = expand($USER_GITHUB)
"nn <Leader>rs <esc>:exec ReloadAllSnippets()<cr>
endif
if utils#enabledPlugin('tabular') > 0
nmap <Leader>z= :Tabularize /=<CR>
vmap <Leader>z= :Tabularize /=<CR>
nmap <Leader>z: :Tabularize /:<CR>
vmap <Leader>z: :Tabularize /:<CR>
nmap <Leader>z:: :Tabularize /:\zs<CR>
vmap <Leader>z:: :Tabularize /:\zs<CR>
nmap <Leader>z, :Tabularize /,<CR>
vmap <Leader>z, :Tabularize /,<CR>
nmap <Leader>z\ :Tabularize /<bar><CR>
vmap <Leader>z\ :Tabularize /<bar><CR>
endif
if utils#enabledPlugin('calendar') > 0
"nmap <ESC>c :Calendar<CR>
nmap <Leader>Ca :Calendar<CR>
"cmap cal Calendar<SPACE>
"cmap caL CalendarH<SPACE>
let calendar_diary = '$DIARY_DIR'
au BufNewFile *.cal call utils#calInit()
endif
if utils#enabledPlugin('ack') > 0
" improve grep if possible
set grepprg=ack\ -a
nmap <Leader>a :Ack<SPACE>
endif
if utils#enabledPlugin('gundo') > 0
nmap <leader>U :GundoToggle<CR>
endif
if utils#enabledPlugin('fugitive') > 0
nmap <Leader>ge :Gedit<Space>
nmap <Leader>gb :Gblame<CR>
nmap <Leader>gs :Gstatus<CR>
nmap <Leader>gc :Gcommit<CR>
nmap <Leader>gd :Gdiff<CR>
nmap <Leader>gD :Gsdiff<CR>
nmap <Leader>gl :Glog<CR>
nmap <Leader>gr :Gread<CR>
nmap <Leader>gw :Gwrite<CR>
nmap <Leader>gr :GBrowse<CR>
vmap <Leader>gr :GBrowse<CR>
" show status
" set statusline+=%{fugitive#statusline()}
endif
if utils#enabledPlugin('vcscommand') > 0
nmap <Leader>va <Plug>VCSAdd
nmap <Leader>vb <Plug>VCSAnnotate
nmap <Leader>vB <Plug>VCSAnnotate!
nmap <Leader>vc <Plug>VCSCommit
nmap <Leader>vd <Plug>VCSDiff
nmap <Leader>vD <Plug>VCSDelete
nmap <Leader>vg <Plug>VCSGotoOriginal
nmap <Leader>vG <Plug>VCSGotoOriginal!
nmap <Leader>vi <Plug>VCSInfo
nmap <Leader>vl <Plug>VCSLog
nmap <Leader>vL <Plug>VCSLock
nmap <Leader>vr <Plug>CSReview
nmap <Leader>vs <Plug>VCSStatus
nmap <Leader>vu <Plug>VCSUpdate
nmap <Leader>vU <Plug>VCSUnlock
nmap <Leader>vv <Plug>VCSVimDiff
endif
if utils#enabledPlugin('tasklist') > 0
nmap <leader>tl <Plug>TaskList
let g:tlTokenList = ['FIXME', 'TODO', 'XXX', 'HACK']
endif
" NOTE: For program-specific or filetype-specific plugin settings,
" we manage to put them into program.vim or <filetype>.vim under ftplugin