/root/.vimrc

1
map <F5> :call CompileRunGcc()<CR>
2
func! CompileRunGcc()
3
    exec "w"
4
    if &filetype == 'c'
5
        exec "!g++ % -o %<"
6
        exec "! ./%<"
7
    elseif &filetype == 'cpp'
8
        exec "!g++ % -o %<"
9
        exec "! ./%<"
10
    elseif &filetype == 'python'
11
        exec "!time python3 %"
12
    elseif &filetype == 'java'
13
        exec "!javac %"
14
        exec "!java  %<"
15
    elseif &filetype == 'sh'
16
	:!time bash %
17
    elseif &filetype == 'go'
18
	exec "!go build %<"
19
    endif
20
endfunc
21
execute pathogen#infect()
22
23
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
24
"set termencoding=utf-8
25
"set encoding=utf-8
26
"autocmd BufWritePost $MYVIMRC source $MYVIMRC
27
28
set nocompatible
29
filetype off
30
set rtp+=~/.vim/bundle/Vundle.vim
31
call vundle#begin()
32
Plugin 'VundleVim/Vundle.vim'
33
" 请在此句下添加插件------------
34
Plugin 'vim-airline/vim-airline-themes'
35
Plugin 'wakatime/vim-wakatime' " waka
36
Plugin 'vim-airline/vim-airline' " 状态栏
37
Plugin 'scrooloose/nerdtree' " 树形目录
38
Plugin 'Yggdroot/indentLine' " 缩进指示线
39
Plugin 'scrooloose/nerdcommenter' " 方便的写注释
40
Plugin 'tell-k/vim-autopep8' " 自动格式化工具
41
Plugin 'jiangmiao/auto-pairs' " 括号引号自动补全
42
Plugin 'ctrlpvim/ctrlp.vim' " 定位工程中某个文件
43
Plugin 'luochen1990/rainbow' " 彩虹色括号增强版
44
Plugin 'dyng/ctrlsf.vim' " 工程中全局搜索特定字符
45
Plugin 'majutsushi/tagbar' " 显示文件中的类函数和变量
46
Plugin 'vim-scripts/indentpython.vim' " 支持PythonPep8自动缩进
47
Plugin 'MarcWeber/vim-addon-mw-utils'
48
Plugin 'tomtom/tlib_vim'
49
Plugin 'garbas/vim-snipmate'
50
Plugin 'honza/vim-snippets'
51
Plugin 'morhetz/gruvbox'
52
Plugin 'w0rp/ale'  " 语法检查
53
" 请在此句上添加插件------------
54
call vundle#end()
55
filetype plugin indent on " 自动识别文件类型,文件类型脚本,缩进定义文件
56
"-------------------------------
57
syntax on " 开启语法高亮
58
let python_highlight_all=1 " python高亮
59
set magic " 这玩意儿俺也不知道干嘛用
60
set nu " 显示行号
61
set guifont=Monaco:h12 " 设置字体
62
set tabstop=4 " 设置tab长度
63
set shiftwidth=4 " 统一缩进4
64
set softtabstop=4 " 删除tab为4
65
set smarttab " 行和段开始使用制表符
66
set noexpandtab " 不适用空格代替制表符
67
set showmatch " 显示匹配的括号
68
set backspace=2 " 增强删除
69
set mouse=a " 启用鼠标
70
set selection=exclusive
71
set selectmode=mouse,key
72
set ignorecase " 搜索忽略大小写
73
set hlsearch " 高亮搜索项
74
set cursorline " 突出显示当前行
75
"set cursorcolumn " 突出显示当前列
76
set encoding=utf-8 " 解码utf-8
77
set fenc=utf-8 " 文件编码
78
set splitbelow " 分割布局
79
set splitright " 分割布局
80
"set autoindent " 自动对齐
81
set smartindent " 智能对齐
82
set langmenu=zn_CN.UTF-8 " 菜单语言
83
set helplang=cn " 语言设置
84
set confirm " 在处理未保存或只读文件的时候,弹出确认框
85
set autowrite " 切换时自动保存当前文件
86
set autochdir " 自动切换当前目录为当前文件所在目录
87
set wildmenu " 增强模式中命令行自动完成操作
88
set foldenable " 允许折叠
89
set foldmethod=syntax " 语法折叠
90
set foldcolumn=0 " 折叠区域宽度
91
set foldlevel=1 " 折叠层数为1
92
set foldclose=all " 设置自动关闭折叠
93
set completeopt=longest,menu " 智能补全
94
set scrolloff=3 " 光标移动到顶部和底部时保持3行的距离
95
set laststatus=2 " 显示状态栏
96
set ruler " 光标位置显示在状态栏中
97
set showcmd " 在状态行显示目前所执行的命令,未完成的命令也会显示出来
98
" 分割布局快捷键设置
99
nnoremap <C-J> <C-W><C-J>
100
nnoremap <C-K> <C-W><C-K>
101
nnoremap <C-L> <C-W><C-L>
102
nnoremap <C-H> <C-W><C-H>
103
104
" 标识不必要的空白字符
105
"Flagging Unnecessary Whitespace
106
highlight BadWhitespace ctermbg=red guibg=darkred
107
au BufRead,BufNewfile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
108
109
"auto add python header --start
110
autocmd BufNewFile *.py 0r ~/.vim/vim_template/vim_python_header
111
autocmd BufNewFile *.py ks|call FileName()|'s
112
autocmd BufNewFile *.py ks|call CreatedTime()|'s
113
fun FileName()
114
	if line("$") > 10
