-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
516 lines (422 loc) · 13.4 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
""" GUI related settings
set guifont=WenQuanYi\ Micro\ Hei\ Mono\ 16
set winaltkeys=no
set mouse=
""" The pathogen plugin
let g:pathogen_disabled = []
call add(g:pathogen_disabled, 'some_plugin')
call pathogen#infect('plugins/{}')
call pathogen#helptags()
""" Common options
set hls ic scs is
set sts=4 sw=4 ts=4 et
let mapleader = "\\"
autocmd FileType tex,javascript,html set sts=2 sw=2
autocmd FileType rst set textwidth=79 sts=3 sw=3
autocmd FileType yaml setl indentexpr= autoindent
syntax on
filetype plugin indent on
autocmd BufEnter * syntax sync fromstart
autocmd BufRead,BufNewFile *.tpl set filetype=jinja
set fileencodings^=utf8,gb18030
"set path^=~/work/**
set tags=./tags;,~/.tags.python
set completeopt-=preview
set completeopt+=longest
set grepprg=ack\ -k\ --smart-case
"set grepprg=ack
" The xargs part is used to filter out non-exist files. Ack has a -s option
" for this, but currently does not work due to some bug.
" let &grepprg = 'git ls-files -co --exclude-standard -z \| xargs -0 ls -d 2>/dev/null \| ack -x --smart-case'
set formatoptions-=t
set formatoptions+=ormMn
set backspace=indent,eol,start
set timeoutlen=300
""" Key mappings
nnoremap <F9> :set paste! paste?<CR>
imap <F9> <C-o><F9>
set pastetoggle=<F9>
nnoremap <C-]> g<C-]>
nnoremap g<C-]> <C-]>
vnoremap <C-]> g<C-]>
vnoremap g<C-]> <C-]>
nnoremap j gj
nnoremap gj j
nnoremap k gk
nnoremap gk k
nnoremap Y y$
nnoremap <F5> <C-l>
nnoremap <C-h> 25zh
nnoremap <C-l> 25zl
nnoremap <C-x>js :set filetype=javascript filetype?<CR>
nnoremap <C-x>cpp :set filetype=cpp filetype?<CR>
nnoremap <C-x>c :set filetype=c filetype?<CR>
nnoremap <C-x>jinja :set filetype=jinja filetype?<CR>
"nnoremap <C-x>wrap :set textwidth=79 formatoptions+=ta formatoptions-=c<CR>
nnoremap <C-n> :NERDTreeToggle<CR>
nnoremap <C-n>n :NERDTreeFind<CR>
nnoremap <C-n>t :tabe %<CR>:NERDTreeFind<CR>
nnoremap <C-n>p :tabe %<CR>:CtrlP<CR>
nmap <C-n>k _<C-k><C-w>l
nnoremap <C-n>v :tabe<CR>:e $MYVIMRC<CR>
nnoremap <C-n>vv :source $MYVIMRC<CR>
nnoremap <C-n>ss :Obsession ~/.vim/sessions/default<CR>
nnoremap <C-n>s :call Prompt_Save_Session()<CR>
nnoremap <C-n>ll :source ~/.vim/sessions/default<CR>
nnoremap <C-n>l :call Prompt_Load_Session()<CR>
nnoremap <C-k> :TagbarToggle<CR>
" not necessary, but shows how to use v:count and condition in mapping...
nnoremap <expr> = (v:count == 0 ? v:count : '') . 'gt'
" the same as above, but much simpler:
"nnoremap = gt
nnoremap K gt
nnoremap + gT
nnoremap J gT
"nnoremap _ :tabe<CR>
nnoremap _ <C-w>v<C-w>T
nnoremap Y y$
nnoremap -j :let g:NERDTreeQuitOnOpen = 1 - g:NERDTreeQuitOnOpen<CR>:let g:NERDTreeQuitOnOpen<CR>
nnoremap -p :set paste! paste?<CR>
nnoremap -n :setl nu! nu?<CR>
nnoremap -l :setl list! list?<CR>
nnoremap -s :call Toggle_Statusline()<CR>
nnoremap -i :call Toggle_Formatoption()<CR>
nnoremap -u :call Toggle_Colorcolumn()<CR>
"imap <C-a> <Nop>
imap <C-a> <Esc>-ia
nmap <C-a> -i
" not so important ones:
"inoremap <F3> <C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR>
""" Helper functions
function! Prompt_Save_Session()
call inputsave()
let session_name = input("Save session: ")
call inputrestore()
redraw
let file = '~/.vim/sessions/' . session_name
execute 'Obsession' file
endfunction
function! Prompt_Load_Session()
call inputsave()
let session_name = input("Load session: ")
call inputrestore()
redraw
let file = "~/.vim/sessions/" . session_name
if !filereadable(expand(file))
echo "Session file " . file . " does not exist."
else
execute 'source' file
endif
endfunction
function! Toggle_Colorcolumn()
if &colorcolumn
setlocal colorcolumn=
else
setlocal colorcolumn=80
endif
endfunction
function! Toggle_Formatoption()
if !exists('g:_format_option_toggled')
let g:_format_option_toggled = 0
else
let g:_format_option_toggled = 1 - g:_format_option_toggled
endif
if g:_format_option_toggled
set formatoptions-=tav
echo "auto-format off"
else
set formatoptions+=tav
echo "auto-format on"
endif
endfunction
function! Toggle_Statusline()
if !exists('g:show_status_line')
let g:show_status_line = 1
else
let g:show_status_line = 1 - g:show_status_line
endif
if g:show_status_line
set laststatus=2
set statusline=%F
set statusline+=%y
set statusline+=%r
set statusline+=%=
set statusline+=%7.c,
set statusline+=%l/%L
set statusline+=\ \ \ \ %P
else
set laststatus=1
set statusline=
endif
endfunction
call Toggle_Statusline()
""" Tabline
set tabline=%!Tab_Line()
function! Tab_Line()
let s = '' " complete tabline goes here
let columns = &columns
let total_length = 0
let cur_tab = tabpagenr()
let cur_tab_begin = 0
let cur_tab_end = 0
let tabs = []
for t in range(tabpagenr('$'))
" set tab number for mouse click (copied from the doc)
let tab = {}
let prefix = ''
let body = ''
let prefix .= '%' . (t+1) . 'T'
if (t+1) == cur_tab
let prefix .= '%#TabLineSel#'
let cur_tab_begin = total_length
else
let prefix .= '%#TabLine#'
endif
let s .= prefix
let tab.prefix = prefix
let tab.begin = total_length
let body .= ' ' . (t+1)
" get buffer infos
let bf_names = ''
let n_modified = 0
let bf_list = tabpagebuflist(t+1)
let bf_num = len(bf_list)
let i = 0
for b in bf_list
if getbufvar(b, "&modified")
let n_modified += 1
endif
let name_to_add = ''
let btype = getbufvar(b, "&buftype")
let bname = bufname(b)
"echom 'num:' b 'name:' bufname(b) 'buftype:' btype
if btype == 'help'
let name_to_add .= ':h-' . fnamemodify(bname, ':t:s/.txt$//')
elseif btype == 'quickfix'
continue
elseif bname == ''
let name_to_add .= '[New]'
elseif bname =~# 'NERD_tree'
let name_to_add .= '[N]'
elseif bname =~# '__Tagbar__'
let name_to_add .= '[K]'
elseif bname =~# 'ControlP'
let name_to_add .= '[P]'
elseif bname =~# '__init__\.py$'
let tmp = fnamemodify(bname, ':h:t')
if len(tmp) > 5
let tmp = substitute(tmp, '^\([^_ .]\{,5}\).*$', '\1', '')
endif
let tmp .= '/[init]'
let name_to_add .= tmp
else
let known_exts = ['py', 'js', 'jsx']
let ext = fnamemodify(bname, ':e')
if index(known_exts, ext) >= 0
let show_ext = 0
let tmp = fnamemodify(bname, ':t:r')
else
let show_ext = 1
let tmp = fnamemodify(bname, ':t')
endif
if len(tmp) > 10
let oldtmp = tmp
let tmp = substitute(oldtmp, '^\([^_ .]\{,5}\).*$', '\1', '')
if len(tmp) <= 3
let tmp = substitute(oldtmp, '^\([^ .]\{,7}\).*$', '\1', '')
elseif len(tmp) == 4
let tmp = substitute(oldtmp, '^\([^ .]\{,8}\).*$', '\1', '')
endif
if show_ext
let tmp .= '.' . ext
endif
endif
let name_to_add .= tmp
endif
let i += 1
let bf_names .= ' ' . name_to_add
endfor
"echom bf_names
if n_modified > 0
let body .= '+'
let total_length += len(bf_names) + 4
else
let total_length += len(bf_names) + 3
endif
if (t+1) == cur_tab
let cur_tab_end = total_length
endif
"echom total_length cur_tab_begin cur_tab_end
let body .= bf_names
let body .= ' '
let s .= body
let tab.body = body
let tab.end = total_length
call add(tabs, tab)
endfor
"echom string(tabs)
if total_length > columns
let cur_tab_length = cur_tab_end - cur_tab_begin
let tmp = (columns - cur_tab_length) * 1.0 / 2
let show_range_begin = float2nr(ceil(cur_tab_begin - tmp))
let show_range_end = float2nr(ceil(cur_tab_end + tmp))
"echom total_length string(show_range_begin) string(show_range_end)
if show_range_begin < 0
let delta = 0 - show_range_begin
let show_range_begin = 0
let show_range_end = show_range_end + delta
elseif show_range_end > total_length
let delta = show_range_end - total_length
let show_range_end = total_length
let show_range_begin = show_range_begin - delta
endif
"echom total_length string(show_range_begin) string(show_range_end)
" reassemble the tabs
let s = ''
for tab in tabs
"echom string(tab)
if tab.end <= show_range_begin || tab.begin >= show_range_end
"echom 1
continue
elseif (tab.begin+1) < show_range_begin && tab.end > show_range_begin
let delta = tab.end - show_range_begin
let new_body = tab.body[(delta+2):]
let tab.body = new_body
"tab.body[0] = '<'
"echom 2 delta new_body
elseif tab.begin < show_range_end && tab.end > show_range_end
let delta = show_range_end - tab.begin
let new_body = tab.body[:(delta-1)]
let tab.body = new_body
"echom 3 delta new_body
endif
"echom string(tab)
let s .= tab.prefix
let s .= tab.body
endfor
endif
let s .= '%#TabLineFill#%T'
" right-align the label to close the current tab page
"if tabpagenr('$') > 1
" let s .= '%=%#TabLine#%999Xclose'
"endif
return s
endfunction
""" Plugins
"" netrw
let g:netrw_liststyle = 3
let g:netrw_winsize = 25
let g:netrw_browse_split = 4
let g:netrw_banner = 0
"" neocomplete
let g:neocomplete#enable_at_startup = 1
let g:neocomplete#enable_smart_case = 1
let g:neocomplete#enable_auto_select = 1
let g:neocomplete#auto_completion_start_length = 2
if !exists('g:neocomplete#sources#omni#input_patterns')
let g:neocomplete#sources#omni#input_patterns = {}
endif
if !exists('g:neocomplete#force_omni_input_patterns')
let g:neocomplete#force_omni_input_patterns = {}
endif
"let g:neocomplete#force_omni_input_patterns.javascript = '[^. \t]\.\w*'
inoremap <expr> <C-g> neocomplete#undo_completion()
inoremap <expr> <C-l> neocomplete#complete_common_string()
"inoremap <expr> <S-Tab> pumvisible() ? neocomplete#close_popup() : "\<S-Tab>"
inoremap <expr> <CR> pumvisible() ? neocomplete#cancel_popup()."\<CR>" : "\<CR>"
"" ultisnips
let g:UltiSnipsEditSplit = 'vertical'
let g:UltiSnipsSnippetsDir = '~/.vim/ultisnips'
let g:UltiSnipsSnippetDirectories = [$HOME.'/.vim/ultisnips']
let g:UltiSnipsExpandTrigger = "<C-Tab>"
let g:ulti_expand_res = 0
function! Ultisnips_Try_Expand()
call UltiSnips#ExpandSnippet()
return g:ulti_expand_res
endfunction
function! Neocomplete_Select_Candidate()
if pumvisible()
return neocomplete#close_popup()
else
return "\<Tab>"
endif
endfunction
inoremap <silent> <Tab> <C-r>=(Ultisnips_Try_Expand() > 0) ? "" : Neocomplete_Select_Candidate()<CR>
" Interestingly, the following will not work:
" inoremap <expr> <Tab> (Ultisnips_Try_Expand() > 0) ? "" :
" Neocomplete_Select_Candidate()
"" ctrlp
let g:ctrlp_working_path_mode = 'a'
" List files using git. If vcs other than git is used, it has to be added
" here.
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
"" nerdtree
let g:NERDTreeQuitOnOpen = 1
"" tagbar
let g:tagbar_sort = 0
"" vim-jsx
let g:jsx_ext_required = 0
"" jedi
" don't forget to run `git submodule update --init` inside jedi's directory
let g:jedi#auto_vim_configuration = 0
let g:jedi#completions_enabled = 0
autocmd FileType python setlocal omnifunc=jedi#completions
autocmd FileType python setlocal indentkeys-=<:>
let g:neocomplete#sources#omni#input_patterns.python =
\ '\h\w*\|[^. \t]\.\w*'
" 'force' mode
let g:neocomplete#force_omni_input_patterns.python =
\ '\%(^\s*@\|^\s*from .\+import \|^\s*from .\+import .*, \|^\s*from \|^\s*import \)\w*'
let g:jedi#goto_command = "<leader>]"
let g:jedi#goto_assignments_command = "<leader>["
let g:jedi#usages_command = "<leader>p"
let g:jedi#documentation_command = "<leader>d"
let g:jedi#rename_command = "<leader>r"
"" syntastic
"""
" recommended settings
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
"let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
"""
let g:syntastic_python_checkers = []
let g:syntastic_c_checkers = []
let g:syntastic_cpp_checkers = []
"let g:syntastic_c_checkers = ['clang_check']
"let g:syntastic_clang_check_config_file = '.vim-clang'
"" vim-racer
let g:racer_cmd = "racer"
" when using vim-python3, the following is not needed
"py << EOF
"import sys
"import os
"sys.path[:0] = [
" os.path.expanduser('~/.local/lib/python3.4/site-packages'),
" '/usr/lib/python3.4/site-packages'
"]
"EOF
"" vim-clang
" don't forget to install clang
let g:clang_auto = 0
let g:clang_c_completeopt = 'menuone,longest'
let g:clang_cpp_completeopt = 'menuone,longest'
let g:clang_dotfile = '.vim-clang'
let g:clang_check_syntax_auto = 1
let g:clang_c_options = '-std=gnu99 -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-private-field'
let g:clang_cpp_options = '-std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-private-field'
let g:neocomplete#force_omni_input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)\w*'
"let g:neocomplete#force_omni_input_patterns.cpp = '[^.[:digit:]
"*\t]\%(\.\|->\)\w*\|\h\w*::\w*'
let g:neocomplete#sources#omni#input_patterns.cpp = '\w*::\w*'
let g:neocomplete#force_omni_input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\w\+'
"" powerline
"let g:powerline_pycmd = 'py3'
"" python-mode
let g:pymode_python = 'python3'
"" gutentags
let g:gutentags_dont_load = 1
" vim: set sts=2 sw=2 et: