Vim配置

1.查看~/目录下有没有一个.vimrc的文件,如果没有自己在当前目录创建一个。

touch  .vimrc

2.需要说明的是在root目录下的.vimrc对所有用户生效。你也可以在每个用户下单独配置个性化.vimrc。

3.vim的功能实际上是由配置文件和插件共同决定的,这里提供一份配置文件源码,复制到自己的.vimrc文件中即可: 

  1 set helplang=cn  
  2 set encoding=utf-8  
  3 set cscopequickfix=s-,c-,d-,i-,t-,e-  
  4 nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>  
  5 nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>  
  6 nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>  
  7 nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>  
  8 nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>  
  9 nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>  
 10 nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>  
 11 nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>  
 12 let g:miniBufExplMapCTabSwitchBufs = 1  
 13 let g:miniBufExplMapWindowNavVim = 1  
 14 let g:miniBufExplMapWindowNavArrows = 1  
 15 nnoremap <silent> <F12> :A<CR>  
 16 nnoremap <silent> <F3> :Grep<CR>  
 17 let g:SuperTabRetainCompletionType=2  
 18 let g:SuperTabDefaultCompletionType="<C-X><C-O>"  
 19 " 自动语法高亮  
 20  syntax on  
 21 " 检测文件类型  
 22 filetype on  
 23 " 检测文件类型插件  
 24 filetype plugin on  
 25 " 不设定在插入状态无法用退格键和 Delete 键删除回车符  
 26 set backspace=indent,eol,start  
 27 set whichwrap+=<,>,h,l  
 28 " 显示行号  
 29 set number  
 30 " 上下可视行数  
 31 set scrolloff=6  
 32 " replace tab with space  
 33 set expandtab  
 34 " 设定 tab 长度为 4  
 35 set tabstop=4  
 36 " 设置按BackSpace的时候可以一次删除掉4个空格  
 37 set softtabstop=4  
 38 " 设定 << 和 >> 命令移动时的宽度为 4  
 39 set shiftwidth=4  
 40 set smarttab  
 41 set history=1024  
 42 " 不突出显示当前行  
 43 set nocursorline  
 44 " 覆盖文件时不备份  
 45 set nobackup  
 46 " 自动切换当前目录为当前文件所在的目录  
 47 set autochdir  
 48 " 搜索时忽略大小写,但在有一个或以上大写字母时仍大小写敏感  
 49 set ignorecase  
 50 set smartcase  
 51 " 搜索到文件两端时不重新搜索  
 52 set nowrapscan  
 53 " 实时搜索  
 54 set incsearch  
 55 " 搜索时高亮显示被找到的文本  
 56 set hlsearch  
 57 " 关闭错误声音  
 58 set noerrorbells  
 59 set novisualbell  
 60 "set t_vb=  
 61   
 62 " 不自动换行  
 63 "set nowrap  
 64 "How many tenths of a second to blink  
 65 set mat=2  
 66 " 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存  
 67 set hidden  
 68 " 智能自动缩进  
 69 set smartindent  
 70 " 设定命令行的行数为 1  
 71 set cmdheight=1  
 72 " 显示状态栏 (默认值为 1, 无法显示状态栏)  
 73 set laststatus=2  
 74 "显示括号配对情况  
 75 set showmatch  
 76   
 77 " 解决自动换行格式下, 如高度在折行之后超过窗口高度结果这一行看不到的问题  
 78 set display=lastline  
 79 " 设定配色方案  
 80 colorscheme evening  
 81 " 设置在状态行显示的信息  
 82 set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ [%{(&fenc==\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %c:%l/%L%)  
 83   
 84 " 显示Tab符  
 85 set list  
 86 set listchars=tab:\|\ ,trail:.,extends:>,precedes:<  
 87 "启动时不显示 捐赠提示  
 88 set shortmess=atl  
 89   
 90 "blank      空白  
 91 "buffers    缓冲区  
 92 "curdir     当前目录  
 93 "folds      折叠  
 94 "help       帮助  
 95 "options    选项  
 96 "tabpages   选项卡  
 97 "winsize    窗口大小  
 98 "slash      转换文件路径中的\为/以使session文件兼容unix  
 99 "unix       设置session文件中的换行模式为unix  
100 set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize,slash,unix,resize  
101   
102 " 允许backspace和光标键跨越行边界  
103 set whichwrap+=<,>,h,l  
104 " backspace  
105 set backspace=eol,start,indent  
106   
107 " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)  
108 set mouse=a  
109 set selection=exclusive  
110 set selectmode=mouse,key  
111   
112 " 在被分割的窗口间显示空白,便于阅读  
113 set fillchars=vert:\ ,stl:\ ,stlnc:\  
114   
115 " 高亮显示匹配的括号  
116 set showmatch  
117   
118 " 匹配括号高亮的时间(单位是十分之一秒)  
119 set matchtime=5  
120   
121 "编码设置  
122 set enc=utf-8  
123 set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936  
124   
125 " set mapleader  
126 let mapleader=","  
127   
128 nmap J 5j  
129 nmap K 5k  
130   
131 " Ctrl+a  
132 nmap <silent> <C-a> ggvG$  
133   
134 " 选中状态下 Ctrl+c 复制  
135 vnoremap <c-c> "+y  
136   
137 " Ctrl+v  
138 nmap <silent> <C-v> "+p  
139   
140 " 窗口切换  
141 nnoremap <c-h> <c-w>h  
142 nnoremap <c-l> <c-w>l  
143 nnoremap <c-j> <c-w>j  
144 nnoremap <c-k> <c-w>k  
145   
146 " 插入模式下上下左右移动光标  
147 inoremap <c-h> <left>  
148 inoremap <c-l> <right>  
149 inoremap <c-j> <c-o>gj  
150 inoremap <c-k> <c-o>gk  
151   
152 " Ctrl+s  
153 " If the current buffer has never been saved, it will have no name,  
154 " call the file browser to save it, otherwise just save it.  
155 "nnoremap <silent> <C-S> :if expand("%") == ""<CR>browse confirm w<CR>else<CR>confirm w<CR>endif<CR>  
156 "imap <c-s> <c-o><c-s><CR>  
157 " Use CTRL-S for saving, also in Insert mode  
158 nmap <C-S> :update<CR>  
159 vmap <C-S> <C-C>:update<CR>  
160 imap <C-S> <C-O>:update<CR>  
161   
162 " C++的编译和运行  
163 "map <F6> :call CompileRunGpp()<CR>  
164 "func! CompileRunGpp()  
165 "exec "w"  
166 "exec "!g++ % -o %<"  
167 "exec "! ./%<"  
168 "endfunc  
169 map <F10> :call RunGpp()<cr>    
170 func! RunGpp()    
171 exec "w"    
172 exec "! ./%<"    
173 endfunc    
174   
175 "vim plugin setting  
176   
177 "======================"  
178 set tags=tags  
179 set tags+=~/.vim/my-tags/tags  
180 set tags+=~/.vim/my-tags/stl-tags  
181 set tags+=~/.vim/my-tags/sys-tags  
182 set autochdir    
183 "Update ctags    
184 map <silent> <F8> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q<cr>   
185   
186 """"""""""""""""""""""""""""""  
187    " Tag list (ctags)  
188 """"""""""""""""""""""""""""""  
189 "if MySys() == "windows"                "设定windows系统中ctags程序的位置  
190 "   let Tlist_Ctags_Cmd = 'ctags'  
191 "elseif MySys() == "linux"              "设定Linux系统中ctags程序的位置  
192    let Tlist_Ctags_Cmd = '/home/sphinx/.vim/ctags-5.8/ctags'  
193 "endif  
194   
195 let Tlist_Show_One_File = 1            "不同时显示多个文件的tag,只显示当前文件的  
196 let Tlist_Exit_OnlyWindow = 1          "如果taglist窗口是最后一个窗口,则退出vim  
197 let Tlist_Use_Right_Window = 0         "在右侧窗口中显示taglist窗口  
198 let Tlist_OnlyWindow=1  
199   
200 "let Tlist_Use_Right_Window=0  
201 "let Tlist_Sort_Type='name'  
202 "let Tlist_Show_Menu=1  
203 "let Tlist_Max_Submenu_Items=10  
204 "let Tlist_Max_Tag_length=16     "20  
205 "let Tlist_Use_SingleClick=0  
206 "let Tlist_Auto_Open=0  
207 "let Tlist_Close_On_Select=0  
208 "let Tlist_File_Fold_Auto_Close=1  
209 "let Tlist_GainFocus_On_ToggleOpen=0  
210 "let Tlist_Process_File_Always=1  
211 "let Tlist_WinHeight=10  
212 "let Tlist_WinWidth=18  
213 "let Tlist_Use_Horiz_Window=0  
214   
215 let Tlist_Auto_Highlight_Tag = 1  
216 "let Tlist_Auto_Open = 1  
217 let Tlist_Auto_Update = 1  
218 let Tlist_Close_On_Select = 0  
219 let Tlist_Compact_Format = 0  
220 let Tlist_Display_Prototype = 0  
221 let Tlist_Display_Tag_Scope = 1  
222 let Tlist_Enable_Fold_Column = 0  
223 let Tlist_File_Fold_Auto_Close = 0  
224 let Tlist_GainFocus_On_ToggleOpen = 1  
225 let Tlist_Hightlight_Tag_On_BufEnter = 1  
226 let Tlist_Inc_Winwidth = 0  
227 let Tlist_Max_Submenu_Items = 1  
228 let Tlist_Max_Tag_Length = 30  
229 let Tlist_Process_File_Always = 0  
230 let Tlist_Show_Menu = 0  
231 let Tlist_Sort_Type = "order"  
232 let Tlist_Use_Horiz_Window = 0  
233 let Tlist_WinWidth = 31  
234   
235 map <F12> :TlistOpen<CR>  
236   
237 "OMNI  
238 "omnicppcoplete    
239 "-- omnicppcomplete setting --     
240 set completeopt=menu,menuone     
241 let OmniCpp_MayCompleteDot = 1     
242 " autocomplete with .     
243 let OmniCpp_MayCompleteArrow = 1     
244 " autocomplete with ->     
245 let OmniCpp_MayCompleteScope = 1     
246 " autocomplete with ::     
247 let OmniCpp_SelectFirstItem = 2     
248 " select first item (but don't insert)     
249 let OmniCpp_NamespaceSearch = 2     
250 " search namespaces in this and included files     
251 let OmniCpp_ShowPrototypeInAbbr = 1     
252 " show function prototype in popup window     
253 let OmniCpp_GlobalScopeSearch=1     
254 let OmniCpp_DisplayMode=1     
255 let OmniCpp_DefaultNamespaces=["std"]    
256 set nocp    
257 filetype plugin on    
258   
259 "WinManager  
260 let g:winManagerWindowLayout='FileExplorer|TagList'  
261 "let g:winManagerWindowLayout='FileExplorer|BufExplorer|TagList'  
262 let g:persistentBehaviour=0  
263 let g:winManagerWidth=20  
264 let g:defaultExplorer=1  
265 nmap wm :WMToggle<cr>  
266   
267 "QuickFix  
268 nmap <F6> :cn<cr>  
269 nmap <F7> :cp<cr>  
270   
271 "MiniBufExplorer  
272 "let g:miniBufExplMapWindowNavVim = 1  
273 "let g:miniBufExplMapWindowNavArrows = 1  
274 let g:miniBufExplModSelTarget = 1  
275 let g:miniBufExplorerMoreThanOne = 2  
276 let g:miniBufExplModSelTarget = 0  
277 let g:miniBufExplUseSingleClick = 1  
278 let g:miniBufExplMapWindowNavVim = 1  
279 let g:miniBufExplVSplit = 15    "25  
280 let g:miniBufExplSplitBelow=1  
281   
282 let g:bufExplorerSortBy = "name"  
283   
284 autocmd BufRead,BufNew :call UMiniBufExplorer  
285   
286 map <leader>u :TMiniBufExplorer<cr>  
287   
288   
289 "AutoClose  
290 "let g:AutoClosePairs = {'(': ')', '{': '}', '[': ']', '"': '"', "'": "'"}  
291 let g:AutoClosePairs = {'(': ')', '{': '}', '[': ']', '"': '"', "'": "'"}   
292 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""   
293 "   Maintainer:   
294 "   "       Geek SphinX  
295 "   "       topcodersphinx@gmail.com  
296 "   "  
297 "   "   Version:  
298 "   "       1.0 - Thu Nov  1 17:21:44 CST 2012  
299 "   "  
300 "   """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
301   
302 " Sets how many lines of history VIM has to remember  
303 " set history=1024  
304 "  
305 " " Auto syntax highlight  
306 " set syntax=on  
307 "  
308 " " Check file format  
309 " filetype on  
310 "  
311 " " Enable filetype plugins  
312 " filetype plugin on  
313 " filetype indent on  
314 "  
315 " " Sets non VI compatible mode  
316 " set nocompatible  
317 "  
318 " " Set to auto read when a file is changed from the outside  
319 " set autoread  
320 "  
321 " " With a map leader it's possible to do extra key combinations  
322 " " like <leader>w saves the current file  
323 " let mapleader = ","  
324 " let g:mapleader = ","  
325 "  
326 " " Fast saving  
327 " nmap <leader>w :w<cr>  
328 " nmap <leader>q :q<cr>  
329 "  
330 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
331 " " => VIM user interface  
332 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
333 " " Replace J, K  
334 " nmap J 5j  
335 " nmap K 5k  
336 "  
337 " " Ctrl+A to select all content in visual mode  
338 " nmap <silent> <C-a> ggvG$  
339 "  
340 " " Ctrl+C to copy  
341 " vnoremap <C-c> "+y  
342 "  
343 " " Ctrl+V to paste  
344 " nmap <silent> <C-v> "+p  
345 "  
346 " " Set 7 lines to the cursor - when moving vertically using j/k  
347 " set so=7  
348 "  
349 " " Turn on the Wild menu  
350 " set wildmenu  
351 "  
352 " " Ignore compiled files  
353 " set wildignore=*.o,*~,*.pyc  
354 "  
355 " "Always show current position  
356 " set ruler  
357 "  
358 " " Height of the command bar  
359 " set cmdheight=2  
360 "  
361 " " A buffer becomes hidden when it is abandoned  
362 " set hid  
363 "  
364 " " Configure backspace so it acts as it should act  
365 " set whichwrap+=<,>  
366 " set backspace=indent,eol,start  
367 "  
368 " " Ignore case when searching  
369 " set ignorecase  
370 "  
371 " " When searching try to be smart about cases   
372 " set smartcase  
373 "  
374 " " Highlight search results  
375 " set hlsearch  
376 "  
377 " " Makes search act like search in modern browsers  
378 " set incsearch  
379 "  
380 " " Don't redraw while executing macros (good performance config)  
381 " set lazyredraw  
382 "  
383 " " For regular expressions turn magic on  
384 " set magic  
385 "  
386 " " Show matching brackets when text indicator is over them  
387 " set showmatch  
388 "  
389 " " How many tenths of a second to blink when matching brackets  
390 " set mat=2  
391 "  
392 " " No annoying sound on errors set noerrorbells  
393 " set novisualbell  
394 " set t_vb=  
395 " set tm=500  
396 "  
397 " " Show line number  
398 " set number  
399 "  
400 " " Highlight over 80 columns  
401 " highlight OverLength ctermbg=red ctermfg=white guibg=#592929  
402 " match OverLength /\%81v.\+/  
403 "  
404 " " Show Tab symbol  
405 " set list  
406 " set listchars=tab:\|\ ,trail:.,extends:>,precedes:<  
407 "  
408 " " Switch windows  
409 " nnoremap <C-h> <C-w>h  
410 " nnoremap <C-l> <C-w>l  
411 " nnoremap <C-j> <C-w>j  
412 " nnoremap <C-k> <C-w>k  
413 "  
414 " " Move cursor in insert mode  
415 " inoremap <C-h> <C-o>h  
416 " inoremap <C-l> <C-o>l  
417 " inoremap <C-j> <C-o>j  
418 " inoremap <C-k> <C-o>k  
419 "  
420 "  
421 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
422 " " => Colors and Fonts  
423 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
424 " " Enable syntax highlighting  
425 " syntax enable  
426 "  
427 " "colorscheme desert  
428 " colorscheme molokai  
429 " set background=dark  
430 "  
431 " " Set extra options when running in GUI mode  
432 " if has("gui_running")  
433 "     set guioptions-=T  
434 "         set guioptions+=e  
435 "             set t_Co=256  
436 "                 set guitablabel=%M\ %t  
437 "                 endif  
438 "  
439 "                 " Set utf8 as standard encoding and en_US as the standard  
440 "                 language  
441 "                 set encoding=utf8  
442 "  
443 "                 " Use Unix as the standard file type  
444 "                 set ffs=unix,dos,mac  
445 "  
446 "                 " Use Inconsolata as the gui font  
447 "                 set guifont=Inconsolata\ 15  
448 "  
449 "                 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
450 " => Text, tab and indent related  
451 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
452 " " Use spaces instead of tabs  
453 " set expandtab  
454 "  
455 " " Be smart when using tabs ;)  
456 " set smarttab  
457 "  
458 " " 1 tab == 4 spaces  
459 " set shiftwidth=4  
460 " set tabstop=4  
461 "  
462 " " Linebreak on 500 characters  
463 " set lbr  
464 " set tw=500  
465 "  
466 " set ai "Auto indent  
467 " set si "Smart indent  
468 " set wrap "Wrap lines  
469 "  
470 "  
471 " """"""""""""""""""""""""""""""  
472 " " => Status line  
473 " """"""""""""""""""""""""""""""  
474 " " Always show the status line  
475 " set laststatus=2  
476 "  
477 " " Format the status line  
478 " "set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \  
479 " Line:\ %l  
480 "  
481 "  
482 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
483 " " => Mouse  
484 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
485 " set mouse=a  
486 " set selection=exclusive  
487 " set selectmode=mouse,key  
488 "  
489 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
490 " " => Plugins  
491 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
View Code

 

posted @ 2018-03-15 08:53  刘-皇叔  阅读(329)  评论(0)    收藏  举报