115
		let l = 10
116
	else
117
		let l = line("$")
118
	endif
119
	exe "1,".l."g/File Name:.*/s/File Name:.*/File Name: ".expand("%")
120
endfun
121
fun CreatedTime()
122
	if line("$") > 10
123
		let l = 10
124
	else
125
		let l = line("$")
126
	endif
127
	exe "1,".l."g/Created Time:.*/s/Created Time:.*/Created Time: ".strftime("%Y-%m-%d %T")
128
	autocmd BufNewFile * normal G
129
endfun
130
autocmd BufNewFile * normal G
131
"auto add python header --end
132
133
" Python代码缩进 PEP8风格
134
"au BufNewFile,BufRead *.py
135
au BufNewFile,BufRead  *.py
136
	\ set tabstop=4 |
137
	\ set softtabstop=4 |
138
	\ set shiftwidth=4 |
139
	\ set textwidth=79 |
140
	\ set expandtab |
141
	\ set autoindent |
142
	\ set fileformat=unix
143
au BufNewFile,BufRead *.js, *.html, *.css
144
    \ set tabstop=2 |
145
    \ set softtabstop=2 |
146
    \ set shiftwidth=2 |
147
au BufNewFile,BufRead *.yml
148
    \ set tabstop=2 |
149
    \ set softtabstop=2 |
150
    \ set shiftwidth=2 |
