分享

打造适合自己的VIM设置

 紫火神兵 2013-01-13

经过3天的煎熬,找各种资料终于弄了个基本的符合自己vim配置。

 

这篇文章以后会不定时更新。

 

用到的插件:

Java代码  收藏代码
  1. a.vim    //头文件和编程文件之间切换  
  2. bufexplorer.vim      //文件浏览器,基本不用  
  3. color_sample_pack.vim   //各种颜色主题  
  4. csExplorer.vim                //  
  5. DoxygenToolkit.vim         //个性文本生成工具,知道大概干什么,以后再说  
  6. genutils.vim   
  7. list  
  8. lookupfile.vim                 //查找文件插件  
  9. mark.vim                        //标记高亮显示  
  10. minibufexpl.vim              //很好用的打开文件显示浏览器  
  11. NERD_commenter.vim   //注释插件  
  12. NERD_tree.vim  
  13. project.vim                    //工程目录插件  
  14. ShowFunc.vim               //显示函数插件,还没怎么用  
  15. taglist.vim                     //前提是安装了ctags,此插件才好用,Exburant ctags  
  16. winfileexplorer.vim        //winmanager里的,winmanager可以控制taglist和bufexplorer的显示。  
  17. winmanager.vim  
  18. wintagexplorer.vim  

 

vimrc文件:

 

 

