vim configure

env install

1
2
3
4
5
6
7
8
9
10
#!/bin/bash

#apt-get是针对ubuntu平台的安装,mac安装可将apt-get更改为brew
apt-get update -y
apt-get upgrade -y
apt-get install build-essential cmake vim-nox python3-dev clang libclang-dev clang-tidy clang-format -y
apt-get install mono-complete nodejs default-jdk npm gnutls-bin xdg-utils curl -y
apt-get install golang git -y
apt-get remove
apt-get autoremove
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
#npm i -g install instant-markdown-d

if [ ! -d ~/.vim/bundle ]
then
mkdir -p ~/.vim/bundle
fi

if [ ! -d ~/.vim/autoload ]
then
mkdir -p ~/.vim/autoload
#wget https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim ~/.root/autoload/
fi
# get bundle
git config --global http.sslVerify false
git config --global http.postBuffer 1048576000
if [ ! -d ~/.vim/bundle/Vundle.vim ]
then
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
fi
if [ ! -d ~/.vim/bundle/nerdtree ]
then
git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle/nerdtree
fi
if [ ! -d ~/.vim/bundle/nerdtree-git-plugin ]
then
git clone --recursive https://github.com/Xuyuanp/nerdtree-git-plugin.git ~/.vim/bundle/nerdtree-git-plugin
fi
if [ ! -d ~/.vim/bundle/vim-devicons ]
then
git clone --recursive https://github.com/ryanoasis/vim-devicons.git ~/.vim/bundle/vim-devicons
fi
if [ ! -d ~/.vim/bundle/syntastic ]
then
git clone --depth=1 https://github.com/vim-syntastic/syntastic.git ~/.vim/bundle/syntastic
fi
if [ ! -d ~/.vim/bundle/vim-airline ]
then
git clone --depth=1 https://github.com/vim-airline/vim-airline.git ~/.vim/bundle/vim-airline
fi
if [ ! -d ~/.vim/bundle/vim-colors-solarized ]
then
git clone --recursive https://github.com/altercation/vim-colors-solarized.git ~/.vim/bundle/vim-colors-solarized
fi
if [ ! -d ~/.vim/bundle/YouCompleteMe ]
then
git clone --recursive https://github.com/ycm-core/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
echo "export GO111MODULE=on" >> ~/.profile
echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
cd ~/.vim/bundle/YouCompleteMe/ && python3 ./install.py --clangd-completer
fi

vimrc configure

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
runtime! debian.vim
filetype off

" Plugin
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"" install Vundle
Plugin 'gmarik/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'ryanoasis/vim-devicons'
Plugin 'vim-syntastic/syntastic'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'altercation/vim-colors-solarized'
Plugin 'majutsushi/tagbar'
Plugin 'valloric/youcompleteme'
Plugin 'zivyangll/git-blame.vim'
Plugin 'haya14busa/incsearch.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'rhysd/vim-clang-format'
Plugin 'instant-markdown/vim-instant-markdown'

" Plugin end
call vundle#end()
filetype plugin indent on

" Plugin config
"" Nerd tree
autocmd vimenter * NERDTreeFind
wincmd w
autocmd vimenter * wincmd w
let g:NERDTreeDirArrowExpandable='►'
let g:NERDTreeDirArrowCollapsible='▼'
let g:NERDTreeWinPos='left'
let g:NERDTreeWinSize=40
let g:NERDTreeShowLineNumbers=1
autocmd vimenter * if !argc()|NERDTree|endif
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
""nnoremap <F10> :NERDTreeToggle<CR>
let g:NERDTreeGitStatusIndicatorMapCustom={
\ 'Modified' :'✹',
\ 'Staged' :'✚',
\ 'Untracked' :'✭',
\ 'Renamed' :'➜',
\ 'Unmerged' :'═',
\ 'Deleted' :'✖',
\ 'Dirty' :'✗',
\ 'Ignored' :'☒',
\ 'Clean' :'✔︎',
\ 'Unknown' :'?',
\ }

" Check if NERDTree is open or active
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" Call NERDTreeFind if NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" Highlight currently open buffer in NERDTree
autocmd BufEnter * call SyncTree()

function! ToggleNerdTree()
set eventignore=BufEnter
NERDTreeToggle
set eventignore=
endfunction
""nmap <C-n> :call ToggleNerdTree()<CR>
nmap <F10> :call ToggleNerdTree()<CR>


"" syntastic check
execute pathogen#infect()
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%{FugitiveStatusline()}
set statusline+=%*

"" vim airline
let g:airline#extensions#tabline#enabled=1
let g:syntastic_always_populate_loc_list=1
let g:syntastic_auto_loc_list=1
let g:syntastic_check_on_open=1
let g:syntastic_check_on_wq=0