151
" 自动补全括号 已被插件auto-pairs取代
152
:inoremap ( ()<ESC>i
153
:inoremap ) <c-r>=ClosePair(')')<CR>
154
:inoremap { {<CR>}<ESC>O
155
:inoremap } <c-r>=ClosePair('}')<CR>
156
:inoremap [ []<ESC>i
157
:inoremap ] <c-r>=ClosePair(']')<CR>
158
:inoremap < <><ESC>i
159
:inoremap > <c-r>=ClosePair('>')<CR>
160
:inoremap " ""<ESC>i
161
:inoremap ' ''<ESC>i
162
function! ClosePair(char)
163
if getline('.')[col('.') - 1] == a:char
164
return "\<Right>"
165
else
166
return a:char
167
endif
168
endfunction
169
170
" NeraTree 配置
171
" 快捷键设置
172
map <F2> :NERDTreeToggle<CR>
173
let NERDTreeChDirMode=1
174
let NERDTreeShowBookmarks=1 " 显示书签
175
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$'] " 设置忽略文件类型
176
let NERDTreeWinSize=25 " 窗口大小
177
178
" indentLine 配置
179
let g:indentLine_char=' '
180
let g:indentLine_enabled=1
181
182
" autopep8 配置
183
let g:autopep8_disable_show_diff=1
184
185
" nercommenter 快捷键设置
186
map <F4> <leader>ci <CR>
187
188
" CtrlSF 快捷键设置
189
map f <Plug>CtrlSFPrompt
190
map F <Plug>CtrlSFQuickfixPronpt
191
192
" Tagbar 快捷键设置
193
map <F6> :TagbarToggle<CR>
194
195
" airline 配置
196
let g:airline_theme="angr"
197
let g:airline#extensions#tabline#enabled=1 " 启用顶部tabline
198
let g:airline#extensions#tabline#left_sep=' ' " 顶部tabline显示方式
199
let g:airline#extensions#tabline#left_alt_sep='|'
200
201
" rainbow 配置
202
let g:rainbow_conf = {
203
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
204
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
205
\ 'operators': '_,_',
206
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
207
\ 'separately': {
208
\ '*': {},
209
\ 'tex': {
210
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
211
\ },
212
\ 'lisp': {
213
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
214
\ },
215
\ 'vim': {
216
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
217
\ },
218
\ 'html': {
219
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
220
\ },
221
\ 'css': 0,
222
\ }
223
\}
224
225
" jedi代码补全配置
226
"let g:jedi#goto_command = "<leader>d"
227
"let g:jedi#goto_assignments_command = "<leader>g"
228
"let g:jedi#goto_definitions_command = ""
229
"let g:jedi#documentation_command = "K"
230
"let g:jedi#usages_command = "<leader>n"
231
"let g:jedi#completions_command = "<C-Space>"
232
"let g:jedi#rename_command = "<leader>r"
233
234
" Pydiction
235
let g:pydiction_location = '~/.vim/bundle/Pydiction/complete-dict'
236
let g:pydiction_menu_height = 3
237
238
" Remap snipmate's trigger key from tab to <C-J>
239
imap <C-J> <Plug>snipMateNextOrTrigger
240
smap <C-J> <Plug>snipMateNextOrTrigger
241
242
" ale
243
" 始终开启标志列
244
"let g:ale_sign_column_always = 1
245
let g:ale_set_highlights = 0
246
" 自定义error和warning图标
247
let g:ale_sign_error = '>>'
248
let g:ale_sign_warning = '--'
249
 "在vim自带的状态栏中整合ale
250
let g:ale_statusline_format = ['✗ %d', '⚡ %d', '✔ OK']
251
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}\ %{ALEGetStatusLine()}
252
253
"显示Linter名称,出错或警告等相关信息
254
let g:ale_echo_msg_error_str = 'E'
255
let g:ale_echo_msg_warning_str = 'W'
256
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
257
258
let g:ale_lint_on_text_changed = 'never'
259
let g:ale_lint_on_enter = 0
260
261
"普通模式下,sp前往上一个错误或警告,sn前往下一个错误或警告
262
nmap sp <Plug>(ale_previous_wrap)
263
nmap sn <Plug>(ale_next_wrap)
264
265
"<Leader>s触发/关闭语法检查
266
nmap <Leader>s :ALEToggle<CR>
267
268
"<Leader>d查看错误或警告的详细信息
269
nmap <Leader>a :ALEDetail<CR>
270
271
let g:ale_linters = {
272
\   'c++': ['g++'],
273
\   'c': ['g++'],
274
\   'python': ['pylint'],
275
\}
276
277
" wakatime
278
let g:wakatime_PythonBinary = '/usr/python/bin/python3'  " (Default: 'python')
279
let g:wakatime_OverrideCommandPrefix = '/usr/python/bin/wakatime'  " (Default: '')
280
let g:ale_completion_enabled=1
281
282
" gruvbox
283
set bg=light
284
colorscheme gruvbox
285
set guioptions=
286
"set guifont=Monaco:h17
287
288
"<!--html标签自动补全{{{-->
289
" html自动补全
290
"autocmd BufNewFile *  setlocal filetype=html
291
"function! InsertHtmlTag()
292
	"let pat = '\c<\w\+\s*\(\s\+\w\+\s*=\s*[''#$;,()."a-z0-9]\+\)*\s*>'
293
	"normal! a>
294
	"let save_cursor = getpos('.')
295
	"let result = matchstr(getline(save_cursor[1]), pat)
296
	"if (search(pat, 'b', save_cursor[1]) && searchpair('<','','>','bn',0,  getline('.')) > 0)
297
	"if (search(pat, 'b', save_cursor[1]))
298
		"normal! lyiwf>
299
		"normal! a</
300
		"normal! p
301
		"normal! a>
302
	"endif
303
	":call cursor(save_cursor[1], save_cursor[2], save_cursor[3])
304
"endfunction
305
"inoremap > <ESC>:call InsertHtmlTag()<CR>a<CR><Esc>O
306
"<!--}}}-->