-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
546 lines (478 loc) · 15.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
"" Kang Seonghoon's .vimrc file (2010-01-05)
"" This file is placed in the public domain.
"" Recent version of this file is always available at:
"" http://hg.mearie.org/private/settings-vim/
"" =========================================================
scripte utf-8
set nocp all&
" CUSTOMIZING by hodduc {{{ --------------------------------
" Force terminal to use 256color (to use powerline)
set term=xterm-256color
" Vim Bundle Installation
set nocompatible
filetype on
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
" UI integration
Bundle 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim'}
Bundle 'fholgado/minibufexpl.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'Valloric/YouCompleteMe'
" Bundle 'ervandew/supertab'
Bundle 'mileszs/ack.vim'
" Bundle 'davidhalter/jedi-vim'
" Bundle 'moll/vim-node'
" Bundle 'capslock.vim'
" color schemes
Bundle 'molokai'
Bundle 'altercation/vim-colors-solarized'
Bundle 'summerfruit256.vim'
" git integration
Bundle 'tpope/vim-fugitive'
" Python pack
Bundle 'klen/python-mode'
Bundle 'ekalinin/Dockerfile.vim'
Bundle 'fatih/vim-go'
Bundle 'cstrahan/vim-capnp'
Bundle 'majutsushi/tagbar'
let g:Powerline_symbols = 'fancy'
filetype plugin indent on
" vim-go keymapping
let g:go_fmt_command = "goimports"
let g:go_highlight_operators = 1
let g:go_highlight_functions = 1
let g:go_highlight_structs = 1
" let g:go_auto_type_info = 1
au FileType go nmap <F1> <Plug>(go-doc)<CR>
au FileType go nmap <F2> <Plug>(go-doc-browser)<CR>
au FileType go nmap <F5> <Plug>(go-run)<CR>
au FileType go nmap <F6> <Plug>(go-test)<CR>
au FileType go nmap <F7> <Plug>(go-build)<CR>
au FileType go nmap <F8> :Tagbar<CR>
set cursorline
" CUSTOMIZING end }}} -------------------------------------
" UTILITY FUNCTIONS {{{ ------------------------------------
" maps key to the command in insert, normal, and (if vmap=1) visual mode
fu! s:Map(key, value, vmap)
exe 'imap <silent> ' . a:key . ' <C-\><C-O>' . a:value
exe 'nmap <silent> ' . a:key . ' ' . a:value
if a:vmap | exe 'vmap <silent> ' . a:key . ' <Esc>' . a:value . 'gv' | endif
endf
" maps two keys to the command if needed. used for mac's Command key
fu! s:Map2(key1, key2, value, vmap)
call s:Map(a:key1, a:value, a:vmap)
if has("macunix") | call s:Map(a:key2, a:value, a:vmap) | endif
endf
" maps key to the function
fu! s:MapFunc(key, fname, vmap)
call s:Map(a:key, ':call <SID>' . a:fname . '()<CR>', a:vmap)
endf
" creates the directory if not exists
fu! s:MakeDir(path)
if glob(a:path) == ''
try
call mkdir(a:path, 'p')
catch /^Vim(mkdir):/
endtry
endif
endf
" }}} ------------------------------------------------------
" TERMINAL {{{ ---------------------------------------------
if &term =~ "xterm"
set t_Co=8
if has("terminfo")
let &t_Sf = "\<Esc>[3%p1%dm"
let &t_Sb = "\<Esc>[4%p1%dm"
else
let &t_Sf = "\<Esc>[3%dm"
let &t_Sb = "\<Esc>[4%dm"
endif
endif
" terminal encoding (always use utf-8 if possible)
if !has("win32") || has("gui_running")
set enc=utf-8 tenc=utf-8
if has("win32")
set tenc=cp949
let $LANG = substitute($LANG, '\(\.[^.]\+\)\?$', '.utf-8', '')
endif
endif
if &enc ==? "euc-kr"
set enc=cp949
endif
" }}} ------------------------------------------------------
" EDITOR {{{ -----------------------------------------------
set nu ru sc wrap ls=2 lz " -- appearance
set noet bs=2 ts=8 sw=8 sts=0 " -- tabstop
set noai nosi hls is ic cf ws scs magic " -- search
set sol sel=inclusive mps+=<:> " -- moving around
set ut=10 uc=200 " -- swap control
set report=0 lpl wmnu " -- misc.
" encoding and file format
set fenc=utf-8 ff=unix ffs=unix,dos,mac
set fencs=utf-8,cp949,cp932,euc-jp,shift-jis,big5,latin2,ucs2-le
" list mode
set list lcs=extends:>,precedes:<
if &tenc ==? "utf-8"
set lcs+=tab:»\ ,trail:·
else
set lcs+=tab:\|\
endif
" }}} ------------------------------------------------------
" TEMPORARY/BACKUP DIRECTORY {{{ ---------------------------
set swf nobk bex=.bak
if exists("$HOME")
" makes various files written into ~/.vim/ or ~/_vim/
let s:home_dir = substitute($HOME, '[/\\]$', '', '')
if has("win32")
let s:home_dir = s:home_dir . '/_vim'
else
let s:home_dir = s:home_dir . '/.vim'
endif
if exists('*mkdir') && v:version >= 700
" automatically create directories for first time
call s:MakeDir(s:home_dir)
call s:MakeDir(s:home_dir . '/tmp')
call s:MakeDir(s:home_dir . '/backup')
endif
if isdirectory(s:home_dir)
let &dir = s:home_dir . '/tmp,' . &dir
let &bdir = s:home_dir . '/backup,' . &bdir
let &vi = &vi . ',n' . s:home_dir . '/viminfo'
endif
endif
" }}} ------------------------------------------------------
" KEY MAPPING {{{ ------------------------------------------
set wak=no " -- no alt menu mapping
set noto ttimeout tm=3000 ttm=100 " -- input timeout
let mapleader = '\'
" moving around and editing
map <MiddleMouse> <Nop>
map! <MiddleMouse> <Nop>
vmap <Tab> >gv
vmap <S-Tab> <gv
fu! s:HomeKey() " -- home key correction
let l:column = col('.') | exe "norm ^"
if l:column == col('.') | exe "norm 0" | endif
endf
call s:MapFunc('<Home>', 'HomeKey', 0)
" switching around buffer
map <F11> :bn<CR>
map <F12> :bN<CR>
if has("macunix")
map <D-F11> :bn<CR>
map <D-F12> :bN<CR>
endif
" make search appears in the middle of the screen
nmap n nzz
nmap N Nzz
nmap * *zz
nmap # #zz
nmap g* g*zz
nmap g# g#zz
" immediate buffer configuration
map <silent> <Leader>n :let &nu = 1 - &nu<CR>
map <silent> <Leader>l :let &list = 1 - &list<CR>
map <silent> <Leader>p :let &paste = 1 - &paste<CR>
map <silent> <Leader>w :let &wrap = 1 - &wrap<CR>
nmap <silent> <Leader>1 :set ts=1 sw=1<CR>
nmap <silent> <Leader>2 :set ts=2 sw=2<CR>
nmap <silent> <Leader>4 :set ts=4 sw=4<CR>
nmap <silent> <Leader>8 :set ts=8 sw=8<CR>
" editing and applying .vimrc
if has("win32")
nmap <silent> <Leader>R :so $HOME/_vimrc<CR>
nmap <silent> <Leader>rc :e $HOME/_vimrc<CR>
else
nmap <silent> <Leader>R :so $HOME/.vimrc<CR>
nmap <silent> <Leader>rc :e $HOME/.vimrc<CR>
endif
" inserting matching quotes
fu! s:InputQuotes()
if mode() == "R"
exe "normal \<Esc>" | return "" " -- beep
elseif match(getline("."), '\%u2018\%'.col('.').'c\%u2019') < 0
return "\u2018\u2019\<Insert>\<BS>\<Insert>"
else
return "\<Del>\<BS>\u201c\u201d\<Insert>\<BS>\<Insert>"
endif
endf
imap <silent> <C-'> <C-R>=<SID>InputQuotes()<CR>
" misc. mapping
nmap <silent> <Leader>cd :cd %:p:h<CR>
nmap <silent> <Leader><Space> :noh<CR>
" }}} ------------------------------------------------------
" ABBRIVATION {{{ ------------------------------------------
if has("digraphs")
dig +< 12296 >+ 12297 <+ 12298 +> 12299
endif
" }}} ------------------------------------------------------
" GUI {{{ --------------------------------------------------
if has("gui_running")
set go+=c go-=t go-=m go-=T sel=inclusive
set lines=40 co=100 lsp=0
set mouse=a " --TODO
colo desert
if has("transparency")
set transp=5
endif
" font fix
if has("win32")
silent! set gfn=Raize:h10 gfw=DotumChe:h11 lsp=-1
silent! set gfn=NanumGothicCoding:h10 gfw= lsp=0
elseif has("macunix")
silent! set macatsui gfn=Monaco:h12 gfw=AppleGothic\ Regular:h13
silent! set gfn=NanumGothicCoding:h13 gfw= lsp=1
endif
" toggle menubar
fu! s:MenuBar()
if stridx(&go, 'm') == -1
set go+=T go+=m
else
set go-=T go-=m
endif
endf
call s:MapFunc('<M-F10>', 'MenuBar', 1)
" toggle smaller and bigger font
let s:fontenlarged = 0
fu! s:FontSize()
if s:fontenlarged
let &gfn = substitute(&gfn, '\(:h\)\@<=\d\+', '\=submatch(0)/2', 'g')
let &gfw = substitute(&gfw, '\(:h\)\@<=\d\+', '\=submatch(0)/2', 'g')
exe ':winp ' . s:oldwinposx . ' ' . s:oldwinposy
let &lines = s:oldlines | let &columns = s:oldcolumns
else
let s:oldwinposx = getwinposx() | let s:oldwinposy = getwinposy()
let s:oldlines = &lines | let s:oldcolumns = &columns
let &gfn = substitute(&gfn, '\(:h\)\@<=\d\+', '\=submatch(0)*2', 'g')
let &gfw = substitute(&gfw, '\(:h\)\@<=\d\+', '\=submatch(0)*2', 'g')
endif
let s:fontenlarged = 1 - s:fontenlarged
endf
map <silent> <Leader>f :call <SID>FontSize()<CR>
" launching console
if has("win32")
fu! s:Console(path)
let l:path = iconv(a:path, &enc, &tenc)
silent exe "! start /d \"" . a:path . "\""
endf
elseif has("macunix")
fu! s:Console(path)
let l:path = iconv(a:path, &enc, &tenc)
silent !if ps x | grep -v grep | grep -q iTerm;
\ then osascript -e 'tell application "iTerm"
\ to tell the last terminal to launch session ""';
\ else osascript -e 'tell application "iTerm" to activate';
\ fi
silent exe "!osascript -e 'tell application \"iTerm\" " .
\ "to tell the last terminal to tell the last session " .
\ "to write text \"cd '\\''" . a:path . "'\\''; clear\"'"
endf
else
fu! s:Console(path)
echoerr ".vimrc: " . mapleader . "C is not enabled here."
endf
endif
nmap <silent> <Leader>C :call <SID>Console(expand("%:p:h"))<CR>
else
" update terminal title
set title titlestring=%{$USER}@%{hostname()}:\ %F\ (%l/%L)\ -\ VIM
endif
" share vim's own clipboard with system clipboard
if has("gui_running") || has("xterm_clipboard")
set cb=unnamed
endif
" macvim specific
" we cannot use has("gui_macvim") because normal vim also
" requires this change.
if match($VIM, 'MacVim\.app') >= 0
set imd
endif
" }}} ------------------------------------------------------
" SYNTAX {{{ -----------------------------------------------
syn enable
filet plugin indent on
let php_sync_method = 0
let html_wrong_comments = 1
" syntax extensions
fu! s:SyntaxExtHTML()
" HTML CDATA section
syn region htmlCdataSection matchgroup=htmlCdataDecl start=+<!\[CDATA\[+ end=+\]\]>+
syn cluster htmlTop add=htmlCdataSection
hi def link htmlCdataDecl htmlTag
endf
" }}} ------------------------------------------------------
" AUTOCMD {{{ ----------------------------------------------
if has("autocmd")
aug vimrc
au!
" filetype-specific configurations
au FileType python setl ts=8 sw=4 sts=4 et
au Filetype text setl tw=80
au FileType javascript,jsp setl cin
au FileType html,htmldjango setl ts=2 sts=2 sw=2 et
au FileType go setl ts=4 sts=4 sw=4
au BufNewFile,BufRead *.gbp setf json
au BufNewFile,BufRead *.phps,*.php3s setf php
" syntax extensions (see prior section for definition)
au Syntax html call s:SyntaxExtHTML()
au Syntax * syn sync minlines=500 maxlines=1000
" restore cursor position when the file has been read
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "norm g`\"" |
\ endif
" fix window position for mac os x
if has("gui_running") && has("macunix")
au GUIEnter *
\ if getwinposx() < 50 |
\ exe ':winp 50 ' . (getwinposy() + 22) |
\ endif
endif
" fix window size if window size has been changed
if has("gui_running")
fu! s:ResizeWindows()
let l:nwins = winnr("$") | let l:num = 1
let l:curtop = 0 | let l:curleft = 0
let l:lines = &lines - &cmdheight
let l:prevlines = s:prevlines - &cmdheight
let l:cmd = ""
while l:num < l:nwins
if l:curleft == 0
let l:adjtop = l:curtop * l:lines / l:prevlines
let l:curtop = l:curtop + winheight(l:num) + 1
if l:curtop < l:lines
let l:adjheight = l:curtop * l:lines / l:prevlines - l:adjtop - 1
let l:cmd = l:cmd . l:num . "resize " . l:adjheight . "|"
endif
endif
let l:adjleft = l:curleft * &columns / s:prevcolumns
let l:curleft = l:curleft + winwidth(l:num) + 1
if l:curleft < &columns
let l:adjwidth = l:curleft * &columns / s:prevcolumns - l:adjleft - 1
let l:cmd = l:cmd . "vert " . l:num . "resize " . l:adjwidth . "|"
else
let l:curleft = 0
endif
let l:num = l:num + 1
endw
exe l:cmd
endf
fu! s:ResizeAllWindows()
if v:version >= 700
let l:tabnum = tabpagenr()
tabdo call s:ResizeWindows()
exe "norm " . l:tabnum . "gt"
else
call s:ResizeWindows()
endif
let s:prevlines = &lines | let s:prevcolumns = &columns
endf
au GUIEnter * let s:prevlines = &lines | let s:prevcolumns = &columns
au VimResized * call s:ResizeAllWindows()
endif
aug END
endif
" }}} ------------------------------------------------------
" VIM7 SPECIFIC {{{ ----------------------------------------
if v:version >= 700
" editor setting
set nuw=6
" omni completition
set ofu=syntaxcomplete#Complete
imap <C-Space> <C-X><C-N>
" key mapping for tabpage
call s:Map2('<C-Tab>', '<D-Down>', 'gt', 0)
call s:Map2('<C-S-Tab>', '<D-Up>', 'gT', 0)
let i = 1
while i <= 10
call s:Map2('<M-' . (i % 10) . '>', '<D-' . (i % 10) . '>', i . 'gt', 0)
let i = i + 1
endw
call s:Map2('<M-n>', '<D-n>', ':tabnew<CR>', 0)
call s:Map2('<M-w>', '<D-w>', ':tabclose<CR>', 0)
" session management
fu! s:SaveSession()
let l:path = $HOME
if isdirectory(l:path . '/Desktop')
let l:path .= '/Desktop'
endif
let l:path = input('Where to save the session? ', l:path, 'dir')
if l:path != ''
let l:path .= '/session'
if glob(l:path) != ''
let l:suffix = 0
while glob(l:path . '.' . l:suffix) != ''
let l:suffix += 1
endwhile
let l:path .= '.' . l:suffix
endif
exe 'mks ' . l:path
echo 'Saved the session: ' . l:path
endif
endf
fu! s:RestoreSession()
let l:path = $HOME
if isdirectory(l:path . '/Desktop')
let l:path .= '/Desktop'
endif
let l:path .= '/session'
let l:path = input('What session to be recovered? ', l:path, 'file')
if l:path != ''
exe 'so ' . l:path
echo 'Recovered the session: ' . l:path
endif
endf
nmap <silent> <Leader>ss :call <SID>SaveSession()<CR>
nmap <silent> <Leader>sr :call <SID>RestoreSession()<CR>
" automatic session recovery
fu! s:SearchSession()
let l:tmpdirs = strpart(&dir, 0, stridx(&dir, ','))
for i in split(globpath(l:tmpdirs, '**/*.sw?'), '\n')
" vim swap file format is defined in src/memline.c. highlight is
" that file name starts at offset 108, and at least up to 850
" bytes are available for it. (some add. info is at end of it)
let l:path = substitute(strpart(join(readfile(i, 'b', 512), "\n"),
\ 108, 512), '\n*$', '', '')
exe 'tabnew' l:path
endfo
endf
" TODO
"call s:SearchSession()
endif
" }}} ------------------------------------------------------
" CUSTOMIZING by hodduc {{{ --------------------------------
set t_Co=256
try
colorscheme molokai
" colorscheme summerfruit256
catch /^Vim\%((\a\+)\)\=:E185/
echo 'colorscheme molokai not exist'
endtry
let g:pymode_folding = 0
let g:pymode_rope = 0
let g:pymode_lint = 1
let g:pymode_lint_checkers = ['pyflakes', 'pep8']
let g:pymode_lint_ignore = "E501,E261"
let g:pymode_options_max_line_length = 99
let g:pymode_lint_unmodified = 1
" turn off YouCompleteMe identifier based completion
let g:ycm_min_num_of_chars_for_completion = 99
let g:ycm_key_invoke_completion = '<C-l>'
set wildmenu
set wildmode=list:longest,full
nmap <silent> <C-j> :MBEbp<CR>
nmap <silent> <C-k> :MBEbn<CR>
" CUSTOMIZING end }}} -------------------------------------
" end of configuration
finish
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TODOS:
" - integrated ctags support
" - more filetype-specific configuration
" - more smooth ResizeAllWindows behavior in mac os x
" (as MacVim generates VimResized event on *every* ticks)
" - bring SearchSession routine to the light
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" vim: ts=4 sw=4 fdm=marker nofen