Chinaunix首页 | 论坛 | 博客
  • 博客访问: 899806
  • 博文数量: 119
  • 博客积分: 2493
  • 博客等级: 大尉
  • 技术积分: 2363
  • 用 户 组: 普通用户
  • 注册时间: 2012-06-03 14:00
文章分类

全部博文(119)

文章存档

2013年(19)

2012年(100)

分类:

2012-12-09 09:08:32

这个是我当时用的时候在网上找的比较全的一个配置文件,这里贴出来和大家分享下~~~~

  1. "==============================================================================
  2. " => General
  3. "==============================================================================
  4. set nocompatible
  5. ":命令显示历史
  6. set history=500
  7.  
  8. "去掉gvim菜单栏
  9. "set go-=m
  10. "去掉gvim工具栏
  11. set go-=T
  12.  
  13. "normal模式下取消输入法
  14.  InsertLeave *    set imdisable
  15.  InsertEnter *    set noimdisable
  16.  
  17. "开启插件和缩进
  18. filetype plugin indent on
  19.  
  20. set autoread
  21. set mouse=a
  22. set mousehide
  23.  
  24. "设置无响铃
  25. set novisualbell
  26. "字体设定
  27. if has("win32")
  28.     set guifont=黑体:h13:cANSI    
  29. elseif has("unix")    
  30.     set guifont=Andale\ Mono\ 12
  31. endif
  32.  
  33. "设置 mapleader = ,
  34. let g:mapleader = ","
  35.  
  36. "快速存储和关闭
  37. nmap w :w!
  38. nmap q :q
  39. nmap qq :q!
  40. nmap wq :wq
  41. "打开最近文件
  42. map <leader>m :MRU<cr>
  43.  
  44. map <leader>ax :!chmod a+x %<cr><cr>
  45.  
  46. "Favorite filetypes
  47. if has("win32")
  48.     set ffs=dos,unix,mac
  49. elseif has("unix")
  50.     set ffs=unix,dos,mac
  51. endif
  52.  
  53. "编码设定Encoding
  54. set fileencoding=utf-8
  55. set fileencodings=utf-8,gbk,utf-16,big5
  56.  
  57. set langmenu=zh_CN.UTF-8
  58. source $VIMRUNTIME/delmenu.vim
  59. source $VIMRUNTIME/menu.vim
  60. language messages zh_CN.UTF-8
  61. "==============================================================================
  62. " => fast edit vimrc 快速编辑vimrc
  63. "==============================================================================
  64. if has("win32")
  65.     "Fast editing of _vimrc
  66.     map <leader>e : $VIM/_vimrc<cr>
  67.     "reload _vimrc
  68.     map s :source $VIM/_vimrc
  69.     "When .vimrc is edited, reload it
  70.      bufwritepost vimrc source /$VIM/_vimrc
  71. elseif has("unix")
  72.     "Fast editing of .vimrc
  73.     map e :e! $HOME/.vimrc
  74.     "reload _vimrc
  75.     map <leader>s :source $HOME/.vimrc<cr>
  76.     "When .vimrc is edited, reload it
  77.     autocmd! bufwritepost vimrc source ~/.vimrc
  78. endif
  79. "==============================================================================
  80. " => Serach
  81. "==============================================================================
  82. "忽略大小写检索
  83. set ignorecase
  84. "输入检索时动态变化
  85. set incsearch
  86. "检索高亮
  87. set hlsearch
  88. "==============================================================================
  89. " => Colors and Fonts
  90. "==============================================================================
  91. "语法高亮 Enable syntax highlight
  92. syntax enable
  93.  
  94. if has("gui_running")
  95.     if has("win32")
  96.         "Auto Maximize when gvim startup in Window system.
  97.         au GUIEnter * simalt ~x
  98.     endif
  99. endif
  100.  
  101. "主题颜色设定
  102. "colorscheme torte
  103. "colorscheme molokai
  104. "colorscheme lettuce
  105. "colorscheme navajo-night
  106.  
  107. autocmd BufEnter * :syntax sync fromstart
  108.  
  109. "高亮当前行 Highlight current
  110. set cursorline
  111.  
  112. "Display tab as >----,and trail spaces of the line as -
  113. "set listchars=tab:>-,trail:-
  114. "==============================================================================
  115. " VIM userinterface
  116. "==============================================================================
  117.  
  118. "Turn on WiLd menu
  119. set wildmenu
  120. set wildignore=*.bak,*.o,*.e,*~
  121.  
  122. "Always show current position
  123. set ruler
  124.  
  125. "The commandbar is 2 high
  126. set cmdheight=2
  127. set showcmd
  128.  
  129. "Show line number
  130. set number
  131.  
  132. "Do not redraw, when running macros.. lazyredraw
  133. set lazyredraw
  134.  
  135. "Change buffer - without saving
  136. set hidden
  137.  
  138. "Set backspace
  139. set backspace=eol,start,indent
  140.  
  141. "Backspace and cursor keys wrap to
  142. set whichwrap+=<,>,[,],h,l
  143.  
  144. " 光标移动到buffer的顶部和底部时保持三行差距
  145. set scrolloff=3
  146. "==============================================================================
  147. " => Status line
  148. "==============================================================================
  149.  
  150. function! CurDir()
  151.     let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
  152.     return curdir
  153. endfunction
  154.  
  155. "状态栏显示参数 Format the status line
  156. set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c\ \ \ %p%%
  157. set laststatus=2
  158. "==============================================================================
  159. " Tab configuration
  160. "==============================================================================
  161. "译注:将当前内容在新标签中打开
  162. map <leader>tn :tabnew %<cr>
  163. "译注:打开空白新标签
  164. map te :tabedit
  165. "译注:关闭当前标签
  166. map <leader>tc :tabclose<cr>
  167. "译注:移动当前标签,使用方法为
  168. map tm :tabmove
  169. "让 gvim 支持 Alt+n 来切换标签页
  170. autocmd VimEnter * call BufPos_Initialize()
  171. "==============================================================================
  172. " for lookupfile.vim
  173. "==============================================================================
  174. let g:LookupFile_MinPatLength = 2 "最少输入2个字符才开始查找
  175. let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串
  176. let g:LookupFile_PreservePatternHistory = 1 "保存查找历史
  177. let g:LookupFile_AlwaysAcceptFirst = 1 "回车打开第一个匹配项目
  178. let g:LookupFile_AllowNewFiles = 0 "不允许创建不存在的文件
  179. if filereadable("./tags") "设置tag文件的名字
  180.     let g:LookupFile_TagExpr = '"./tags"'
  181. endif
  182. "==============================================================================
  183. " moving around
  184. "==============================================================================
  185. "window move
  186. map j
  187. map k
  188. map h
  189. map l
  190. "nomal模式下tab来切换窗口
  191. nmap <tab> <C-W>w
  192. ",v 打开水平窗口
  193. map v :vsplit
  194.  
  195. "buffer Switch
  196. map <A-j> :bp<cr>
  197. map <A-k> :bn<cr>
  198. "==============================================================================
  199. " 缩进设置 Indent
  200. "==============================================================================
  201. "Auto indent
  202. set autoindent
  203.  
  204. "Smart indent
  205. set smartindent
  206.  
  207. "C-style indenting
  208. set cindent
  209.  
  210. "Wrap lines
  211. set wrap
  212. "==============================================================================
  213. " => Folding
  214. "==============================================================================
  215. "Enable folding, I find it very useful
  216. set foldmethod=syntax
  217. set nofoldenable
  218. "==============================================================================
  219. " => Files and backups
  220. "==============================================================================
  221. "Turn backup off
  222. set nobackup
  223. set nowritebackup
  224. set noswapfile
  225. "==============================================================================
  226. " => Text options
  227. "==============================================================================
  228. "四字符缩进
  229. set shiftwidth=4
  230. set softtabstop=4
  231. set tabstop=4
  232. set noexpandtab
  233.  
  234. set ambiwidth=double
  235. "自动拆分行
  236. set linebreak
  237.  
  238. " txt file auto insert linebreak after 78 char
  239. "au FileType txt set tw=78 fo+=Mm
  240.  
  241. " C file
  242. "au FileType c,cpp setl sw=8 ts=8
  243. "对C,Cpp和perl文件保存并调试
  244. au FileType c nmap tt :w:!gcc -o %:r %
  245. au FileType cpp nmap tt :w:!g++ -o %:r %
  246. au FileType perl nmap tt :w:!perl %
  247. au FileType tex nmap tt :w:!latex %:!dvipdfm %:s/.tex/.dvi/:!gnome-open %:s/.tex/.pdf/
  248. "cmake 自动补全
  249. au FileType cmake set dict+=$HOME/.vim/cmake.txt
  250. "==============================================================================
  251. "for latex-suit.vim
  252. "==============================================================================
  253. au FileType tex so ~/.vim/ftplugin/tex_latexSuite.vim
  254. if has("win32")
  255.     set shellslash
  256. endif
  257. "filetype indent on
  258. let g:tex_flavor = 'latex'
  259. set grepprg=grep\ -nH\ $*
  260. let g:Tex_CompileRule_dvi = 'latex --interaction=nonstopmode $*'
  261. let g:Tex_CompileRule_ps = 'dvips -Ppdf -o $*.ps $*.dvi'
  262. let g:Tex_CompileRule_pdf = 'ps2pdf $*.ps'
  263. "==============================================================================
  264. "some key map
  265. "==============================================================================
  266. ",cd Switch to current dir
  267. map <leader>cd :cd %:p:h<cr>:set tags+=tags<cr>:cs add cscope.out<cr>
  268. "F4 保存并make
  269. map :w!:make
  270. "清除高亮显示
  271. map <F2> :nohl<cr>
  272. "Super paste 可在不同文件的文本框中复制粘贴
  273. "插入模式下C-a全局选中
  274. inoremap <C-a> <esc>ggVG
  275. "可视模式下对选中模块进行复制C-c或剪切C-x
  276. vmap "+y
  277. vmap <C-x> "+x
  278. "插入模式下C-v粘贴
  279. inoremap <C-v> <esc>:set paste<cr>mui<C-R>+<esc>mv'uV'v=:set nopaste<cr>
  280. "==============================================================================
  281. "for a.vim
  282. "==============================================================================
  283. ",a和,aa C/C++源文件和头文件切换
  284. map <leader>a :A<cr>
  285. map <leader>aa :A<cr>
  286. ",as 在竖直方向新窗口中打开对应源文件或头文件
  287. map as :AS
  288. ",av 在水平方向新窗口中打开对应源文件或头文件
  289. map <leader>av :AV<cr>
  290. ",at 在新标签页中打开对应源文件或头文件
  291. map at :AT
  292. "==============================================================================
  293. "for NERD_commenter.vim 智能注释
  294. "==============================================================================
  295. "空格键添加去除注释
  296. "map <space> <leader>ci
  297. map <space> <plug>NERDCommenterInvert
  298. let NERDCreateDefaultMappings=0
  299. "==============================================================================
  300. "for NERD_tree.vim
  301. "==============================================================================
  302. map :NERDTreeToggle
  303. let NERDChristmasTree=1
  304. let NERDTreeAutoCenter=1
  305. let NERDTreeShowLineNumbers=1
  306. let NERDTreeWinPos='right'
  307. let NERDTreeWinSize=30
  308. "==============================================================================
  309. "for taglist.vim
  310. "==============================================================================
  311. map <F10> :TlistToggle<cr>
  312. let Tlist_Enable_Fold_Column = 0
  313. let Tlist_WinWidth = 25
  314. let Tlist_Show_One_File = 1
  315. let g:Tb_ForceSyntaxEnable = 1
  316. "==============================================================================
  317. "for OmniCppComplete.vim 补全插件
  318. "==============================================================================
  319. set completeopt=menu
  320. let OmniCpp_ShowPrototypeInAbbr = 1
  321. let OmniCpp_DefaultNamespaces = ["std"] " 逗号分割的字符串
  322. let OmniCpp_MayCompleteScope = 1
  323. let OmniCpp_ShowPrototypeInAbbr = 1
  324. let OmniCpp_SelectFirstItem = 2
  325. " c-j自动补全,当补全菜单打开时,c-j,k上下选择
  326. "imap <expr> <c-j> pumvisible()?"\":"\"
  327. "imap pumvisible()?"\<C-P>":"\<esc>"
  328. " f:文件名补全,l:行补全,d:字典补全,]:tag补全
  329. "imap
  330. "imap <C-F> <C-X><C-F>
  331. "imap
  332. "imap <C-L> <C-X><C-L>
  333. "==============================================================================
  334. "for DoxygenToolkit.vim doxygen注释插件
  335. "==============================================================================
  336. let g:DoxygenToolkit_authorName = "Xu Wenzhang(xwz), carl.xwz@gmail.com, http://xuwenzhang.org"
  337. let g:DoxygenToolkit_versionString = "1.0"
  338. "let s:licenseTag = "Copyright(C)\"
  339. "let s:licenseTag = s:licenseTag . "For free\<enter>"
  340. "let s:licenseTag = s:licenseTag . "All right reserved\"
  341. "let g:DoxygenToolkit_licenseTag = s:licenseTag
  342. let g:DoxygenToolkit_briefTag_funcName="yes"
  343. let g:DoxygenToolkit_briefTag_className="yes"
  344. let g:doxygen_enhanced_color=1
  345.  
  346. ",<space> 用doxygen模式来注释
  347. map <leader><space> :Dox<cr>
  348. ",hd 加入doxygen注释文件头
  349. map hd gg:DoxLic:DoxAuthor
  350. "==============================================================================
  351. "for c-support
  352. "==============================================================================
  353. "c-support时间格式设定
  354. let g:C_FormatDate = '%F'
  355. let g:C_FormatTime = '%H:%M'
  356. let g:C_FormatYear             = 'year %Y'
  357. "==============================================================================
  358. "for vimwiki
  359. "==============================================================================
  360. let g:vimwiki_use_mouse = 1
  361. "设置vimwiki目录
  362. let g:vimwiki_list = [{'path': '~/vimwiki/wiki/', 'path_html': '~/vimwiki/html/'}]
  363. "au filetype vimwiki map <leader>tt <Plug>VimwikiToggleListItem
  364. "打开当前链接
  365. au filetype vimwiki map wf VimwikiFollowLink
  366. "在新窗口中打开当前链接
  367. au filetype vimwiki map <Leader>we <Plug>VimwikiSplitLink
  368. "在新标签中打开日志wiki,即以当天日期命名的wiki
  369. au filetype vimwiki map dt VimwikiTabMakeDiaryNote
  370. "保存当前文件,将当前vimwiki文件转为html,并且打开当前网页
  371. au filetype vimwiki map <leader>tt :w<cr>:Vimwiki2HTML<cr>:!google-chrome %:p:s?/wiki/?/html/?:s?\.wiki?\.html?<cr><cr>
  372. "保存所有文件,将所有vimwiki文件转为html,并且打开当前网页
  373. au filetype vimwiki map ta :wa:VimwikiAll2HTML:!google-chrome %:p:s?/wiki/?/html/?:s?\.wiki?\.html?
  374. "==============================================================================
  375. "for ScrollColor.vim
  376. "==============================================================================
  377. "浏览主题颜色
  378. map :NEXTCOLOR
  379. map :PREVCOLOR
  380. "==============================================================================
  381. "for ctags
  382. "==============================================================================
  383. map <F12> :call Do_CsTag()<cr>
  384.  Do_CsTag()
  385.     let dir = getcwd()
  386.  
  387.     "先删除已有的tags和cscope文件,如果存在且无法删除,则报错。
  388.     if ( DeleteFile(dir, "tags") )
  389.         return
  390.     endif
  391.     if ( DeleteFile(dir, "cscope.files") )
  392.         return
  393.     endif
  394.     if ( DeleteFile(dir, "cscope.out") )
  395.         return
  396.     endif
  397.  
  398.     if(executable('ctags'))
  399.         " execute "!g++ -E % -o tmpcpp -I../eg"
  400.          execute "!ctags -R --c++-kinds=+p --fields=+ialS --extra=+q --language-force=C++ ."
  401.         "silent! execute "!unlink tmpcpp"
  402.     endif
  403.     if(executable('cscope') && has("cscope") )
  404.         if(has("win32"))
  405.             silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
  406.         else
  407.             silent! execute "!find . -iname '*.[ch]' -o -name '*.cpp' > cscope.files"
  408.         endif
  409.         silent! execute "!cscope -b"
  410.         execute "normal :"
  411.         if filereadable("cscope.out")
  412.             execute "cs add cscope.out"
  413.         endif
  414.     endif
  415.     " 刷新屏幕
  416.     execute "redr!"
  417. endfunction
  418.  
  419.  DeleteFile(dir, filename)
  420.     if filereadable(a:filename)
  421.         if (has("win32"))
  422.             let ret = delete(a:dir."\\".a:filename)
  423.         else
  424.             let ret = delete("./".a:filename)
  425.         endif
  426.         if (ret != 0)
  427.             echohl WarningMsg | echo "Failed to delete ".a:filename | echohl None
  428.             return 1
  429.         else
  430.             return 0
  431.         endif
  432.     endif
  433.     return 0
  434. endfunction
  435.  
  436. set tags=tags,../tags
  437.  
  438.  Add_tags()
  439. "Add tags file
  440. if has("win32")
  441.     set tags+=
  442. elseif has("unix")
  443.     set tags+=/usr/include/tags,/usr/src/tags
  444. endif
  445. "Add cscope file
  446.     if has("cscope") && has("unix")
  447.         if filereadable("/usr/src/cscope.out")
  448.             cs add /usr/src/cscope.out /usr/src/
  449.         endif
  450.  
  451.         if filereadable("/usr/include/cscope.out")
  452.             cs add /usr/include/cscope.out /usr/include/
  453.         endif
  454.     endif
  455. endfunction
  456.  
  457. " cscope 绑定
  458. if has("cscope")
  459.     set csto=1
  460.     set cst
  461.     set nocsverb
  462.     if filereadable("cscope.out")
  463.         cs add cscope.out
  464.     endif
  465.     " s: C语言符号 g: 定义 d: 这个函数调用的函数 c: 调用这个函数的函数
  466.     " t: 文本 e: egrep模式 f: 文件 i: include本文件的文件
  467.     nmap ss :cs find s =expand("<cword>")
  468.     nmap sg :cs find g =expand("<cword>")
  469.     nmap sc :cs find c =expand("<cword>")
  470.     nmap st :cs find t =expand("<cword>")
  471.     nmap se :cs find e =expand("<cword>")
  472.     nmap sf :cs find f =expand("<cfile>")
  473.     nmap si :cs find i ^=expand("<cfile>")$
  474.     nmap sd :cs find d =expand("<cword>")
  475. endif
  476. "用A-Num来切换标签
  477.  BufPos_ActivateBuffer(num)
  478.     let l:count = 1
  479.     for i in range(1, bufnr("$"))
  480.         if buflisted(i) && getbufvar(i, "&modifiable")
  481.             if l:count == a:num
  482.                 exe "buffer " . i
  483.                 return
  484.             "endif
  485.             let l:count = l:count + 1
  486.         endif
  487.     endfor
  488.     echo "No buffer!"
  489. endfunction
  490. function! BufPos_Initialize()
  491.     for i in range(0, 9)
  492.         exe "map <M-" . i . "> " . i . "gt"
  493.     endfor
  494. endfunction
  495.  
  496. "进入文件所在目录然后
  497. cd %:p:h
  498. "set tags+=tags
  499. "cs add cscope.out

阅读(14474) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~