"" vim-colors-solarized
syntax enable " Enable syntax highlighting
colorscheme solarized " Change color scheme
""colorscheme industry " Change color scheme
let g:solarized_termcolors=256
call togglebg#map("<F5>")
set background=dark " Use colors that suit a dark background

"" tagbar
let g:tagbar_ctags_bin='/usr/bin/ctags'
let g:tagbar_sort=0
let g:tagbar_width=40
nnoremap <F9> :TagbarToggle<CR>

"" youcompleteme
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py'
let g:ycm_confirm_extra_conf=1
let g:ycm_auto_trigger=1
"let g:ycm_confirm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
nnoremap <leader>yfw <Plug>(YCMFindSymbolInWorkspace)
nnoremap <leader>yfd <Plug>(YCMFindSymbolInDocument)
nnoremap <leader>jd :YcmCompleter GoToDefinition<CR>
nnoremap <leader>jl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>jf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>jg :YcmCompleter GoToDefinitionElseDeclaration<CR>
let g:ycm_key_invoke_completion='<c-space>'
""set completeopt=menu,menuone
set completeopt=menu
set completeopt-=preview
let g:ycm_add_preview_to_completeopt=0
let g:ycm_autoclose_preview_window_after_insertion=0
let g:ycm_autoclose_preview_window_after_completion=0
""autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
""autocmd InsertLeave * if pumvisible() == 0|pclose|endif
let g:ycm_filetype_whitelist={
\ "c":1,
\ "cc":1,
\ "cpp":1,
\ "h":1,
\ "hpp":1,
\ "objc":1,
\ "sh":1,
\ "zsh":1,
\ "zimbu":1,
\ }
let g:ycm_semantic_triggers = {
\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
\ 'cs,lua,javascript': ['re!\w{2}'],
\ }
"" git blame
nnoremap <Leader>\ :<C-u>call gitblame#echo()<CR>

"" clang format
""autocmd FileType c ClangFormatAutoEnable
""autocmd FileType h ClangFormatAutoEnable
""autocmd FileType cu ClangFormatAutoEnable
""autocmd FileType cpp ClangFormatAutoEnable
""autocmd FileType hpp ClangFormatAutoEnable
let g:clang_format#command = 'clang-format'
nmap <F4> :ClangFormat<cr>
let g:clang_format#detect_style_file = 1

let g:clang_format#style_options = {
\ "BasedOnStyle" : "Google",
\ "ColumnLimit" : 110,
\ "IndentWidth" : 4
\}

"" instant markdown
"Uncomment to override defaults:
"let g:instant_markdown_slow = 1
"let g:instant_markdown_autostart = 0
"let g:instant_markdown_open_to_the_world = 1
"let g:instant_markdown_allow_unsafe_content = 1
"let g:instant_markdown_allow_external_content = 0
"let g:instant_markdown_mathjax = 1
"let g:instant_markdown_mermaid = 1
"let g:instant_markdown_logfile = '/tmp/instant_markdown.log'
"let g:instant_markdown_autoscroll = 0
"let g:instant_markdown_port = 8888
"let g:instant_markdown_python = 1

" common set up
set number " Show line numbers
set showmatch " Highlight matching brace
set visualbell " Use visual bell (no beeping)
set hlsearch " Highlight all search results
set smartcase " Enable smart-case search
set gdefault " Always substitute all matches in a line
set ignorecase " Always case-insensitive
set incsearch " Searches for strings incrementally
set autoindent " Auto-indent new lines
set cindent "Use 'C' style program indenting
set expandtab " Use spaces instead of tabs
set shiftwidth=4 " Number of auto-indent spaces
set smartindent " Enable smart-indent
set smarttab " Enable smart-tabs
set softtabstop=4 " Number of spaces per Tab
set tabstop=4
set ruler " Show row and column ruler information
set undolevels=1000 " Number of undo levels
set backspace=indent,eol,start " Backspace behaviour
set lazyredraw " Don’t update screen during macro and script execution
set scrolloff=1 " The number of screen lines to keep above and below the cursor
set display+=lastline " Always try to show a paragraph’s last line
set relativenumber " Show line number on the current line and relative numbers on all other lines
set mouse=a " Enable mouse for scrolling and resizing
set title " Set the window’s title, reflecting the file currently being edited
set autoread " Automatically re-read files if unmodified inside Vim
set confirm " Display a confirmation dialog when closing an unsaved file
set history=1000 " Increase the undo limit
set showcmd " 输入的命令显示出来,看的清楚些
set laststatus=2 " 启动显示状态行(1),总是显示状态行(2)
set nocompatible " 去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set modifiable
set fileencodings=ucs-bom,utf-8,cp936,latin1
set fileencoding=utf-8
""set binary
set noeol
set clipboard+=unnamed " 共享剪贴板
set magic " 设置魔术
set confirm " 在处理未保存或只读文件的时候,弹出确认
set completeopt=longest,menu " 打开文件类型检测, 加了这句才可以用智能补全
set noerrorbells visualbell t_vb=
autocmd GUIEnter * set visualbell t_vb=
set t_RV=

