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
| """""""""""""""""""""""""
" Rover12421 2014/03/03 "
"""""""""""""""""""""""""
" 关闭vi的一致性模式 避免以前版本的一些Bug和局限
set nocompatible
" 配置backspace键工作方式
set backspace=indent,eol,start
" 显示行号
set number
nnoremap <F6> :set nonumber!<CR>:set foldcolumn=0<CR>
" 设置在编辑过程中右下角显示光标的行列信息
set ruler
" 当一行文字很长时取消换行
set nowrap
" 在状态栏显示正在输入的命令
set showcmd
" 设置历史记录条数
set history=100
" 设置取消备份 禁止临时文件生成
set nobackup
set noswapfile
" 突出现实当前行列、高亮当前行列
set cursorline
set cursorcolumn
" 设置匹配模式 类似当输入一个左括号时会匹配相应的那个右括号
set showmatch
" 设置C/C++方式自动对齐
set autoindent
set cindent
" 开启语法高亮功能
syntax enable syntax on
" 指定配色方案为256色
set t_Co=256
" 设置搜索时忽略大小写
set ignorecase
" 设置在Vim中可以使用鼠标 防止在Linux终端下无法拷贝
set mouse=a
" 设置Tab宽度
set tabstop=4
" 设置自动对齐空格数
set shiftwidth=4
" 设置按退格键时可以一次删除4个空格
set softtabstop=4
" 设置按退格键时可以一次删除4个空格
set smarttab
" 将Tab键自动转换成空格 真正需要Tab键时使用[Ctrl + V + Tab]
set expandtab
" 设置编码方式
set encoding=utf-8
" 自动判断编码时 依次尝试一下编码
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
" 检测文件类型
filetype on
" 针对不同的文件采用不同的缩进方式
filetype indent on
" 允许插件
filetype plugin on
" 启动智能补全
filetype plugin indent on
"===================================================================
"===================================================================
"
" 自定义vim操作
"
"====================================================================
"====================================================================
map <F5> :call Do_OneFileMake()<CR>
map <F2> :call Do_FileSave()<CR>
map <F3> :call Do_FileSaveAndQuit()<CR>
" === 当前文件保存 ===
function Do_FileSave()
let source_file_name=expand("%:t")
if source_file_name==""
echoh1 WarningMsg | echo "The file name is empty." | echoh1 None
return
endif
execute "w"
endfunction
" === 当前文件保存退出 ===
function Do_FileSaveAndQuit()
let source_file_name=expand("%:t")
if source_file_name==""
echoh1 WarningMsg | echo "The file name is empty." | echoh1 None
return
endif
execute "wq"
endfunction
" === 单文件编译 仅支持c、cc、cpp、go文件 ===
function Do_OneFileMake()
if expand("%:p:h")!=getcwd()
echoh1 WarningMsg | echo "Failed to make. This's file is not in the current dir." | echoh1 None
return
endif
let source_file_name=expand("%:t")
if source_file_name==""
echoh1 WarningMsg | echo "The file name is empty." | echoh1 None
return
endif
if ( (&filetype!="c")&&(&filetype!="cc")&&(&filetype!="cpp")&&(&filetype!="go") )
echoh1 WarningMsg | echo "Please just make c、cc、cpp and go file." | echoh1 None
return
endif
if &filetype=="c"
set makeprg=gcc\ %\ -o\ %<
endif
execute "w"
execute "silent make"
execute "q"
endfunction
"==============================================================
"==============================================================
"
" Vundle插件管理和配置项
"
"==============================================================
"==============================================================
" 开始使用Vundle的必须配置
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" === 使用Vundle来管理Vundle ===
Bundle 'gmarik/vundle'
" === PowerLine插件 状态栏增强展示 ===
Bundle 'Lokaltog/vim-powerline'
" vim有一个状态栏 加上powline则有两个状态栏
set laststatus=2
let g:Powline_symbols='fancy'
" === The-NERD-tree 目录导航插件 ===
Bundle 'vim-scripts/The-NERD-tree'
" 开启目录导航快捷键映射成n键
nnoremap <C-t> :NERDTreeToggle<CR>
" 高亮鼠标所在的当前行
let NERDTreeHighlightCursorline=1
" === Tagbar 标签导航 ===
Bundle 'majutsushi/tagbar'
" 标签导航快捷键
nmap <F9> :TagbarToggle<CR>
let g:tagbar_autofocus = 1
" === A 头文件和实现文件自动切换插件 ===
Bundle 'vim-scripts/a.vim'
" 将切换的快捷键映射成<F4>
nnoremap <silent> <F4> :A<CR>
"=== ctrlp 文件搜索插件 不需要外部依赖包 ===
Bundle 'kien/ctrlp.vim'
" 设置开始文件搜索的快捷键
let g:ctrlp_map = '<leader>p'
" 设置默认忽略搜索的文件格式
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$\|.rvm$'
" 设置搜索时显示的搜索结果最大条数
let g:ctrlp_max_height=15
" === YouCompleteMe 自动补全插件===
Bundle 'Valloric/YouCompleteMe'
" 自动补全配置插件路径
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'
let g:EclimCompletionMethod = 'omnifunc'
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_min_num_of_chars_for_completion = 1
"youcompleteme 默认tab s-tab 和自动补全冲突
"let g:ycm_key_list_select_completion=['<c-n>']
"let g:ycm_key_list_select_completion = ['<Down>']
"let g:ycm_key_list_previous_completion=['<c-p>']
"let g:ycm_key_list_previous_completion = ['<Up>']
"nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
"let g:UltiSnipsExpandTrigger="<c-j>"
" 当选择了一项后自动关闭自动补全提示窗口
"let g:ycm_autoclose_preview_window_after_completion=1
" === 自动补全单引号、双引号、括号等 ===
Bundle 'Raimondi/delimitMate'
" === 主题solarized ===
Bundle 'altercation/vim-colors-solarized'
let g:solarized_termtrans=1
let g:solarized_contrast="normal"
let g:solarized_visibility="normal"
" === 主题 molokai ===
Bundle 'tomasr/molokai'
" 设置主题 colorscheme molokai
set background=dark
set t_Co=256
" === indentLine代码排版缩进标识 ===
Bundle 'Yggdroot/indentLine'
let g:indentLine_noConcealCursor = 1
let g:indentLine_color_term = 0
" 缩进的显示标识|
let g:indentLine_char = '¦'
" === vim-trailing-whitespace将代码行最后无效的空格标红 ===
Bundle 'bronson/vim-trailing-whitespace'
" === markdown编辑插件 ===
Bundle 'plasticboy/vim-markdown'
let g:vim_markdown_folding_disabled=1
" === golang编辑插件 ===
Bundle 'jnwhiteh/vim-golang'
" ==========================
" 其他推荐插件
" vim scripts
Bundle 'taglist.vim'
Bundle 'c.vim'
Bundle 'minibufexpl.vim'
Bundle 'grep.vim'
Bundle 'mru.vim'
Bundle 'comments.vim'
" 神级插件,ZenCoding可以让你以一种神奇而无比爽快的感觉写HTML、CSS
Bundle 'ZenCoding.vim'
" 自动补全xml/html代码
Bundle 'xml.vim'
" json代码补全
Bundle 'JSON.vim'
" Python代码检查
Bundle 'pyflakes.vim'
" 提供命令模式下的补全
Bundle 'CmdlineComplete'
" 提供日历的功能,可以写日记
Bundle 'calendar.vim'
" 自动检测文件编码
Bundle 'FencView.vim'
" git repo
Bundle 'scrooloose/nerdtree'
Bundle 'vim-scripts/AutoClose'
Bundle 'scrooloose/syntastic'
Bundle 'kien/rainbow_parentheses.vim'
Bundle 'vim-scripts/UltiSnips'
" 据说是革命性的移动方案,不知道有多革命性
Bundle 'Lokaltog/vim-easymotion'
" smali 语法高亮
Bundle 'alderz/smali-vim'
"Bundle 'kelwin/vim-smali'
" ==========================
" Vundle配置必须 开启插件
filetype plugin indent on
" syntastic
" ==========================
let g:syntastic_check_on_open = 1
let g:syntastic_cpp_include_dirs = ['/usr/include/']
let g:syntastic_cpp_remove_include_errors = 1
let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libstdc++'
"set error or warning signs
let g:syntastic_error_symbol = '✗'
let g:syntastic_warning_symbol = '⚠'
"whether to show balloons
let g:syntastic_enable_balloons = 1
" ==========================
""""""""""""ctags settings"""""""""""""""""
set tags+=~/.vim/cpptags
set tags+=~/.vim/systags
"""""""""""color scheme""""""""""""""""""""
let g:molokai_original=1
""""""""" Settings of taglist""""""""""""""
" increase the width of the taglist window
let Tlist_WinWidth=10
" automatically open the taglist window
let Tlist_Auto_Open=0
" exit wim when only the taglist window exist
let Tlist_Exit_OnlyWindow=1
" open tags with single click
let Tlist_Use_SingleClick=1
" close tag folds for inactive buffers
let Tlist_File_Fold_Auto_Close=1
" show the fold indicator column in the taglist window
let Tlist_Enable_Fold_Column=1
" Automatically update the taglist to include newly edited files
let Tlist_Auto_Update=1
"""""""""" NERDtree settings"""""""""""""""
" let NERDTreeWinPos='right'
"""""""""" mini buffer navigator"""""""""""
let g:miniBUfExplMapWindowNavVim=1
let g:miniBufExplMapWindowNavArrows=1
let g:miniBufExplMapCTabSwitchBufs=1
let g:miniBufExplModSelTarget=1
let g:miniBufExplUseSingleClick=1
"map <C-c> "+y
map <C-v> "+p
|