我的vim配置(一)

废话少说,先上图。。。。

 

 

 

 

贴vim配置文件。位置在~/.vimrc

 

  1 call pathogen#infect()
  2 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  3 " 一般设定 
  4 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  5 " 显示中文帮助
  6 source ~/.vim/macros/gdb_mappings.vim
  7 "nmap <S-F7>  :call SToggleGDB()<cr>
  8  "nmap <F7>  :call <SID>Toggle()<CR>
  9 if version >= 603
 10 
 11     set helplang=cn
 12 
 13     set encoding=utf-8
 14 
 15 endif
 16 colorscheme slate
 17 set guifont=Courier_New:h10:cANSI  
 18 " 设定默认解码 
 19 set fenc=utf-8 
 20 set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936 
 21 
 22 " 不要使用vi的键盘模式,而是vim自己的 
 23 set nocompatible 
 24 
 25 " history文件中需要记录的行数 
 26 set history=100 
 27 
 28 " 在处理未保存或只读文件的时候,弹出确认 
 29 set confirm 
 30 
 31 " 与windows共享剪贴板 
 32 set clipboard+=unnamed 
 33 
 34 " 侦测文件类型 
 35 filetype on 
 36 
 37 set cursorline              " 突出显示当前行
 38 
 39 " 载入文件类型插件 
 40 filetype plugin indent on
 41 set completeopt=longest,menu
 42 set nocp
 43 filetype plugin on 
 44 
 45 " 为特定文件类型载入相关缩进文件 
 46 filetype indent on 
 47 
 48 " 保存全局变量 
 49 set viminfo+=! 
 50 
 51 " 带有如下符号的单词不要被换行分割 
 52 set iskeyword+=_,$,@,%,#,- 
 53 
 54 " 语法高亮 
 55 syntax on 
 56 
 57 " 高亮字符,让其不受100列限制 
 58 :highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white 
 59 :match OverLength '\%101v.*' 
 60 
 61 " 状态行颜色 
 62 highlight StatusLine guifg=SlateBlue guibg=Yellow 
 63 highlight StatusLineNC guifg=SlateBlue guibg=White 
 64 
 65 
 66 " 映射全选+复制 ctrl+a
 67 map <C-A> ggVGY
 68 map! <C-A> <Esc>ggVGY
 69 map <F12> gg=G
 70 " 选中状态下 Ctrl+c 复制
 71 vmap <C-c> "+y
 72 
 73 
 74 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 75 " 文件设置 
 76 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
 77 " 不要备份文件(根据自己需要取舍) 
 78 set nobackup 
 79 
 80 " 不要生成swap文件,当buffer被丢弃的时候隐藏它 
 81 setlocal noswapfile 
 82 set bufhidden=hide 
 83 
 84 " 字符间插入的像素行数目 
 85 set linespace=0 
 86 
 87 " 增强模式中的命令行自动完成操作 
 88 set wildmenu 
 89 
 90 " 在状态行上显示光标所在位置的行号和列号 
 91 set ruler 
 92 set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%) 
 93 
 94 " 命令行(在状态行下)的高度,默认为1,这里是2 
 95 set cmdheight=2 
 96 
 97 " 使回格键(backspace)正常处理indent, eol, start等 
 98 set backspace=2 
 99 