if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add $PWD/cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif

nnoremap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>f :cs find f <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>i :cs find i <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
nnoremap <F12> gg=G
"去空行
nnoremap <F2> :g/^\s*$/d<CR>

"默认最大化窗口打开
au GUIEnter * simalt ~x

"""""新文件标题""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"新建.c,.h,.sh,.java文件,自动插入文件头
" autocmd BufNewFile *.py,*.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
autocmd BufNewFile * exec ":call SetTitle()"

""定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1,"\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Created Time: ".strftime("%c"))
call append(line(".")+2, "\#########################################################################")
call append(line(".")+3, "\#!/bin/bash")
call append(line(".")+4, "")
elseif &filetype == 'python'
call setline(1,"\#########################################################################")
call append(line("."), "\#-*- coding:utf-8 -*-")
call append(line(".")+1, "\#!/usr/bin/env python")
call append(line(".")+2, "\# File Name: ".expand("%"))
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\#########################################################################")
call append(line(".")+5, "")
elseif expand("%:e")== 'h'
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Created Time: ".strftime("%c"))
call append(line(".")+2, " ************************************************************************/")
call append(line(".")+3, "")
elseif &filetype == 'cpp'
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Created Time: ".strftime("%c"))
call append(line(".")+2, " ************************************************************************/")
call append(line(".")+3, "")
call append(line(".")+4, "#include <iostream>")
call append(line(".")+5, "")
elseif &filetype == 'c'
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Created Time: ".strftime("%c"))
call append(line(".")+2, " ************************************************************************/")
call append(line(".")+3, "")
call append(line(".")+4, "#include <stdio.h>")
call append(line(".")+5, "")
elseif expand("%:e")== 'md'
call setline(1, "```")
call append(line("."), "File Name: ".expand("%"))
call append(line(".")+1, "Created Time: ".strftime("%c"))
call append(line(".")+2, "```")
call append(line(".")+3, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Created Time: ".strftime("%c"))
call append(line(".")+2, " ************************************************************************/")
call append(line(".")+3, "")
endif
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
endfunc

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"自动补全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
filetype plugin indent on

"highlight Functions
autocmd BufNewFile,BufRead * :syntax match cfunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
autocmd BufNewFile,BufRead * :syntax match cfunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1
hi cFunctions gui=NONE cterm=bold ctermfg=blue

hi PreCondit ctermfg=161 cterm=bold
highlight LineNr ctermfg=darkblue
hi MatchParen ctermbg=Yellow guibg=lightblue
hi ModeMsg ctermfg=Green

set cursorline
hi CursorLine cterm=underline
hi SpellBad gui=undercurl ctermbg=52
hi SpellCap guisp=#7070F0 gui=undercurl
hi SpellLocal guisp=#70F0F0 gui=undercurl
hi SpellRare guisp=#FFFFFF gui=undercurl
hi SpellCap ctermbg=17
hi SpellLocal ctermbg=17
hi SpellRare ctermfg=none ctermbg=none cterm=reverse

let vim_markdown_preview_github=1

" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
autocmd!
" In text files, always limit the width of text to 78 characters
" autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
" don't write swapfile on most commonly used directories for NFS mounts or USB sticks
autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
" start with spec file template
autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
augroup END
endif

"" vimdiff
if &diff
colorscheme evening
endif


""""""""""""""""""""""""""""""
"Chinese Punctuation
""""""""""""""""""""""""""""""
function! CheckChineseMark()
"依次检查
if search('。')
execute "%s/。/\."
endif

if search(',')
execute "%s/,/,"
endif

if search(';')
execute "%s/;/;"
endif

if search('?')
execute "%s/?/?"
endif

if search(':')
execute "%s/:/\:"
endif

if search('‘')
execute "%s/‘/\'"
endif

if search('’')
execute "%s/’/\'"
endif

if search('”')
execute "%s/”/\""
endif

if search('“')
execute "%s/“/\""
endif

if search('《')
execute "%s/《/\<"
endif

if search('》')
execute "%s/》/\>"
endif

if search('——')
execute "%s/——/-"
endif

if search(')')
execute "%s/)/\)"
endif

if search('(')
execute "%s/(/\("
endif

if search('!')
execute "%s/!/!"
endif

if search('【')
execute "%s/【/\["
endif

if search('】')
execute "%s/】/\]"
endif
endfunction
nnoremap <C-L> <ESC>:call CheckChineseMark()<ESC>
-------------The End-------------