Java代码  收藏代码
  1. "display the cursor  
  2. "set ruler  
  3. set nocp  
  4. filetype plugin on  
  5.   
  6. " detect the filetype  
  7. this sentence eq   filetype on, filetype plugin on, filetype indent on  
  8. filetype plugin indent on  
  9. set nocompatible  
  10.   
  11. set foldmethod=syntax  
  12.   
  13. "set color display  
  14. set t_Co=256  
  15.   
  16.   
  17. "Set mapleader  
  18. "when use just in normal mode type ,ee   
  19. let mapleader = ","  
  20.   
  21. "Fast reloading of the .vimrc  
  22. map <silent> <leader>ss :source ~/.vimrc<cr>  
  23. "Fast editing of .vimrc  
  24. map <silent> <leader>ee :e ~/.vimrc<cr>  
  25. "When .vimrc is edited, reload it  
  26. autocmd! bufwritepost .vimrc source ~/.vimrc  
  27.   
  28. """"""""""""""""""""""""""""  
  29. "     MiniBufferExplorer   "  
  30. """"""""""""""""""""""""""""  
  31. let g:miniBufExplMapWindowNavVim=1  
  32. let g:miniBufExplMapWindowNavArrows=1  
  33. let g:miniBufExplMapCTabSwitchBufs=1  
  34. "let g:miniBufExplModSelTarget=1   
  35.   
  36.   
  37. "进行Taglist的设置  
  38. "TlistUpdate可以更新tags  
  39. map <F3> :silent! Tlist<CR>  
  40. "按下F3就可以呼出了  
  41. let Tlist_Ctags_Cmd='/usr/bin/ctags'   
  42. "因为我们放在环境变量里,所以可以直接执行  
  43. let Tlist_Use_Right_Window=1  
  44. "让窗口显示在右边,0的话就是显示在左边  
  45. let Tlist_Show_One_File=1  
  46. "让taglist可以同时展示多个文件的函数列表  
  47. let Tlist_File_Fold_Auto_Close=1  
  48. "非当前文件,函数列表折叠隐藏  
  49. let Tlist_Exit_OnlyWindow=1  
  50. "当taglist是最后一个分割窗口时,自动推出vim  
  51. "是否一直处理tags.1:处理;0:不处理  
  52. let Tlist_Process_File_Always=0  
  53. "不是一直实时更新tags,因为没有必要  
  54. let Tlist_Inc_Winwidth=0  
  55.   
  56.   
  57. "设置字体  
  58. "set guifont=DejaVu\ Sans\ Mono\ 10  
  59. set guifont=Consolas\ 11  
  60. " 开启语法高亮  
  61. syntax enable  
  62. syntax on  
  63. "设置了在窗口右侧何处开始换行没有\n符号,textwidth有\n  
  64. set wrapmargin=10  
  65.   
  66. "在代码使用4个空格代替TAB符  
  67. autocmd FileType c,cpp,py set shiftwidth=4 | set expandtab  
  68.   
  69. "zzg added   
  70. "set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]  
  71. "set laststatus=2  
  72. "imap <C-s> <ESC>:w<cr>a  
  73.   
  74. set shiftwidth=4  
  75. "set indent length  
  76.   
  77. set expandtab  
  78. " set use a series of backspaces to  replace tab  
  79.   
  80. set tabstop=4  
  81. " set when press a tab how many backspaces will skip  
  82.   
  83. "关闭vi兼容模式  
  84. "set nocp  
  85.   
  86. " 自动切换目录  
  87. set autochdir  
  88. " 打开行号显示  
  89. set nu  
  90. " 设置文字编码自动识别  
  91. set fencs=utf-8,cp936  
  92. " 使用鼠标  
  93. set mouse=a  
  94. " 设置高亮搜索  
  95. set hlsearch  
  96. " 设置代码折叠  
  97. "set fdm=indent  
  98. "set foldmethod=syntax  
  99. "autocmd FileType c,cpp  setl fdm=syntax | setl fen   
  100. " 输入字符串就显示匹配点  
  101. set incsearch  
  102. " 输入的命令显示出来,看的清楚些。  
  103. set showcmd  
  104. " 选择配色方案  
  105. "hi Nomal ctermfg=Grey ctermbg=Black  
  106. colorscheme darkburn  
  107. "colorscheme darkblue  
  108. "colorscheme morning  
  109.   
  110. """"""""""""""""""""""""""""""  
  111. " BufExplorer  
  112. """"""""""""""""""""""""""""""  
  113. "let g:bufExplorerDefaultHelp=0       " Do not show default help.  
  114. "let g:bufExplorerShowRelativePath=1  " Show relative paths.  
  115. "let g:bufExplorerSortBy='mru'        " Sort by most recently used.  
  116. "let g:bufExplorerSplitRight=0        " Split left.  
  117. "let g:bufExplorerSplitVertical=1     " Split vertically.  
  118. "let g:bufExplorerSplitVertSize=30    " Split width  
  119. "let g:bufExplorerUseCurrentWindow=1  " Open in new window.  
  120. "autocmd BufWinEnter \[Buf\ List\] setl nonumber   
  121.   
  122. "打开当前目录文件列表  
  123. """"""""""""""""""""""""""""""  
  124. " netrw setting  
  125. """"""""""""""""""""""""""""""  
  126. let g:netrw_winsize = 30  
  127. nmap <silent> fe :Sexplore!<cr>   
  128.   
  129.   
  130. let g:LookupFile_TagExpr = '"./filenametags"'   
  131.   
  132.   
  133.   
  134. """""""""""""""""""""""""""""  
  135. " WinManager setting  
  136. """""""""""""""""""""""""""""  
  137. let g:winManagerWindowLayout = "FileExplorer|TagList"  
  138. let g:winManagerWidth = 30  
  139. let g:defaultExplorer = 0  
  140. nmap <C-W><C-F> :FirstExplorerWindow<cr>  
  141. nmap <C-W><C-B> :BottomExplorerWindow<cr>  
  142. nmap <silent> wm :WMToggle<cr>  
  143.   
  144. """"""""""""""""""""""""""""""  
  145. " lookupfile setting  
  146. """"""""""""""""""""""""""""""  
  147. let g:LookupFile_MinPatLength = 2               "最少输入2个字符才开始查找  
  148. let g:LookupFile_PreserveLastPattern = 0        "不保存上次查找的字符串  
  149. let g:LookupFile_PreservePatternHistory = 1     "保存查找历史  
  150. let g:LookupFile_AlwaysAcceptFirst = 1          "回车打开第一个匹配项目  
  151. let g:LookupFile_AllowNewFiles = 0              "不允许创建不存在的文件  
  152. if filereadable("./filenametags")                "设置tag文件的名字  
  153. let g:LookupFile_TagExpr = '"./filenametags"'  
  154. endif  
  155. "映射LookupFile为,lk  
  156. nmap <silent> <leader>lk :LUTags<cr>  
  157. "映射LUBufs为,ll  
  158. nmap <silent> <leader>ll :LUBufs<cr>  
  159. "映射LUWalk为,lw  
  160. nmap <silent> <leader>lw :LUWalk<cr>  
  161.   
  162. " lookup file with ignore case  
  163. function! LookupFile_IgnoreCaseFunc(pattern)  
  164.     let _tags = &tags  
  165.     try  
  166.         let &tags = eval(g:LookupFile_TagExpr)  
  167.         let newpattern = '\c' . a:pattern  
  168.         let tags = taglist(newpattern)  
  169.     catch  
  170.         echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE  
  171.         return ""  
  172.     finally  
  173.         let &tags = _tags  
  174.     endtry  
  175.   
  176.     " Show the matches for what is typed so far.  
  177.     let files = map(tags, 'v:val["filename"]')  
  178.     return files  
  179. endfunction  
  180. let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'   
  181.   
  182.   
  183. """"""""""""""""""""""""""""""  
  184. " mark setting  
  185. """"""""""""""""""""""""""""""  
  186. nmap <silent> <leader>hl <Plug>MarkSet  
  187. vmap <silent> <leader>hl <Plug>MarkSet  
  188. nmap <silent> <leader>hh <Plug>MarkClear  
  189. vmap <silent> <leader>hh <Plug>MarkClear  
  190. nmap <silent> <leader>hr <Plug>MarkRegex  
  191. vmap <silent> <leader>hr <Plug>MarkRegex   
  192.   
  193. "Quickfix hotkey  
  194. autocmd FileType c,cpp  map <buffer> <leader><space> :w<cr>:make<cr>  
  195. nmap <leader>cn :cn<cr>  
  196. nmap <leader>cp :cp<cr>  
  197. nmap <leader>cw :cw 10<cr>   
  198.   
  199. "在当前文件中快速查找光标下的单词:   
  200. nmap <leader>lv :lv /<c-r>=expand("<cword>")<cr>/ %<cr>:lw<cr>   
  201.   
  202.   
  203. map <F12> :call Do_CsTag()<CR>  
  204. nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>  
  205. nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>  
  206. nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>  
  207. nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>  
  208. nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>  
  209. nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>  
  210. nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>  
  211. nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>  
  212. function Do_CsTag()  
  213.     let dir = getcwd()  
  214.     if filereadable("tags")  
  215.         if(g:iswindows==1)  
  216.             let tagsdeleted=delete(dir."\\"."tags")  
  217.         else  
  218.             let tagsdeleted=delete("./"."tags")  
  219.         endif  
  220.         if(tagsdeleted!=0)  
  221.             echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None  
  222.             return  
  223.         endif  
  224.     endif  
  225.     if has("cscope")  
  226.         silent! execute "cs kill -1"  
  227.     endif  
  228.     if filereadable("cscope.files")  
  229.         if(g:iswindows==1)  
  230.             let csfilesdeleted=delete(dir."\\"."cscope.files")  
  231.         else  
  232.             let csfilesdeleted=delete("./"."cscope.files")  
  233.         endif  
  234.         if(csfilesdeleted!=0)  
  235.             echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None  
  236.             return  
  237.         endif  
  238.     endif  
  239.     if filereadable("cscope.out")  
  240.         if(g:iswindows==1)  
  241.             let csoutdeleted=delete(dir."\\"."cscope.out")  
  242.         else  
  243.             let csoutdeleted=delete("./"."cscope.out")  
  244.         endif  
  245.         if(csoutdeleted!=0)  
  246.             echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None  
  247.             return  
  248.         endif  
  249.     endif  
  250.     if(executable('ctags'))  
  251.         "silent! execute "!ctags -R --c-types=+p --fields=+S *"  
  252.         silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."  
  253.     endif  
  254.     if(executable('cscope') && has("cscope") )  
  255.         if(g:iswindows!=1)  
  256.             silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"  
  257.         else  
  258.             silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"  
  259.         endif  
  260.         silent! execute "!cscope -b"  
  261.         execute "normal :"  
  262.         if filereadable("cscope.out")  
  263.             execute "cs add cscope.out"  
  264.         endif  
  265.     endif  
  266. endfunction  
  267.   
  268.   
  269.   
  270.   
  271. " OmniCppComplete  
  272. let OmniCpp_NamespaceSearch = 1  
  273. let OmniCpp_GlobalScopeSearch = 1  
  274. let OmniCpp_ShowAccess = 1  
  275. let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters  
  276. let OmniCpp_MayCompleteDot = 1 " autocomplete after .  
  277. let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->  
  278. let OmniCpp_MayCompleteScope = 1 " autocomplete after ::  
  279. let OmniCpp_DefaultNamespaces = ["std""_GLIBCXX_STD"]  
  280. " automatically open and close the popup menu / preview window  
  281. autocmd CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif  
  282.   
  283.   
  284.   
  285. " set something for ominicomplete  
  286. set completeopt=longest,menu   
  287.   
  288. "对NERD_commenter的设置  
  289. let NERDShutUp=1  
  290.   
  291. map fg :Dox<cr>  
  292. let g:DoxygenToolkit_authorName="zzg"  
  293. let g:DoxygenToolkit_licenseTag="My own license\<enter>"  
  294. let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"  
  295. let g:DoxygenToolkit_briefTag_pre = "@brief\t"  
  296. let g:DoxygenToolkit_paramTag_pre = "@param\t"  
  297. let g:DoxygenToolkit_returnTag = "@return\t"  
  298. let g:DoxygenToolkit_briefTag_funcName = "no"  
  299. let g:DoxygenToolkit_maxFunctionProtoLines = 30  
  300.   
  301.   
  302.   
  303. " mapping omini  
  304. inoremap <expr> <CR>       pumvisible()?"\<C-Y>":"\<CR>"  
  305. inoremap <expr> <C-J>      pumvisible()?"\<PageDown>\<C-N>\<C-P>":"\<C-X><C-O>"  
  306. inoremap <expr> <C-K>      pumvisible()?"\<PageUp>\<C-P>\<C-N>":"\<C-K>"  
  307. inoremap <expr> <C-U>      pumvisible()?"\<C-E>":"\<C-U>"   
  308.   
  309.   
  310. set tags+=~/.vim/stl_tags  
  311.   
  312. "set paste  if set this the omnicomplete will not work   
  313. "remember to the last position you edit zzg  
  314. if has("autocmd")  
  315.        autocmd BufRead *.txt set tw=78  
  316.        autocmd BufReadPost *  
  317.         \ if line("'\"") > 0 && line ("'\"") <= line("$") |  
  318.         \   exe "normal g'\"" |  
  319.         \ endif  
  320. endif  

 

 

 

 

总结一下安装过程中遇到的问题:

   安装ctags由于以前安装过emacs,所以有了emacs的ctags,我误以为是exburant ctags已经安装了,结果错了很长时间,要安装Exburant ctags,也就是正常情况下的ctags。

   安装cscope时make错误,就没安,继续往下,但是cpp的自动补全不好使。后来查到cscope缺少的相关软件有:

   bison , flex  lib curses-dev 什么的

   用 apt-cache search keywords 就能找到了.然后再安装对应的包就行了。

 

最后设置vim下用256色,并用了一个非常好看的颜色主题:darkburn.vim

 

有两个网站关于vim讲的非常好:

http://www./

http:///blog/     很敬佩这位大牛!!

 

 

 

下载插件的官网是:搜一下想找的插件立马就会出来,官网很强大。

http://www./scripts/

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多