100 " 允许backspace和光标键跨越行边界 
101 set whichwrap+=<,>,h,l 
102 
103 " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位) 
104 set mouse=a 
105 set selection=exclusive 
106 set selectmode=mouse,key 
107 
108 "自动添加作者信息
109 map <F4> ms:call TitleDet()<cr>'s
110 
111 function AddTitle()
112     call append(0,"/*======================================================================")
113     call append(1," *           Author :   kevin")
114     call append(2," *         Filename :   ".expand("%d:t"))
115     call append(3," *       Creat time :   ".strftime("%Y-%m-%d %H:%M"))
116     call append(4," *      Description :")
117     call append(5,"========================================================================*/")
118     call append( 6,"#include <iostream>")
119     call append( 7,"#include <algorithm>")
120     call append( 8,"#include <cstdio>")
121     call append( 9,"#include <cstring>")
122     call append(10,"#include <queue>")
123     call append(11,"#include <cmath>")
124     call append(12,"#define M ")
125     call append(13,"using namespace std;")
126     call append(14,"int main(int argc,char *argv[])")
127     call append(15,"{")
128     call append(16,"    return 0;")
129     call append(17,"}")
130 
131     echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
132 
133 endf
134 
135 "更新最近修改时间和文件名
136 
137 normal m'
138 
139 "execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
140 
141 normal "
142 
143 normal mk
144 
145 "execute '/# *Filename:/s@:.*$@\=":\t\t".expand("%:t")@'
146 
147 execute "noh"
148 
149 normal 'k
150 
151 "echohl WarningMsg | echo "\n" | echo "Successful in updating the copy right."| echohl None
152 
153 "endfunction
154 
155  
156 
157 "判断前10行代码里面,是否有Last modified这个单词,
158 
159 "如果没有的话,代表没有添加过作者信息,需要新添加;
160 
161 "如果有的话,那么只需要更新即可
162 
163 function TitleDet()
164 
165     let n=1
166 
167     while n < 10
168 
169         let line = getline(n)
170 
171         if line =~'^\#\s*\S*Last\smodified:\S*.*$'
172 
173             call UpdateTitle()
174 
175             return
176 
177         endif
178 
179         let n = n + 1
180 
181     endwhile
182 
183     call AddTitle()
184 
185 endfunction
186 
187 
188 " 设置NerdTree
189 map <F3> :NERDTreeMirror<CR>
190 map <F3> :NERDTreeToggle<CR>
191 
192 set tags=/home/kevin/file/tags
193 
194 "list{
195     let Tlist_Auto_Open = 1
196     let Tlist_Show_One_File = 1           
197     let Tlist_Use_Right_Window = 0
198     let Tlist_Exit_OnlyWindow = 1                   
199     let Tlist_GainFocus_On_ToggleOpen = 1  
200     let Tlist_Ctags_Cmd='/usr/bin/ctags'    
201     map <F2> :Tlist<CR>   
202     "}
203 
204 
205 
206 " 启动的时候不显示那个援助索马里儿童的提示 
207 set shortmess=atI 
208 
209 " 通过使用: commands命令,告诉我们文件的哪一行被改变过 
210 set report=0 
211 
212 " 不让vim发出讨厌的滴滴声 
213 set noerrorbells 
214 
215 " 在被分割的窗口间显示空白,便于阅读 
216 "set fillchars=vert:\ ,stl:\ ,stlnc:\ 
217 "set fillchars=vert:| ,stl:| ,stlnc:|
218 
219 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
220 " 搜索和匹配 
221 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
222 " 高亮显示匹配的括号 
223 set showmatch 
224 
225 " 匹配括号高亮的时间(单位是十分之一秒) 
226 set matchtime=5 
227 
228 " 在搜索的时候忽略大小写 
229 set ignorecase 
230 
231 " 不要高亮被搜索的句子(phrases) 
232 set nohlsearch 
233 
234 "代码补全
235 set completeopt=preview,menu
236 
237 " 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索) 
238 set incsearch 
239 
240 " 输入:set list命令是应该显示些啥? 
241 set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$ 
242 
243 " 光标移动到buffer的顶部和底部时保持3行距离 
244 set scrolloff=3 
245 
246 " 不要闪烁 
247 set novisualbell 
248 
249 " 我的状态行显示的内容(包括文件类型和解码) 
250 set statusline=%F%m%r%h%w\[POS=%l,%v][%p%%]\%{strftime(\"%d/%m/%y\ -\ %H:%M\")} 
251 
252 " 总是显示状态行 
253 set laststatus=2 
254 
255 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
256 " 文本格式和排版 
257 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
258 " 自动格式化 
259 set formatoptions=tcrqn 
260 
261 " 继承前一行的缩进方式,特别适用于多行注释 
262 set autoindent 
263 
264 " 为C程序提供自动缩进 
265 set smartindent 
266 
267 " 使用C样式的缩进 
268 set cindent 
269 
270 " 制表符为4 
271 set tabstop=4 
272 
273 " 统一缩进为4 
274 set softtabstop=4 
275 set shiftwidth=4 
276 
277 " 不要用空格代替制表符 
278 set noexpandtab 
279 
280 " 不要换行 
281 set nowrap 
282 
283 " 在行和段开始处使用制表符 
284 set smarttab 
285 
286 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
287 " CTags的设定 
288 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
289 " 按照名称排序 
290 let Tlist_Sort_Type = "name" 
291 
292 " 在右侧显示窗口 
293 "let Tlist_Use_Right_Window = 1 
294 
295 " 压缩方式 
296 "let Tlist_Compart_Format = 1 
297 
298 " 如果只有一个buffer,kill窗口也kill掉buffer 
299 let Tlist_Exist_OnlyWindow = 1 
300 
301 " 不要关闭其他文件的tags 
302 let Tlist_File_Fold_Auto_Close = 0 
303 
304 " 不要显示折叠树 
305 let Tlist_Enable_Fold_Column = 0 
306 
307 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
308 " Autocommands 
309 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
310 " 只在下列文件类型被侦测到的时候显示行号,普通文本文件不显示 
311 
312 if has("autocmd") 
313 autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number 
314 autocmd FileType xml,html vmap <C-o> <ESC>'<i<!--<ESC>o<ESC>'>o--> 
315 autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o 
316 autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100 
317 autocmd Filetype html,xml,xsl source $VIMRUNTIME/plugin/closetag.vim 
318 autocmd BufReadPost * 
319 \ if line("'\"") > 0 && line("'\"") <= line("$") | 
320 \ exe " normal g`\"" | 
321 \ endif 
322 endif "has("autocmd") 
323 
324 "C,C++ 按F5编译运行
325 
326 map <F5> :call CompileRunGcc()<CR>
327 
328 func! CompileRunGcc()
329 
330     exec "w"
331 
332     if &filetype == 'c'
333 
334         exec "!g++ % -o %<"
335 
336         exec "! ./%<"
337 
338     elseif &filetype == 'cpp'
339 
340         exec "!g++ % -o %<"
341 
342         exec "! ./%<"
343 
344     elseif &filetype == 'java' 
345 
346         exec "!javac %" 
347 
348         exec "!java %<"
349 
350     elseif &filetype == 'sh'
351 
352         :!./%
353 
354     endif
355 
356 endfunc
357 
358 "C,C++的调试
359 
360 map <F8> :call Rungdb()<CR>
361 
362 func! Rungdb()
363 
364     exec "w"
365 
366     exec "!g++ % -g -o %<"
367 
368     exec "!gdb ./%<"
369 
370 endfunc
371 
372 " 能够漂亮地显示.NFO文件 
373 set encoding=utf-8 
374 function! SetFileEncodings(encodings) 
375 let b:myfileencodingsbak=&fileencodings 
376 let &fileencodings=a:encodings 
377 endfunction 
378 function! RestoreFileEncodings() 
379 let &fileencodings=b:myfileencodingsbak 
380 unlet b:myfileencodingsbak 
381 endfunction 
382 
383 au BufReadPre *.nfo call SetFileEncodings('cp437')|set ambiwidth=single au BufReadPost *.nfo call RestoreFileEncodings() 
384 
385 " 高亮显示普通txt文件(需要txt.vim脚本) 
386 au BufRead,BufNewFile * setfiletype txt 
387 
388 " 用空格键来开关折叠 
389 set foldenable 
390 "set foldmethod=manual 
391 set foldmethod=syntax " 设置实用语法方式折叠 
392 nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc':'zo')<CR> 
393 set foldnestmax=2   " 设置最大折叠深度
394 
395 " minibufexpl插件的一般设置 
396 let g:miniBufExplMapWindowNavVim = 1 
397 let g:miniBufExplMapWindowNavArrows = 1 
398 let g:miniBufExplMapCTabSwitchBufs = 1 
399 let g:miniBufExplModSelTarget = 1
400 let g:neocomplcache_enable_at_startup = 1 "自动补全插件自动启动
401 "powerline{ 
402  set guifont=PowerlineSymbols\ for\ Powerline
403  set nocompatible
404  set t_Co=256
405  set laststatus=2
406  set encoding=utf-8
407  let g:Powerline_symbols = 'unicode'
408  "}
409 
410 
411 "256 color
412 "let t_Co=256
413 "set nocompatible
414 "set laststatus=2
415 "set encoding=utf-8
416 "choose theme
417 "let g:Powerline_symbols = 'unicode'
418 
419 
420 
421 inoremap ( ()<Esc>i
422 inoremap [ []<Esc>i
423 inoremap { {<CR>}<Esc>O
424 autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR>
425 inoremap ) <c-r>=ClosePair(')')<CR>
426 inoremap ] <c-r>=ClosePair(']')<CR>
427 inoremap } <c-r>=CloseBracket()<CR>
428 inoremap " <c-r>=QuoteDelim('"')<CR>
429 inoremap ' <c-r>=QuoteDelim("'")<CR>
430 
431 function ClosePair(char)
432  if getline('.')[col('.') - 1] == a:char
433  return "\<Right>"
434  else
435  return a:char
436  endif
437 endf
438 
439 function CloseBracket()
440  if match(getline(line('.') + 1), '\s*}') < 0
441  return "\<CR>}"
442  else
443  return "\<Esc>j0f}a"
444  endif
445 endf
446 
447 function QuoteDelim(char)
448  let line = getline('.')
449  let col = col('.')
450  if line[col - 2] == "\\"
451  "Inserting a quoted quotation mark into the string
452  return a:char
453  elseif line[col - 1] == a:char
454  "Escaping out of the string
455  return "\<Right>"
456  else
457  "Starting a string
458  return a:char.a:char."\<Esc>i"
459  endif
460 endf
461 
462 "设定是否使用quickfix窗口来显示cscope结果{
463 :set cscopequickfix=s-,c-,d-,i-,t-,e-
464 "}
465 
466 if filereadable("Makefile") || filereadable("makefile")
467         set makeprg=make
468 else
469         set makeprg=g++\ %\ -Wall\ -g
470 endif
471 
472 
473 
474 " 显示tab和空格
475 set list
476 " 设置tab和空格样式
477 set lcs=tab:\¦\ ,nbsp:%,trail:-
478 " 设定行首tab为灰色
479 highlight LeaderTab guifg=#666666
480 " 匹配行首tab
481 match LeaderTab /^\t/

 

 

先到这,有了配置文件,不怕更新系统把/home下文件改变了。

posted @ 2014-04-25 22:12  ZeroCode_1337  阅读(345)  评论(0编辑  收藏  举报