-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
480 lines (447 loc) · 14.4 KB
/
vimrc
File metadata and controls
480 lines (447 loc) · 14.4 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
:if version >100
let maplocalleader = " "
set nocompatible
let g:vundle_default_github_url="github.com"
"Vundle{{{
"Set up Vundle:
"git clone https://github.com/ims0/Vundle.vim.git ~/.vim/bundle/Vundle.vim
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'ims0/Vundle.vim'
Plugin 'Yggdroot/LeaderF'
"Plugin 'grailbio/bazel-compilation-database'
"Plugin 'vim-scripts/cscope.vim'
Plugin 'fholgado/minibufexpl.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-rhubarb'
Plugin 'mbbill/code_complete'
Plugin 'godlygeek/tabular'
Plugin 'inkarkat/vim-ingo-library'
Plugin 'ims0/vim-mark'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
"{lua
Plugin 'xolox/vim-misc'
Plugin 'xolox/vim-lua-ftplugin'
"Plugin 'vim-scripts/luainspect.vim'
"}
"{markdown
"Plugin 'plasticboy/vim-markdown'
"Plugin 'suan/vim-instant-markdown'
"}
Plugin 'Valloric/YouCompleteMe'
"Plugin 'mattn/emmet-vim'
call vundle#end() " required
filetype plugin indent on " required
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
nnoremap <localleader>in :PluginInstall <cr>
nnoremap <localleader>li :PluginList <cr>
"}}}
""let &t_ti.="\e[1 q"
""let &t_SI.="\e[5 q"
""let &t_EI.="\e[1 q"
""let &t_te.="\e[0 q"
"sysdiff"{
""let sys_type = system("uname")
""if sys_type =~? "Darwin*"
""endif
if has("clipboard")
if has("macunix")
nnoremap yy "*yy
nnoremap yw "*yw
vnoremap y "*y
vnoremap p "*p
nnoremap yf :let @*=expand("%:t")<CR>
nnoremap yp :let @*=expand("%:p")<CR>
elseif has('unix')
nnoremap yy "+yy
nnoremap yw "+yw
vnoremap y "+y
vnoremap p "+p
nnoremap yf :let @+=expand("%:t")<CR>
nnoremap yp :let @+=expand("%:p")<CR>
endif
else
vnoremap y "1y
vnoremap p "1p
nnoremap yf :let @"=expand("%:t")<CR>
nnoremap yp :let @"=expand("%:p")<CR>
endif
"}"
"my shortcut key{{{
inoremap jk <esc>
nnoremap <c-s> :update<cr>:%s/\t/ /g<cr>
inoremap <c-s> <esc>:update<cr>:%s/\t/ /g<cr>
vnoremap <c-s> <esc>:update<cr>:%s/\t/ /g<cr>
nnoremap <localleader>q :q<cr>
nnoremap <localleader>qq :q!<cr>
nnoremap <localleader>wq :wq<cr>
nnoremap <localleader>wa :wa<cr>
nnoremap <localleader>qa :qa<cr>
nnoremap <localleader>s :%s/
nnoremap <localleader>sw :%s/<c-r><c-w>/
nnoremap <localleader><Space> :%s/ *$//g<cr>
nnoremap <localleader>sh :bot term ++rows=8 bash<cr>
nnoremap <localleader>b :<C-u>call gitblame#echo()<CR>
nnoremap <localleader>y byw
nnoremap <localleader>/ :/\<\>
nnoremap <localleader>? :?\<\>
nnoremap <localleader>ev :vsplit$MYVIMRC<cr>
nnoremap <localleader>sv :source$MYVIMRC<cr>
nnoremap <localleader>" viw<esc>a"<esc>hbi"<esc>lel
nnoremap <localleader>' viw<esc>a'<esc>hbi'<esc>lel
nnoremap <localleader>e :!echo <c-r>"
nnoremap <localleader>* bi*<esc>ea*<esc>
nnoremap <localleader>ma :set mouse=a<cr>
nnoremap <localleader>mv :set mouse=v<cr>
cnoremap <c-a> <home>
cnoremap <c-e> <end>
"{{{ map ctags,NerdTree:F10,F12
nnoremap <F10> :TrinityToggleTagList<CR>
nnoremap <localleader>9 :TrinityToggleTagList<CR>
nnoremap <F12> :TrinityToggleNERDTree<CR>
nnoremap <localleader>0 :TrinityToggleNERDTree<CR>
"}}}
autocmd FileType cpp nnoremap <buffer> <localleader>/ I//<esc>
autocmd FileType c nnoremap <buffer> <localleader>/ I//<esc>
autocmd FileType sh nnoremap <buffer> <localleader>/ I#<esc>
autocmd bufwritepost $HOME/.vim/vimrc source %
"}}}
"设置切换Buffer快捷键"
nnoremap <C-left> :bp<CR>
nnoremap <C-right> :bn<CR>
"选择当前行,不包含前置空格"
nnoremap vv ^vg_
function! Leader_r()
if &filetype == 'sh'
:set noautochdir<cr>
:!bash %
elseif &filetype == 'vim'
:%y"
:@"
elseif &filetype == 'lua'
:!lua %
elseif &filetype == 'python'
:!python %
else
return
endif
endfunction
nnoremap <localleader>r :call Leader_r()<cr>
"LeaderF cfg"{
nnoremap <localleader>f :LeaderfFile<cr>
nnoremap <localleader>g :Leaderf rg
nnoremap <localleader>gg :Leaderf rg <c-r><c-w><cr>
nnoremap <localleader>bu :LeaderfBuffer<cr>
let g:Lf_WildIgnore = {
\ 'dir': ['.svn','.git','CMakeFiles','tools'],
\ 'file': ['*.sw?','~$*','*.ba*','*.exe','*.o','*.a','*.so','*.py[co]']
\}
"}
"Ycm Config{
" install
" git clone https://github.com/ycm-core/YouCompleteMe.git ~/.vim/bundle/
" 初始化本地配置文件
" git submodule init
" 检出父仓库列出的commit
" git submodule update
let g:ycm_log_level = 'error'
let g:ycm_max_diagnostics_to_display = 10
nmap <localleader>yfw <Plug>(YCMFindSymbolInWorkspace)
let g:ycm_show_diagnostics_ui = 1 "switch of symtax diagnostic
"default close ycm hover
let g:ycm_auto_hover = ""
"manually trigger ycm hover
nmap <localleader>y <plug>(YCMHover)
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
let g:ycm_collect_identifiers_from_tag_files = 1
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_confirm_extra_conf=0
let g:ycm_complete_in_comments=0
let g:ycm_error_symbol='E'
let g:ycm_warning_symbol = 'W'
let g:ycm_semantic_triggers = { 'c' : ['->', '.']}
let g:ycm_key_list_select_completion = ['<TAB>','<Down>','<C-j>']
let g:ycm_key_list_previous_completion = ['<S-TAB>', '<Up>','<C-k>']
set completeopt=preview
"YcmCompleter cmd
"https://github.com/ycm-core/YouCompleteMe#goto-commands"
nnoremap gf :YcmCompleter GoToDefinitionElseDeclaration<cr>
nnoremap gr :YcmCompleter GoToReferences<cr>
nnoremap <localleader>dc :YcmCompleter GoToDeclaration<cr>
nnoremap <localleader>df :YcmCompleter GoToDefinition<cr>
nnoremap <localleader>go :YcmCompleter GoTo<cr>
nnoremap <localleader>gp :YcmCompleter GetParent<cr>
nnoremap <localleader>ix :YcmCompleter FixIt<cr>
nnoremap <localleader>= :YcmC Format<cr>
vnoremap <localleader>= ggvG=
"}
"NERDtree{
nnoremap <localleader>nf :NERDTreeFind<cr>
" 改变nerdtree的箭头
""let g:NERDTreeDirArrowExpandable = '▸'
""let g:NERDTreeDirArrowCollapsible = '▾'
" 设置宽度
let NERDTreeWinSize=30
" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1
" 忽略文件
let NERDTreeIgnore=['\.pyc','\~$','\.swp']
" 显示书签列表
let NERDTreeShowBookmarks=1
"}
"cscope setting{
if has("cscope")
set csprg=cscope
set cscopetag
set nocscopeverbose
if filereadable("cscope.out")
cs add cscope.out ./ -C
endif
set cscopeverbose
"The default value is "" (don't use quickfix anyway)
set cscopequickfix=""
nnoremap <c-@> :cs f
nnoremap <localleader>2c :cs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap <localleader>2s :cs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap <localleader>2t :cs find t <C-R>=expand("<cword>")<CR><CR>
nnoremap <localleader>2g :cs find g <C-R>=expand("<cword>")<CR><CR>
nnoremap <localleader>2f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nnoremap <localleader>2i :cs find i <C-R>=expand("<cfile>")<CR><CR>
endif
"}
"设置文件的代码形式
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese,cp936
let g:win_colorscheme_path=$VIMRUNTIME."/colors/Tomorrow-Night.vim"
let g:colorscheme_path=$HOME."/.vim/bundle/vim-mark/plugin/imscolo.vim"
if has("gui_running")
"vim的菜单乱码解决:
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"vim提示信息乱码的解决
language messages zh_CN.utf-8
set guioptions-=T
set guioptions-=m
set guioptions-=L
set guioptions-=r
set guioptions-=b
if filereadable(glob(win_colorscheme_path))
nnoremap <localleader>ms :exec "vsplit".win_colorscheme_path<cr>
set guifont=Consolas:h13:cANSI
colorscheme Tomorrow-Night
endif
else
if filereadable(glob(colorscheme_path))
nnoremap <localleader>ms :exec "vsplit".colorscheme_path<cr>
"colorscheme imscolo
endif
endif
if has("syntax")
syntax on
endif
"paste mode{
:map <F6> :set paste<CR>
:map <F7> :set nopaste<CR>
:imap <F6> <C-O>:set paste<CR>
:imap <F7> <nop>
:set pastetoggle=<F6>
"}
"fold{
set foldcolumn=0
setlocal foldlevel=0
"}
"diff setting{
set diffopt=vertical,context:4
nnoremap <localleader>df :bufdo diffthis<cr>
"}
set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
set mouse=a
set t_Co=256 "number of colors"
set noswapfile
set nobackup "no backup
set autoread
set autowrite " Automatically save before commands like :next and :make
set hidden " Hide buffers when they are abandoned
set number
set ruler "show cursor site in right below
set tabstop=4
set shiftwidth=4
set incsearch " The screen will be updated often,with typing pattern
set hlsearch " highlight all its matches.
set autoindent
set cindent
set completeopt=longest,menu
set wildmode=list:longest
set laststatus=2
"{
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
inoremap ( ()<ESC>i
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap { {}<ESC>i
inoremap } <c-r>=ClosePair('}')<CR>
inoremap [ []<ESC>i
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap " ""<ESC>i
inoremap ' ''<ESC>i
"}
"
"term gdb debug{
function! TermdebugAdd()
exe "packadd termdebug"
:Termdebug
endfunction
nnoremap <localleader>d :call TermdebugAdd()<cr>
"}
"{
nnoremap > V>
nnoremap <s-tab> V<
vnoremap > >gv
vnoremap <s-tab> <gv
"}
"minibufexplore settings{
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 2
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
let g:bufExplorerMaxHeight=3
""let g:miniBufExplUseSingleClick = 1
"}
"sdvc{
set keywordprg=sdcv\ -u\ 朗道英汉字典5.0
function! Mydict()
let retstr=system('sdcv '.expand("<cword>"))
windo if expand("%")=="dict-win" |q!|endif
30vsp dict-win
setlocal buftype=nofile bufhidden=hide noswapfile
1s/^/\=retstr/
1
endfunction
nnoremap F :call Mydict()<CR>
"use sdcv instead man
set keywordprg=sdcv
"}
"
"sys ls{
function! Sysls()
let retstr=system('ls')
bufdo if expand("%")=="_sys_ls" |bd _sys_ls|endif
30vsp _sys_ls
setlocal buftype=nofile bufhidden=hide noswapfile
1s/^/\=retstr/
1
endfunction
:nnoremap <localleader>ls :call Sysls()<cr>
"}
"create job{
func! BuildcsEcho(channel, msg)
echo a:msg
endfunc
func! RefreshCscope()
call job_start([ './buildcs.sh'], {'callback': 'BuildcsEcho'})
endfunc
nnoremap <F3> :call RefreshCscope()<cr>
"}
"show run result{
function! ExecProm()
bufdo if expand("%")=="runResult" |bd runResult|endif
exec "w"
let headtitle = system("echo -e '------------compile result--------------'")
let runResLine = system("echo -e '--------------run result----------------'")
if &filetype == 'c'
let compileResu = system('gcc '.expand('%').' -o '.expand('%<'))
let runResu=headtitle.compileResu.runResLine .system('./'.expand('%<'))
elseif &filetype == 'cpp'
let compileResu = system('g++ -std=c++11 '.expand('%').' -lpthread -o '.expand('%<'))
let runResu=headtitle.compileResu.runResLine .system('./'.expand('%<'))
elseif &filetype == 'python'
let runResu=runResLine .system('python3 '.expand('%'))
elseif &filetype == 'lua'
let runResu=runResLine .system('lua '.expand('%'))
elseif &filetype == 'sh'
let runResu=runResLine .system('sh '.expand('%'))
else
return
endif
bot 9sp runResult
setlocal buftype=nofile bufhidden=hide noswapfile
1s/^/\=runResu/
1
endfunction
nnoremap <localleader>ll :call ExecProm()<cr>
autocmd BufNewFile,BufWrite * :syntax match operators "\<compile result\>"
autocmd BufNewFile,BufWrite * :syntax match operators "\<run result\>"
hi operators ctermfg = DarkCyan
"}
"{
au BufNewFile,BufRead *.h set filetype=h
autocmd BufNewFile *.cpp,*.c,*.h,*.sh, exec ":call SetTitle()"
func! SetTitle()
if &filetype == 'sh'
call setline(1, "\#!/bin/bash")
call append(line("."), "\##########################################################")
call append(line(".")+1, "\# File Name: ".expand("%"))
call append(line(".")+2, "\# Author: ims")
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\##########################################################")
call append(line(".")+5, "")
else
call setline(1, "/*********************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: ims")
call append(line(".")+2, " > Created Time: ".strftime("%c"))
call append(line(".")+3, " *********************************************************/")
call append(line(".")+4, "")
endif
if &filetype == 'c'
call append(line(".")+5, "#include <stdio.h>")
call append(line(".")+6, "#include <string.h>")
call append(line(".")+7, "#include <stdlib.h>")
call append(line(".")+8, "#include <unistd.h>")
call append(line(".")+9, "")
endif
if &filetype == 'cpp'
call append(line(".")+5, "#include <iostream>")
call append(line(".")+6, "#include <string>")
call append(line(".")+7, "#include <vector>")
call append(line(".")+8, "using namespace std;")
call append(line(".")+9, "")
endif
if &filetype == 'cpp' || &filetype == 'c'
call append(line(".")+10, "int main()")
call append(line(".")+11, "{")
call append(line(".")+12, "\t")
call append(line(".")+13, "\treturn 0;")
call append(line(".")+14, "}")
endif
if &filetype == 'h'
let fileName = strpart(expand("%"),0,strlen(expand("%"))-2)
let headFileMacro = toupper(fileName).'_H'
call append(line(".")+5, '#ifndef '.headFileMacro)
call append(line(".")+6, '#define '.headFileMacro)
call append(line(".")+7, "")
call append(line(".")+8, " ")
call append(line(".")+9, "#endif")
set filetype=cpp
endif
normal 14G"
endfunc
autocmd BufRead *.h set filetype=cpp
"}
:endif