forked from shiyanhui/simrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
538 lines (451 loc) · 13.6 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
"-------------------------------------------------------------
" Options
"-------------------------------------------------------------
" 1 important
set nocompatible
set nopaste
" 2 moving around, searching and patterns
set startofline
set incsearch
set magic
set ignorecase
set smartcase
set whichwrap+=<,>,h,l
" 3 tags
" 4 displaying text
set scrolloff=8
set sidescrolloff=10
set fillchars=
set number
set nowrap
set showmatch
set matchtime=2
" 5 syntax, highlighting and spelling
syntax on
set background=dark
set hlsearch
set cursorline
if has("termguicolors")
set termguicolors
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
" 6 multiple windows
set laststatus=2
set hidden
" 7 multiple tab pages
" 8 terminal
if !has('nvim')
set term=xterm-256color
endif
set ttyfast
" 9 using the mouse
set mouse-=a
" 10 printing
" 11 messages and info
set shortmess=atIq
set showcmd
set showmode
set ruler
set report=0
" 12 selecting text
set clipboard=unnamed
" 13 editing text
set undolevels=1024
set noundofile
set backspace=indent,eol,start
set matchpairs=(:),{:},[:]
" 14 tabs and indenting
set tabstop=4
set shiftwidth=4
set smarttab
set softtabstop=4
set shiftround
set expandtab
set autoindent
set smartindent
" 15 folding
" 16 diff mode
" 17 mapping
" 18 reading and writing files
set write
set writebackup
set nobackup
set noautowrite
set nowriteany
set autoread
set fsync
" 19 the swap file
set noswapfile
" 20 command line editing
set history=1024
set wildignore=*.o,*.obj,*.swp,*.pyc,*.bak,*.tmp
set wildmenu
" 21 executing external commands
" 22 running make and jumping to errors
" 23 language specific
" 24 multi-byte characters
set encoding=utf-8
set ambiwidth=single
" 25 various
set loadplugins
if !has('nvim')
set viminfo='64,\"128,:64,%,n~/.viminfo
endif
" terms options
set t_vb=
set t_ti=
set t_te=
set ffs=unix,dos,mac
set visualbell
set scrolljump=5
" gui options
set guifont=Hasklig:h14
set guioptions=
set guicursor+=a:blinkon0
"-------------------------------------------------------------
" KeyMaps
"-------------------------------------------------------------
let mapleader = ','
filetype plugin indent on
" Key Maps
nnoremap x "_x
nnoremap X "_X
nnoremap d "_d
nnoremap dd "_dd
nnoremap D "_D
nnoremap <Leader>w <Esc>:w<CR>
nnoremap <Leader>q <Esc>:q<CR>
inoremap <C-a> <Esc><S-i>
nnoremap <C-a> <Esc><S-i>
cnoremap <C-a> <Home>
inoremap <C-e> <Esc><S-a>
nnoremap <C-e> <Esc><S-a>
cnoremap <C-e> <End>
inoremap <C-f> <Right>
inoremap <C-b> <Left>
cnoremap <C-f> <Right>
cnoremap <C-b> <Left>
inoremap <C-o> <Esc>o
inoremap <C-j> <Esc>O
vnoremap > >gv
vnoremap < <gv
xnoremap p pgvy
" 快速命令行模式
nnoremap ; :!
noremap H ^
noremap L $
nnoremap U <C-r>
" 去掉搜索高亮
nnoremap <Leader>/ :nohls<CR>
" 关闭方向键, 强迫自己用 hjkl
map <Left> <Nop>
map <Right> <Nop>
map <Up> <Nop>
map <Down> <Nop>
" kj 替换 Esc
inoremap kj <Esc>
" 切换前后buffer
nnoremap [b :bprevious<cr>
nnoremap ]b :bnext<cr>
" 使用方向键切换buffer
noremap <left> :bp<CR>
noremap <right> :bn<CR>
" 分屏窗口移动, Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" F1 - F6 设置
" F1 废弃这个键,防止调出系统帮助
" I can type :help on my own, thanks. Protect your fat fingers from the evils of <F1>
noremap <F1> <Esc>"
" F2 行号开关,用于鼠标复制代码用
" 为方便复制,用<F2>开启/关闭行号显示:
function! HideNumber()
if(&relativenumber == &number)
set relativenumber! number!
elseif(&number)
set number!
else
set relativenumber!
endif
set number?
endfunc
nnoremap <F2> :call HideNumber()<CR>
" F3 显示可打印字符开关
nnoremap <F3> :set list! list?<CR>
" F4 换行开关
nnoremap <F4> :set wrap! wrap?<CR>
" F6 语法开关,关闭语法可以加快大文件的展示
nnoremap <F6> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR>
" when in insert mode, press <F5> to go to
" paste mode, where you can paste mass data
" that won't be autoindented
set pastetoggle=<F7>
" disbale paste mode when leaving insert mode
au InsertLeave * set nopaste
"Treat long lines as break lines (useful when moving around in them)
"se swap之后,同物理行上线直接跳
nnoremap k gk
nnoremap gk k
nnoremap j gj
nnoremap gj j
function! BufferCount() abort
return len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
endfunction
function! LocationListWindonwToggle() abort
let buffer_count_before = BufferCount()
silent! lclose
silent! lclose
if BufferCount() == buffer_count_before
execute "silent! lopen"
endif
endfunction
nnoremap <Leader>tl :call LocationListWindonwToggle()<CR>
nnoremap <Leader>jj :lnext<CR>
nnoremap <Leader>kk :lpre<CR>
nnoremap <Leader>s :call ToggleErrors()<cr>
"-------------------------------------------------------------
" Events
"-------------------------------------------------------------
augroup highlight_overlength
autocmd!
autocmd BufEnter * highlight OverLength ctermbg=15
autocmd BufEnter,BufWrite,TextChanged,TextChangedI,InsertEnter,InsertLeave * match OverLength /\%<81v.\%>80v/
augroup END
function! RestoreCursor()
if line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction
augroup restore_cursor
autocmd!
autocmd BufWinEnter * call RestoreCursor()
augroup END
augroup set_tab_2
autocmd!
autocmd FileType markdown,yaml,toml,javascript,typescript,html,css,xml set tabstop=2 shiftwidth=2 softtabstop=2
augroup END
"-------------------------------------------------------------
" Plugins
"-------------------------------------------------------------
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/bundle')
" Efficiency
Plug 'dense-analysis/ale'
Plug 'Valloric/YouCompleteMe', {'dir': '~/.vim/bundle/YouCompleteMe', 'do': './install.py --clang-completer --go-completer --rust-completer'}
Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim'
Plug 'scrooloose/nerdcommenter'
Plug 'tpope/vim-repeat' | Plug 'tpope/vim-surround'
Plug 'easymotion/vim-easymotion'
Plug 'Raimondi/delimitMate'
Plug 'bronson/vim-trailing-whitespace'
Plug 'majutsushi/tagbar'
Plug 'ctrlpvim/ctrlp.vim' | Plug 'tacahiroy/ctrlp-funky'
" Display
Plug 'lifepillar/vim-solarized8'
Plug 'tpope/vim-fugitive' | Plug 'vim-airline/vim-airline' | Plug 'vim-airline/vim-airline-themes'
Plug 'scrooloose/nerdtree' | Plug 'jistr/vim-nerdtree-tabs' | Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'kien/rainbow_parentheses.vim'
" Languages
Plug 'google/yapf', {'rtp': 'plugins/vim', 'for': 'python'}
Plug 'Chiel92/vim-autoformat'
call plug#end()
function! AleConfig()
let g:ale_linters = {
\ 'go': ['gopls', 'gobuild'],
\ 'c': ['gcc'],
\ 'cpp': ['g++'],
\}
let g:ale_sign_error = '>>'
let g:ale_sign_warning = '>'
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_enter = 0
let g:ale_c_clang_options = "std=c11 -Wno-everything"
let g:ale_cpp_clang_options = "-std=c++14 -Wno-everything"
let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
nnoremap <Leader>ta :ALEToggle<CR>
endfunction
function! YouCompleteMeConfig()
let g:ycm_complete_in_comments = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_add_preview_to_completeopt = 0
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_show_diagnostics_ui = 0
let g:ycm_max_num_candidates = 30
let g:ycm_confirm_extra_conf = 0
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
let g:ycm_semantic_triggers = {
\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
\ 'cs,lua,javascript': ['re!\w{2}'],
\ }
let g:ycm_filetype_whitelist = {
\ "c":1,
\ "cpp":1,
\ "cc":1,
\ "go":1,
\ "sh":1,
\ "zsh":1,
\ "rs":1,
\ }
nnoremap gd :YcmCompleter GoToDefinition<CR>
nnoremap <Leader>jd :YcmCompleter GoToDeclaration<CR>
nnoremap <Leader>id :YcmCompleter GoToInclude<CR>
endfunction
function! FzfConfig()
nnoremap <Leader>f :Files<CR>
nnoremap <Leader>b :Buffers<CR>
nnoremap <Leader>ag :Ag<CR>
let g:fzf_history_dir = '~/.local/share/fzf-history'
let g:fzf_layout = { 'down': '~40%' }
let g:fzf_buffers_jump = 1
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
let g:fzf_tags_command = 'ctags -R'
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
command! -bang -nargs=* Ag
\ call fzf#vim#ag(
\ <q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%') : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%') : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
endfunction
function! NERDCommenterConfig()
let g:NERDTreeShowHidden=1
let g:NERDSpaceDelims = 1
let g:NERDTrimTrailingWhitespace = 1
let g:NERDToggleCheckAllLines = 1
let g:NERDCommentEmptyLines = 1
endfunction
function! EasyMotionConfig()
let g:EasyMotion_smartcase = 1
map <Leader>h <Plug>(easymotion-linebackward)
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
map <Leader>l <Plug>(easymotion-lineforward)
endfunction
function! DelimitMateConfig()
let g:delimitMate_expand_cr = 1
let g:delimitMate_expand_space = 1
endfunction
function! TrailingWhiteSpaceConfig()
nnoremap <Leader><Space> :FixWhitespace<CR>
endfunction
function! TagbarConfig()
nnoremap <Leader>t :TagbarToggle<CR>
endfunction
function! CtrlpConfig()
let g:ctrlp_map = '<leader>p'
let g:ctrlp_cmd = 'CtrlP'
map <leader>f :CtrlPMRU<CR>
map <leader><space> :CtrlPBuffer<CR>
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|rvm)$',
\ 'file': '\v\.(exe|so|dll|zip|tar|tar.gz|pyc)$',
\ }
let g:ctrlp_working_path_mode=0
let g:ctrlp_match_window_bottom=1
let g:ctrlp_max_height=15
let g:ctrlp_match_window_reversed=0
let g:ctrlp_mruf_max=500
let g:ctrlp_follow_symlinks=1
" 如果安装了ag, 使用ag
if executable('ag')
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
" ctrlpfunky
" ctrlp插件1 - 不用ctag进行函数快速跳转
nnoremap <Leader>fu :CtrlPFunky<Cr>
" narrow the list down with a word under cursor
nnoremap <Leader>fU :execute 'CtrlPFunky ' . expand('<cword>')<Cr>
let g:ctrlp_funky_syntax_highlight = 1
let g:ctrlp_extensions = ['funky']
endfunction
function! SolarizedConfig()
silent! colorscheme solarized8
let g:solarized_visibility = 'normal'
let g:solarized_diffmode = 'normal'
highlight LineNr ctermbg=NONE guibg=NONE
highlight SignColumn ctermbg=NONE guibg=NONE
endfunction
function! AirlineConfig()
let g:airline_powerline_fonts = 1
let g:airline_solarized_bg = 'dark'
let g:airline_theme = 'solarized'
let g:airline_skip_empty_sections = 1
endfunction
function! NERDTreeConfig()
nnoremap <Leader>n :NERDTreeToggle<CR>
let g:NERDTreeIgnore = ['.pyc$']
let g:NERDTreeCascadeSingleChildDir = 0
let g:NERDTreeSortHiddenFirst = 1
let g:NERDTreeAutoDeleteBuffer = 1
endfunction
function! RainbowParenthesesConfig()
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
let g:rbpt_colorpairs = [
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['brown', 'firebrick3'],
\ ['gray', 'RoyalBlue3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['Darkblue', 'firebrick3'],
\ ['darkgreen', 'RoyalBlue3'],
\ ['darkcyan', 'SeaGreen3'],
\ ['darkred', 'DarkOrchid3'],
\ ['red', 'firebrick3'],
\ ]
augroup rainbow_parentheses
autocmd!
autocmd VimEnter * silent! RainbowParenthesesToggle
autocmd Syntax * silent! RainbowParenthesesLoadRound
autocmd Syntax * silent! RainbowParenthesesLoadSquare
autocmd Syntax * silent! RainbowParenthesesLoadBraces
augroup END
endfunction
function! AutoFormat()
let g:formatdef_custom_c='"clang-format -style=google"'
let g:formatters_c = ['custom_c']
let g:formatter_yapf_style = 'pep8'
noremap <F5> :Autoformat<CR>
endfunction
call AleConfig()
call YouCompleteMeConfig()
call FzfConfig()
call NERDCommenterConfig()
call EasyMotionConfig()
call DelimitMateConfig()
call TrailingWhiteSpaceConfig()
call TagbarConfig()
call CtrlpConfig()
call SolarizedConfig()
call AirlineConfig()
call NERDTreeConfig()
call RainbowParenthesesConfig()
call AutoFormat()