我的vim的vimrc配置文件,保存用 - 飞在天空的鱼 - 博客频道

转载自:飞在天空的鱼 - 博客频道http://blog.csdn.net/zhengzhoudaxue2/article/details/45247733?locationNum=15&fps=1

[cpp]  view plain  copy
  1. " All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by  
  2. " the call to :runtime you can find below.  If you wish to change any of those  
  3. " settings, you should do it in this file (/etc/vim/vimrc), since debian.vim  
  4. " will be overwritten everytime an upgrade of the vim packages is performed.  
  5. " It is recommended to make changes after sourcing debian.vim since it alters  
  6. " the value of the 'compatible' option.  
  7.   
  8. " This line should not be removed as it ensures that various options are  
  9. " properly set to work with the Vim-related packages available in Debian.  
  10. runtime! debian.vim  
  11.   
  12. " Uncomment the next line to make Vim more Vi-compatible  
  13. " NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous  
  14. " options, so any other options should be set AFTER setting 'compatible'.  
  15. "set compatible  
  16.   
  17. " Vim5 and later versions support syntax highlighting. Uncommenting the next  
  18. " line enables syntax highlighting by default.  
  19. if has("syntax")  
  20.   syntax on  
  21. endif  
  22.   
  23. " If using a dark background within the editing area and syntax highlighting  
  24. " turn on this option as well  
  25. "set background=dark  
  26.   
  27. " Uncomment the following to have Vim jump to the last position when  
  28. " reopening a file  
  29. "if has("autocmd")  
  30. "  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif  
  31. "endif  
  32.   
  33. " Uncomment the following to have Vim load indentation rules and plugins  
  34. " according to the detected filetype.  
  35. "if has("autocmd")  
  36. "  filetype plugin indent on  
  37. "endif  
  38.   
  39. " The following are commented out as they cause vim to behave a lot  
  40. " differently from regular Vi. They are highly recommended though.  
  41. "set showcmd        " Show (partial) command in status line.  
  42. "set showmatch      " Show matching brackets.  
  43. "set ignorecase     " Do case insensitive matching  
  44. "set smartcase      " Do smart case matching  
  45. "set incsearch      " Incremental search  
  46. "set autowrite      " Automatically save before commands like :next and :make  
  47. "set hidden     " Hide buffers when they are abandoned  
  48. "set mouse=a        " Enable mouse usage (all modes)  
  49.   
  50. " Source a global configuration file if available  
  51. if filereadable("/etc/vim/vimrc.local")  
  52.   source /etc/vim/vimrc.local  
  53. endif  
  54.   
  55.   
  56.   
  57.  " =============================================================================  
  58. "        << 判断操作系统是 Windows 还是 Linux 和判断是终端还是 Gvim >>  
  59. " =============================================================================  
  60.    
  61. " -----------------------------------------------------------------------------  
  62. "  < 判断操作系统是否是 Windows 还是 Linux >  
  63. " -----------------------------------------------------------------------------  
  64. let g:iswindows = 0  
  65. let g:islinux = 0  
  66. if(has("win32") || has("win64") || has("win95") || has("win16"))  
  67.     let g:iswindows = 1  
  68. else  
  69.     let g:islinux = 1  
  70. endif  
  71.    
  72. " -----------------------------------------------------------------------------  
  73. "  < 判断是终端还是 Gvim >  
  74. " -----------------------------------------------------------------------------  
  75. if has("gui_running")  
  76.     let g:isGUI = 1  
  77. else  
  78.     let g:isGUI = 0  
  79. endif  
  80.    
  81.    
  82. " =============================================================================  
  83. "                          << 以下为软件默认配置 >>  
  84. " =============================================================================  
  85.    
  86. " -----------------------------------------------------------------------------  
  87. "  < Windows Gvim 默认配置> 做了一点修改  
  88. " -----------------------------------------------------------------------------  
  89. if (g:iswindows && g:isGUI)  
  90.     source $VIMRUNTIME/vimrc_example.vim  
  91.     source $VIMRUNTIME/mswin.vim  
  92.     behave mswin  
  93.     set diffexpr=MyDiff()  
  94.    
  95.     function MyDiff()  
  96.         let opt = '-a --binary '  
  97.         if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif  
  98.         if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif  
  99.         let arg1 = v:fname_in  
  100.         if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif  
  101.         let arg2 = v:fname_new  
  102.         if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif  
  103.         let arg3 = v:fname_out  
  104.         if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif  
  105.         let eq = ''  
  106.         if $VIMRUNTIME =~ ' '  
  107.             if &sh =~ '\<cmd'  
  108.                 let cmd = '""' . $VIMRUNTIME . '\diff"'  
  109.                 let eq = '"'  
  110.             else  
  111.                 let cmd = substitute($VIMRUNTIME, ' ''" ''') . '\diff"'  
  112.             endif  
  113.         else  
  114.             let cmd = $VIMRUNTIME . '\diff'  
  115.         endif  
  116.         silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq  
  117.     endfunction  
  118. endif  
  119.    
  120. " -----------------------------------------------------------------------------  
  121. "  < Linux Gvim/Vim 默认配置> 做了一点修改  
  122. " -----------------------------------------------------------------------------  
  123. if g:islinux  
  124.     set hlsearch        "高亮搜索  
  125.     set incsearch       "在输入要搜索的文字时,实时匹配  
  126.    
  127.     " Uncomment the following to have Vim jump to the last position when  
  128.     " reopening a file  
  129.     if has("autocmd")  
  130.         au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif  
  131.     endif  
  132.    
  133.     if g:isGUI  
  134.         " Source a global configuration file if available  
  135.         if filereadable("/etc/vim/gvimrc.local")  
  136.             source /etc/vim/gvimrc.local  
  137.         endif  
  138.     else  
  139.         " This line should not be removed as it ensures that various options are  
  140.         " properly set to work with the Vim-related packages available in Debian.  
  141.         runtime! debian.vim  
  142.    
  143.         " Vim5 and later versions support syntax highlighting. Uncommenting the next  
  144.         " line enables syntax highlighting by default.  
  145.         if has("syntax")  
  146.             syntax on  
  147.         endif  
  148.    
  149.         set mouse=a                    " 在任何模式下启用鼠标  
  150.         "set t_Co=256                   " 在终端启用256色  
  151.         set backspace=2                " 设置退格键可用  
  152.    
  153.         " Source a global configuration file if available  
  154.         if filereadable("/etc/vim/vimrc.local")  
  155.             source /etc/vim/vimrc.local  
  156.         endif  
  157.     endif  
  158. endif  
  159.    
  160.    
  161. " =============================================================================  
  162. "                          << 以下为用户自定义配置 >>  
  163. " =============================================================================  
  164.    
  165. " -----------------------------------------------------------------------------  
  166. "  < Vundle 插件管理工具配置 >  
  167. " -----------------------------------------------------------------------------  
  168. " 用于更方便的管理vim插件,具体用法参考 :h vundle 帮助  
  169. " Vundle工具安装方法为在终端输入如下命令  
  170. " git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle  
  171. " 如果想在 windows 安装就必需先安装 "git for window",可查阅网上资料  
  172.    
  173. set nocompatible                                      "禁用 Vi 兼容模式  
  174. filetype off                                          "禁用文件类型侦测  
  175.    
  176. if g:islinux  
  177.     set rtp+=/home/hisome/.vim/bundle/vundle/  
  178.     call vundle#rc()  
  179. else  
  180.     set rtp+=$VIM/vimfiles/bundle/vundle/  
  181.     call vundle#rc('$VIM/vimfiles/bundle/')  
  182. endif  
  183.    
  184. " 使用Vundle来管理插件,这个必须要有。  
  185. Bundle 'gmarik/vundle'  
  186.    
  187. " 以下为要安装或更新的插件,不同仓库都有(具体书写规范请参考帮助)  
  188. Bundle 'a.vim'  
  189. Bundle 'Align'  
  190. Bundle 'jiangmiao/auto-pairs'  
  191. Bundle 'bufexplorer.zip'  
  192. Bundle 'ccvext.vim'  
  193. Bundle 'cSyntaxAfter'  
  194. Bundle 'ctrlpvim/ctrlp.vim'  
  195. Bundle 'mattn/emmet-vim'  
  196. Bundle 'Yggdroot/indentLine'  
  197. Bundle 'vim-javacompleteex'  
  198. Bundle 'Mark--Karkat'  
  199. Bundle 'Shougo/neocomplcache.vim'  
  200. Bundle 'scrooloose/nerdcommenter'  
  201. Bundle 'scrooloose/nerdtree'  
  202. Bundle 'OmniCppComplete'  
  203. Bundle 'Lokaltog/vim-powerline'  
  204. Bundle 'repeat.vim'  
  205. Bundle 'msanders/snipmate.vim'  
  206. Bundle 'wesleyche/SrcExpl'  
  207. Bundle 'std_c.zip'  
  208. Bundle 'tpope/vim-surround'  
  209. Bundle 'scrooloose/syntastic'  
  210. Bundle 'majutsushi/tagbar'  
  211. Bundle 'taglist.vim'  
  212. Bundle 'TxtBrowser'  
  213. Bundle 'ZoomWin'  
  214. Bundle 'WinManager'  
  215. Bundle 'DoxygenToolkit.vim'  
  216.    
  217. " -----------------------------------------------------------------------------  
  218. "  < 编码配置 >  
  219. " -----------------------------------------------------------------------------  
  220. " 注:使用utf-8格式后,软件与程序源码、文件路径不能有中文,否则报错  
  221. set encoding=utf-8                                   "设置gvim内部编码,默认不更改  
  222. set fileencoding=utf-8                                "设置当前文件编码,可以更改,如:gbk(同cp936)  
  223. set fileencodings=ucs-bom,utf-8,gbk,cp936,latin-1     "设置支持打开的文件的编码  
  224.    
  225. " 文件格式,默认 ffs=dos,unix  
  226. set fileformat=unix                                   "设置新(当前)文件的<EOL>格式,可以更改,如:dos(windows系统常用)  
  227. set fileformats=unix,dos,mac                          "给出文件的<EOL>格式类型  
  228.    
  229. if (g:iswindows && g:isGUI)  
  230.     "解决菜单乱码  
  231.     source $VIMRUNTIME/delmenu.vim  
  232.     source $VIMRUNTIME/menu.vim  
  233.    
  234.     "解决consle输出乱码  
  235.     language messages zh_CN.utf-8  
  236. endif  
  237.    
  238. " -----------------------------------------------------------------------------  
  239. "  < 编写文件时的配置 >  
  240. " -----------------------------------------------------------------------------  
  241. filetype on                                           "启用文件类型侦测  
  242. filetype plugin on                                    "针对不同的文件类型加载对应的插件  
  243. filetype plugin indent on                             "启用缩进  
  244. set smartindent                                       "启用智能对齐方式  
  245. set expandtab                                         "将Tab键转换为空格  
  246. set tabstop=4                                         "设置Tab键的宽度,可以更改,如:宽度为2  
  247. set shiftwidth=4                                      "换行时自动缩进宽度,可更改(宽度同tabstop)  
  248. set smarttab                                          "指定按一次backspace就删除shiftwidth宽度  
  249. "set foldenable                                        "启用折叠  
  250. "set foldmethod=indent                                 "indent 折叠方式  
  251. "set foldcolumn=2   
  252. "set foldlevel=3  
  253. " set foldmethod=marker                                "marker 折叠方式  
  254.   
  255. "AutoCommand  
  256. "新建.c,.h,.sh,.java文件,自动插入文件头  
  257. autocmd BufNewFile *.[ch],*.sh,*.java exec ":call SetTitle()"  
  258. "新建文件后,自动定位到文件末尾  
  259. autocmd BufNewFile * normal G   
  260.   
  261. " 常规模式下用空格键来开关光标行所在折叠(注:zR 展开所有折叠,zM 关闭所有折叠)  
  262. nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>  
  263.    
  264. " 当文件在外部被修改,自动更新该文件  
  265. set autoread  
  266.    
  267. " 常规模式下输入 cS 清除行尾空格  
  268. nmap cS :%s/\s\+$//g<CR>:noh<CR>  
  269.    
  270. " 常规模式下输入 cM 清除行尾 ^M 符号  
  271. nmap cM :%s/\r$//g<CR>:noh<CR>  
  272.    
  273. set ignorecase                                        "搜索模式里忽略大小写  
  274. set smartcase                                         "如果搜索模式包含大写字符,不使用 'ignorecase' 选项,只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用  
  275. " set noincsearch                                       "在输入要搜索的文字时,取消实时匹配  
  276.    
  277. " Ctrl + K 插入模式下光标向上移动  
  278. imap <c-k> <Up>  
  279.    
  280. " Ctrl + J 插入模式下光标向下移动  
  281. imap <c-j> <Down>  
  282.    
  283. " Ctrl + H 插入模式下光标向左移动  
  284. imap <c-h> <Left>  
  285.    
  286. " Ctrl + L 插入模式下光标向右移动  
  287. imap <c-l> <Right>  
  288.    
  289. " 启用每行超过120列的字符提示(字体变蓝并加下划线),不启用就注释掉  
  290. "au BufWinEnter * let w:m2=matchadd('Underlined''\%>' . 120 . 'v.\+', -1)  
  291.    
  292. " -----------------------------------------------------------------------------  
  293. "  < 界面配置 >  
  294. " -----------------------------------------------------------------------------  
  295. set number                                            "显示行号  
  296. set laststatus=2                                      "启用状态栏信息  
  297. set cmdheight=2                                       "设置命令行的高度为2,默认为1  
  298. set cursorline                                        "突出显示当前行  
  299. " set guifont=YaHei_Consolas_Hybrid:h10                 "设置字体:字号(字体名称空格用下划线代替)  
  300. set nowrap                                            "设置不自动换行  
  301. set shortmess=atI                                     "去掉欢迎界面  
  302.    
  303. " 设置 gVim 窗口初始位置及大小  
  304. if g:isGUI  
  305.     " au GUIEnter * simalt ~x                           "窗口启动时自动最大化  
  306.     winpos 100 10                                     "指定窗口出现的位置,坐标原点在屏幕左上角  
  307.     set lines=38 columns=120                          "指定窗口大小,lines为高度,columns为宽度  
  308. endif  
  309.    
  310.                                                                         " 设置代码配色方案  
  311. set t_Co=256  
  312.   
  313. set background=dark  
  314.   
  315. colorscheme molokai  
  316.   
  317. "if g:isGUI  
  318. "   colorscheme Tomorrow-Night-Eighties               "Gvim配色方案  
  319. "else  
  320. "    colorscheme Tomorrow-Night-Eighties               "终端配色方案  
  321. "endif  
  322.    
  323. " 显示/隐藏菜单栏、工具栏、滚动条,可用 Ctrl + F11 切换  
  324. if g:isGUI  
  325.     set guioptions-=m  
  326.     set guioptions-=T  
  327.     set guioptions-=r  
  328.     set guioptions-=L  
  329.     nmap <silent> <c-F11> :if &guioptions =~# 'm' <Bar>  
  330.         \set guioptions-=m <Bar>  
  331.         \set guioptions-=T <Bar>  
  332.         \set guioptions-=r <Bar>  
  333.         \set guioptions-=L <Bar>  
  334.     \else <Bar>  
  335.         \set guioptions+=m <Bar>  
  336.         \set guioptions+=T <Bar>  
  337.         \set guioptions+=r <Bar>  
  338.         \set guioptions+=L <Bar>  
  339.     \endif<CR>  
  340. endif  
  341.    
  342. " -----------------------------------------------------------------------------  
  343. "  < 编译、连接、运行配置 (目前只配置了C、C++、Java语言)>  
  344. " -----------------------------------------------------------------------------  
  345. " F9 一键保存、编译、连接存并运行  
  346. nmap <F9> :call Run()<CR>  
  347. imap <F9> <ESC>:call Run()<CR>  
  348.    
  349. " Ctrl + F9 一键保存并编译  
  350. nmap <c-F9> :call Compile()<CR>  
  351. imap <c-F9> <ESC>:call Compile()<CR>  
  352.    
  353. " Ctrl + F10 一键保存并连接  
  354. nmap <c-F10> :call Link()<CR>  
  355. imap <c-F10> <ESC>:call Link()<CR>  
  356.    
  357. let s:LastShellReturn_C = 0  
  358. let s:LastShellReturn_L = 0  
  359. let s:ShowWarning = 1  
  360. let s:Obj_Extension = '.o'  
  361. let s:Exe_Extension = '.exe'  
  362. let s:Class_Extension = '.class'  
  363. let s:Sou_Error = 0  
  364.    
  365. let s:windows_CFlags = 'gcc\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'  
  366. let s:linux_CFlags = 'gcc\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'  
  367.    
  368. let s:windows_CPPFlags = 'g++\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'  
  369. let s:linux_CPPFlags = 'g++\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'  
  370.    
  371. let s:JavaFlags = 'javac\ %'  
  372.    
  373. func! Compile()  
  374.     exe ":ccl"  
  375.     exe ":update"  
  376.     let s:Sou_Error = 0  
  377.     let s:LastShellReturn_C = 0  
  378.     let Sou = expand("%:p")  
  379.     let v:statusmsg = ''  
  380.     if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"  
  381.         let Obj = expand("%:p:r").s:Obj_Extension  
  382.         let Obj_Name = expand("%:p:t:r").s:Obj_Extension  
  383.         if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou)))  
  384.             redraw!  
  385.             if expand("%:e") == "c"  
  386.                 if g:iswindows  
  387.                     exe ":setlocal makeprg=".s:windows_CFlags  
  388.                 else  
  389.                     exe ":setlocal makeprg=".s:linux_CFlags  
  390.                 endif  
  391.                 echohl WarningMsg | echo " compiling..."  
  392.                 silent make  
  393.             elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"  
  394.                 if g:iswindows  
  395.                     exe ":setlocal makeprg=".s:windows_CPPFlags  
  396.                 else  
  397.                     exe ":setlocal makeprg=".s:linux_CPPFlags  
  398.                 endif  
  399.                 echohl WarningMsg | echo " compiling..."  
  400.                 silent make  
  401.             endif  
  402.             redraw!  
  403.             if v:shell_error != 0  
  404.                 let s:LastShellReturn_C = v:shell_error  
  405.             endif  
  406.             if g:iswindows  
  407.                 if s:LastShellReturn_C != 0  
  408.                     exe ":bo cope"  
  409.                     echohl WarningMsg | echo " compilation failed"  
  410.                 else  
  411.                     if s:ShowWarning  
  412.                         exe ":bo cw"  
  413.                     endif  
  414.                     echohl WarningMsg | echo " compilation successful"  
  415.                 endif  
  416.             else  
  417.                 if empty(v:statusmsg)  
  418.                     echohl WarningMsg | echo " compilation successful"  
  419.                 else  
  420.                     exe ":bo cope"  
  421.                 endif  
  422.             endif  
  423.         else  
  424.             echohl WarningMsg | echo ""Obj_Name"is up to date"  
  425.         endif  
  426.     elseif expand("%:e") == "java"  
  427.         let class = expand("%:p:r").s:Class_Extension  
  428.         let class_Name = expand("%:p:t:r").s:Class_Extension  
  429.         if !filereadable(class) || (filereadable(class) && (getftime(class) < getftime(Sou)))  
  430.             redraw!  
  431.             exe ":setlocal makeprg=".s:JavaFlags  
  432.             echohl WarningMsg | echo " compiling..."  
  433.             silent make  
  434.             redraw!  
  435.             if v:shell_error != 0  
  436.                 let s:LastShellReturn_C = v:shell_error  
  437.             endif  
  438.             if g:iswindows  
  439.                 if s:LastShellReturn_C != 0  
  440.                     exe ":bo cope"  
  441.                     echohl WarningMsg | echo " compilation failed"  
  442.                 else  
  443.                     if s:ShowWarning  
  444.                         exe ":bo cw"  
  445.                     endif  
  446.                     echohl WarningMsg | echo " compilation successful"  
  447.                 endif  
  448.             else  
  449.                 if empty(v:statusmsg)  
  450.                     echohl WarningMsg | echo " compilation successful"  
  451.                 else  
  452.                     exe ":bo cope"  
  453.                 endif  
  454.             endif  
  455.         else  
  456.             echohl WarningMsg | echo ""class_Name"is up to date"  
  457.         endif  
  458.     else  
  459.         let s:Sou_Error = 1  
  460.         echohl WarningMsg | echo " please choose the correct source file"  
  461.     endif  
  462.     exe ":setlocal makeprg=make"  
  463. endfunc  
  464.    
  465. func! Link()  
  466.     call Compile()  
  467.     if s:Sou_Error || s:LastShellReturn_C != 0  
  468.         return  
  469.     endif  
  470.     if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"  
  471.         let s:LastShellReturn_L = 0  
  472.         let Sou = expand("%:p")  
  473.         let Obj = expand("%:p:r").s:Obj_Extension  
  474.         if g:iswindows  
  475.             let Exe = expand("%:p:r").s:Exe_Extension  
  476.             let Exe_Name = expand("%:p:t:r").s:Exe_Extension  
  477.         else  
  478.             let Exe = expand("%:p:r")  
  479.             let Exe_Name = expand("%:p:t:r")  
  480.         endif  
  481.         let v:statusmsg = ''  
  482.         if filereadable(Obj) && (getftime(Obj) >= getftime(Sou))  
  483.             redraw!  
  484.             if !executable(Exe) || (executable(Exe) && getftime(Exe) < getftime(Obj))  
  485.                 if expand("%:e") == "c"  
  486.                     setlocal makeprg=gcc\ -o\ %<\ %<.o  
  487.                     echohl WarningMsg | echo " linking..."  
  488.                     silent make  
  489.                 elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"  
  490.                     setlocal makeprg=g++\ -o\ %<\ %<.o  
  491.                     echohl WarningMsg | echo " linking..."  
  492.                     silent make  
  493.                 endif  
  494.                 redraw!  
  495.                 if v:shell_error != 0  
  496.                     let s:LastShellReturn_L = v:shell_error  
  497.                 endif  
  498.                 if g:iswindows  
  499.                     if s:LastShellReturn_L != 0  
  500.                         exe ":bo cope"  
  501.                         echohl WarningMsg | echo " linking failed"  
  502.                     else  
  503.                         if s:ShowWarning  
  504.                             exe ":bo cw"  
  505.                         endif  
  506.                         echohl WarningMsg | echo " linking successful"  
  507.                     endif  
  508.                 else  
  509.                     if empty(v:statusmsg)  
  510.                         echohl WarningMsg | echo " linking successful"  
  511.                     else  
  512.                         exe ":bo cope"  
  513.                     endif  
  514.                 endif  
  515.             else  
  516.                 echohl WarningMsg | echo ""Exe_Name"is up to date"  
  517.             endif  
  518.         endif  
  519.         setlocal makeprg=make  
  520.     elseif expand("%:e") == "java"  
  521.         return  
  522.     endif  
  523. endfunc  
  524.    
  525. func! Run()  
  526.     let s:ShowWarning = 0  
  527.     call Link()  
  528.     let s:ShowWarning = 1  
  529.     if s:Sou_Error || s:LastShellReturn_C != 0 || s:LastShellReturn_L != 0  
  530.         return  
  531.     endif  
  532.     let Sou = expand("%:p")  
  533.     if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"  
  534.         let Obj = expand("%:p:r").s:Obj_Extension  
  535.         if g:iswindows  
  536.             let Exe = expand("%:p:r").s:Exe_Extension  
  537.         else  
  538.             let Exe = expand("%:p:r")  
  539.         endif  
  540.         if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou)  
  541.             redraw!  
  542.             echohl WarningMsg | echo " running..."  
  543.             if g:iswindows  
  544.                 exe ":!%<.exe"  
  545.             else  
  546.                 if g:isGUI  
  547.                     exe ":!gnome-terminal -x bash -c './%<; echo; echo 请按 Enter 键继续; read'"  
  548.                 else  
  549.                     exe ":!clear; ./%<"  
  550.                 endif  
  551.             endif  
  552.             redraw!  
  553.             echohl WarningMsg | echo " running finish"  
  554.         endif  
  555.     elseif expand("%:e") == "java"  
  556.         let class = expand("%:p:r").s:Class_Extension  
  557.         if getftime(class) >= getftime(Sou)  
  558.             redraw!  
  559.             echohl WarningMsg | echo " running..."  
  560.             if g:iswindows  
  561.                 exe ":!java %<"  
  562.             else  
  563.                 if g:isGUI  
  564.                     exe ":!gnome-terminal -x bash -c 'java %<; echo; echo 请按 Enter 键继续; read'"  
  565.                 else  
  566.                     exe ":!clear; java %<"  
  567.                 endif  
  568.             endif  
  569.             redraw!  
  570.             echohl WarningMsg | echo " running finish"  
  571.         endif  
  572.     endif  
  573. endfunc  
  574.    
  575.    
  576. " -----------------------------------------------------------------------------  
  577. "  < 其它配置 >  
  578. " -----------------------------------------------------------------------------  
  579. set writebackup                             "保存文件前建立备份,保存成功后删除该备份  
  580. set nobackup                                "设置无备份文件  
  581. " set noswapfile                              "设置无临时文件  
  582. " set vb t_vb=                                "关闭提示音  
  583.   
  584. " -----------------------------------------------------------------------------  
  585. "定义函数SetTitle,自动插入文件头  
  586. " -----------------------------------------------------------------------------  
  587. func SetTitle()  
  588. "如果文件类型为.sh文件  
  589. if &filetype == 'sh'  
  590. call setline(1, "\#########################################################################")  
  591. call append(line("."), "\# Author: zhangbo")  
  592. call append(line(".")+1, "\# Created Time: ".strftime("%c"))  
  593. call append(line(".")+2, "\# File Name: ".expand("%"))  
  594. call append(line(".")+3, "\# Description: ")  
  595. call append(line(".")+4, "\#########################################################################")  
  596. call append(line(".")+5, "\#!/bin/bash")  
  597. call append(line(".")+6, "")  
  598. else  
  599. call setline(1, "/*************************************************************************")  
  600. call append(line("."), " Author: zhangbo")  
  601. call append(line(".")+1, " Created Time: ".strftime("%c"))  
  602. call append(line(".")+2, " File Name: ".expand("%"))  
  603. call append(line(".")+3, " Description: ")  
  604. call append(line(".")+4, " ************************************************************************/")  
  605. call append(line(".")+5, "")  
  606. endif  
  607. endfunc   
  608.    
  609.    
  610. " =============================================================================  
  611. "                          << 以下为常用插件配置 >>  
  612. " =============================================================================  
  613.    
  614. " -----------------------------------------------------------------------------  
  615. "  < a.vim 插件配置 >  
  616. " -----------------------------------------------------------------------------  
  617. " 用于切换C/C++头文件  
  618. " :A     ---切换头文件并独占整个窗口  
  619. " :AV    ---切换头文件并垂直分割窗口  
  620. " :AS    ---切换头文件并水平分割窗口  
  621. nnoremap <silent> <F12> : A<CR>  
  622.    
  623. " -----------------------------------------------------------------------------  
  624. "  < Align 插件配置 >  
  625. " -----------------------------------------------------------------------------  
  626. " 一个对齐的插件,用来——排版与对齐代码,功能强大,不过用到的机会不多  
  627.    
  628. " -----------------------------------------------------------------------------  
  629. "  < auto-pairs 插件配置 >  
  630. " -----------------------------------------------------------------------------  
  631. " 用于括号与引号自动补全,不过会与函数原型提示插件echofunc冲突  
  632. " 所以我就没有加入echofunc插件  
  633.    
  634. " -----------------------------------------------------------------------------  
  635. "  < BufExplorer 插件配置 >  
  636. " -----------------------------------------------------------------------------  
  637. " 快速轻松的在缓存中切换(相当于另一种多个文件间的切换方式)  
  638. " <Leader>be 在当前窗口显示缓存列表并打开选定文件  
  639. " <Leader>bs 水平分割窗口显示缓存列表,并在缓存列表窗口中打开选定文件  
  640. " <Leader>bv 垂直分割窗口显示缓存列表,并在缓存列表窗口中打开选定文件  
  641.    
  642. " -----------------------------------------------------------------------------  
  643. "  < ccvext.vim 插件配置 >  
  644. " -----------------------------------------------------------------------------  
  645. " 用于对指定文件自动生成tags与cscope文件并连接  
  646. " 如果是Windows系统, 则生成的文件在源文件所在盘符根目录的.symbs目录下(如: X:\.symbs\)  
  647. " 如果是Linux系统, 则生成的文件在~/.symbs/目录下  
  648. " 具体用法可参考www.vim.org中此插件的说明  
  649. " <Leader>sy 自动生成tags与cscope文件并连接  
  650. " <Leader>sc 连接已存在的tags与cscope文件  
  651.    
  652. " -----------------------------------------------------------------------------  
  653. "  < cSyntaxAfter 插件配置 >  
  654. " -----------------------------------------------------------------------------  
  655. " 高亮括号与运算符等  
  656. au! BufRead,BufNewFile,BufEnter *.{c,cpp,h,java,javascript} call CSyntaxAfter()  
  657.    
  658. " -----------------------------------------------------------------------------  
  659. "  < ctrlp.vim 插件配置 >  
  660. " -----------------------------------------------------------------------------  
  661. " 一个全路径模糊文件,缓冲区,最近最多使用,... 检索插件;详细帮助见 :h ctrlp  
  662. " 常规模式下输入:Ctrl + p 调用插件  
  663.    
  664. " -----------------------------------------------------------------------------  
  665. "  < emmet-vim(前身为Zen coding) 插件配置 >  
  666. " -----------------------------------------------------------------------------  
  667. " HTML/CSS代码快速编写神器,详细帮助见 :h emmet.txt  
  668.    
  669. " -----------------------------------------------------------------------------  
  670. "  < indentLine 插件配置 >  
  671. " -----------------------------------------------------------------------------  
  672. " 用于显示对齐线,与 indent_guides 在显示方式上不同,根据自己喜好选择了  
  673. " 在终端上会有屏幕刷新的问题,这个问题能解决有更好了  
  674. " 开启/关闭对齐线  
  675. nmap <leader>il :IndentLinesToggle<CR>  
  676.    
  677. " 设置Gvim的对齐线样式  
  678. if g:isGUI  
  679.     let g:indentLine_char = "┊"  
  680.     let g:indentLine_first_char = "┊"  
  681. endif  
  682.    
  683. " 设置终端对齐线颜色,如果不喜欢可以将其注释掉采用默认颜色  
  684. let g:indentLine_color_term = 239  
  685.    
  686. " 设置 GUI 对齐线颜色,如果不喜欢可以将其注释掉采用默认颜色  
  687. " let g:indentLine_color_gui = '#A4E57E'  
  688.    
  689. " -----------------------------------------------------------------------------  
  690. "  < vim-javacompleteex(也就是 javacomplete 增强版)插件配置 >  
  691. " -----------------------------------------------------------------------------  
  692. " java 补全插件  
  693.    
  694. " -----------------------------------------------------------------------------  
  695. "  < Mark--Karkat(也就是 Mark) 插件配置 >  
  696. " -----------------------------------------------------------------------------  
  697. " 给不同的单词高亮,表明不同的变量时很有用,详细帮助见 :h mark.txt  
  698.    
  699. " " -----------------------------------------------------------------------------  
  700. " "  < MiniBufExplorer 插件配置 >  
  701. " " -----------------------------------------------------------------------------  
  702. " " 快速浏览和操作Buffer  
  703. " " 主要用于同时打开多个文件并相与切换  
  704.    
  705. " " let g:miniBufExplMapWindowNavArrows = 1     "用Ctrl加方向键切换到上下左右的窗口中去  
  706. " let g:miniBufExplMapWindowNavVim = 1        "用<C-k,j,h,l>切换到上下左右的窗口中去  
  707. " let g:miniBufExplMapCTabSwitchBufs = 1      "功能增强(不过好像只有在Windows中才有用)  
  708. " "                                            <C-Tab> 向前循环切换到每个buffer上,并在但前窗口打开  
  709. " "                                            <C-S-Tab> 向后循环切换到每个buffer上,并在当前窗口打开  
  710.    
  711. " 在不使用 MiniBufExplorer 插件时也可用<C-k,j,h,l>切换到上下左右的窗口中去  
  712. noremap <c-k> <c-w>k  
  713. noremap <c-j> <c-w>j  
  714. noremap <c-h> <c-w>h  
  715. noremap <c-l> <c-w>l  
  716.    
  717. " -----------------------------------------------------------------------------  
  718. "  < neocomplcache 插件配置 >  
  719. " -----------------------------------------------------------------------------  
  720. " 关键字补全、文件路径补全、tag补全等等,各种,非常好用,速度超快。  
  721. let g:neocomplcache_enable_at_startup = 1     "vim 启动时启用插件  
  722. " let g:neocomplcache_disable_auto_complete = 1 "不自动弹出补全列表  
  723. " 在弹出补全列表后用 <c-p> 或 <c-n> 进行上下选择效果比较好  
  724.    
  725. " -----------------------------------------------------------------------------  
  726. "  < nerdcommenter 插件配置 >  
  727. " -----------------------------------------------------------------------------  
  728. " 我主要用于C/C++代码注释(其它的也行)  
  729. " 以下为插件默认快捷键,其中的说明是以C/C++为例的,其它语言类似  
  730. " <Leader>ci 以每行一个 /* */ 注释选中行(选中区域所在行),再输入则取消注释  
  731. " <Leader>cm 以一个 /* */ 注释选中行(选中区域所在行),再输入则称重复注释  
  732. " <Leader>cc 以每行一个 /* */ 注释选中行或区域,再输入则称重复注释  
  733. " <Leader>cu 取消选中区域(行)的注释,选中区域(行)内至少有一个 /* */  
  734. " <Leader>ca 在/*...*///这两种注释方式中切换(其它语言可能不一样了)  
  735. " <Leader>cA 行尾注释  
  736. let NERDSpaceDelims = 1                     "在左注释符之后,右注释符之前留有空格  
  737.    
  738. " -----------------------------------------------------------------------------  
  739. "  < nerdtree 插件配置 >  
  740. " -----------------------------------------------------------------------------  
  741. " 有目录村结构的文件浏览插件  
  742.    
  743. " 常规模式下输入 F2 调用插件  
  744. "nmap <F2> :NERDTreeToggle<CR>  
  745.    
  746. " -----------------------------------------------------------------------------  
  747. "  < omnicppcomplete 插件配置 >  
  748. " -----------------------------------------------------------------------------  
  749. " 用于C/C++代码补全,这种补全主要针对命名空间、类、结构、共同体等进行补全,详细  
  750. " 说明可以参考帮助或网络教程等  
  751. " 使用前先执行如下 ctags 命令(本配置中可以直接使用 ccvext 插件来执行以下命令)  
  752. " ctags -R --c++-kinds=+p --fields=+iaS --extra=+q  
  753. " 我使用上面的参数生成标签后,对函数使用跳转时会出现多个选择  
  754. " 所以我就将--c++-kinds=+p参数给去掉了,如果大侠有什么其它解决方法希望不要保留呀  
  755. filetype plugin on  
  756. set completeopt=menu                        "关闭预览窗口  
  757. set nocp  
  758. set ofu=syntaxcomplete#Complete  
  759. set tags+=tags  
  760. set completeopt=menu,longest,menuone  
  761.   
  762. let OmniCpp_NamespaceSearch=2  
  763. let OmniCpp_GlobalScopeSearch=1  
  764. let OmniCpp_ShowAccess=1  
  765. let OmniCpp_ShowPrototypeInAbbr=1  
  766. let OmniCpp_MayCompleteDot=1     
  767. let OmniCpp_MayCompleteArrow=1  
  768. let OmniCpp_MayCompleteScope=1  
  769. let OmniCpp_DefaultNamespaces=["std""_GLIBCXX_STD"]  
  770. let OmniCpp_SelectFirstItem=2  
  771. let OmniCpp_DisplayMode=1  
  772.   
  773. au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif  
  774.    
  775. " -----------------------------------------------------------------------------  
  776. "  < powerline 插件配置 >  
  777. " -----------------------------------------------------------------------------  
  778. " 状态栏插件,更好的状态栏效果  
  779.    
  780. " -----------------------------------------------------------------------------  
  781. "  < repeat 插件配置 >  
  782. " -----------------------------------------------------------------------------  
  783. " 主要用"."命令来重复上次插件使用的命令  
  784.    
  785. " -----------------------------------------------------------------------------  
  786. "  < snipMate 插件配置 >  
  787. " -----------------------------------------------------------------------------  
  788. " 用于各种代码补全,这种补全是一种对代码中的词与代码块的缩写补全,详细用法可以参  
  789. " 考使用说明或网络教程等。不过有时候也会与 supertab 插件在补全时产生冲突,如果大  
  790. " 侠有什么其它解决方法希望不要保留呀  
  791.    
  792. " -----------------------------------------------------------------------------  
  793. "  < SrcExpl 插件配置 >  
  794. " -----------------------------------------------------------------------------  
  795. " 增强源代码浏览,其功能就像Windows中的"Source Insight"  
  796. "nmap <F3> :SrcExplToggle<CR>                "打开/闭浏览窗口  
  797.    
  798. " -----------------------------------------------------------------------------  
  799. "  < std_c 插件配置 >  
  800. " -----------------------------------------------------------------------------  
  801. " 用于增强C语法高亮  
  802.    
  803. " 启用 // 注视风格  
  804. let c_cpp_comments = 0  
  805.    
  806. " -----------------------------------------------------------------------------  
  807. "  < surround 插件配置 >  
  808. " -----------------------------------------------------------------------------  
  809. " 快速给单词/句子两边增加符号(包括html标签),缺点是不能用"."来重复命令  
  810. " 不过 repeat 插件可以解决这个问题,详细帮助见 :h surround.txt  
  811.    
  812. " -----------------------------------------------------------------------------  
  813. "  < Syntastic 插件配置 >  
  814. " -----------------------------------------------------------------------------  
  815. " 用于保存文件时查检语法  
  816.    
  817. " -----------------------------------------------------------------------------  
  818. "  < Tagbar 插件配置 >  
  819. " -----------------------------------------------------------------------------  
  820. " 相对 TagList 能更好的支持面向对象  
  821.    
  822. " 常规模式下输入 tb 调用插件,如果有打开 TagList 窗口则先将其关闭  
  823. nmap tb :TlistClose<CR>:TagbarToggle<CR>  
  824.    
  825. let g:tagbar_width=30                       "设置窗口宽度  
  826. " let g:tagbar_left=1                         "在左侧窗口中显示  
  827.    
  828. " -----------------------------------------------------------------------------  
  829. "  < TagList 插件配置 >  
  830. " -----------------------------------------------------------------------------  
  831. " 高效地浏览源码, 其功能就像vc中的workpace  
  832. " 那里面列出了当前文件中的所有宏,全局变量, 函数名等  
  833.    
  834. " 常规模式下输入 tl 调用插件,如果有打开 Tagbar 窗口则先将其关闭  
  835. nmap tl :TagbarClose<CR>:Tlist<CR>  
  836.    
  837. let Tlist_Show_One_File=1                   "只显示当前文件的tags  
  838. " let Tlist_Enable_Fold_Column=0              "使taglist插件不显示左边的折叠行  
  839. let Tlist_Exit_OnlyWindow=1                 "如果Taglist窗口是最后一个窗口则退出Vim  
  840. let Tlist_File_Fold_Auto_Close=1            "自动折叠  
  841. let Tlist_WinWidth=30                       "设置窗口宽度  
  842. let Tlist_Use_Right_Window=1                "在右侧窗口中显示  
  843.    
  844. " -----------------------------------------------------------------------------  
  845. "  < txtbrowser 插件配置 >  
  846. " -----------------------------------------------------------------------------  
  847. " 用于文本文件生成标签与与语法高亮(调用TagList插件生成标签,如果可以)  
  848. au BufRead,BufNewFile *.txt setlocal ft=txt  
  849.    
  850. " -----------------------------------------------------------------------------  
  851. "  < ZoomWin 插件配置 >  
  852. " -----------------------------------------------------------------------------  
  853. " 用于分割窗口的最大化与还原  
  854. " 常规模式下按快捷键 <c-w>o 在最大化与还原间切换  
  855.    
  856. " =============================================================================  
  857. "                          << 以下为常用工具配置 >>  
  858. " =============================================================================  
  859.    
  860. " -----------------------------------------------------------------------------  
  861. "  < cscope 工具配置 >  
  862. " -----------------------------------------------------------------------------  
  863. " 用Cscope自己的话说 - "你可以把它当做是超过频的ctags"  
  864. if has("cscope")  
  865.     "设定可以使用 quickfix 窗口来查看 cscope 结果  
  866.     set cscopequickfix=s-,c-,d-,i-,t-,e-  
  867.     "使支持用 Ctrl+]  和 Ctrl+t 快捷键在代码间跳转  
  868.     set cscopetag  
  869.     "如果你想反向搜索顺序设置为1  
  870.     set csto=0  
  871.     "在当前目录中添加任何数据库  
  872.     if filereadable("cscope.out")  
  873.         cs add cscope.out  
  874.     "否则添加数据库环境中所指出的  
  875.     elseif $CSCOPE_DB != ""  
  876.         cs add $CSCOPE_DB  
  877.     endif  
  878.     set cscopeverbose  
  879.     "快捷键设置  
  880.      nmap ss :cs find s <C-R>=expand("<cword>")<CR><CR>  
  881.     nmap sg :cs find g <C-R>=expand("<cword>")<CR><CR>  
  882.     nmap sc :cs find c <C-R>=expand("<cword>")<CR><CR>  
  883.     nmap st :cs find t <C-R>=expand("<cword>")<CR><CR>  
  884.     nmap se :cs find e <C-R>=expand("<cword>")<CR><CR>  
  885.     nmap sf :cs find f <C-R>=expand("<cfile>")<CR><CR>  
  886.     nmap si :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>  
  887.     nmap sd :cs find d <C-R>=expand("<cword>")<CR><CR>  
  888. endif  
  889.    
  890. " -----------------------------------------------------------------------------  
  891. "  < ctags 工具配置 >  
  892. " -----------------------------------------------------------------------------  
  893. " 对浏览代码非常的方便,可以在函数,变量之间跳转等  
  894. set tags=./tags;                            "向上级目录递归查找tags文件(好像只有在Windows下才有用)  
  895.   
  896. " -----------------------------------------------------------------------------  
  897. "< winManager 工具配置 >  
  898. " -----------------------------------------------------------------------------  
  899. let g:AutoOpenWinManager=1  
  900. let g:winManagerWindowLayout='FileExplorer|TagList'  
  901. nmap wm :WMToggle<cr>  
  902. map <silent> <F3> :WMToggle<cr>  
  903.    
  904. " -----------------------------------------------------------------------------  
  905. "  < gvimfullscreen 工具配置 > 请确保已安装了工具  
  906. " -----------------------------------------------------------------------------  
  907. " 用于 Windows Gvim 全屏窗口,可用 F11 切换  
  908. " 全屏后再隐藏菜单栏、工具栏、滚动条效果更好  
  909. if (g:iswindows && g:isGUI)  
  910.     nmap <F11> <Esc>:call libcallnr("gvimfullscreen.dll""ToggleFullScreen", 0)<CR>  
  911. endif  
  912.    
  913. " -----------------------------------------------------------------------------  
  914. "  < vimtweak 工具配置 > 请确保以已装了工具  
  915. " -----------------------------------------------------------------------------  
  916. " 这里只用于窗口透明与置顶  
  917. " 常规模式下 Ctrl + Up(上方向键) 增加不透明度,Ctrl + Down(下方向键) 减少不透明度,<Leader>t 窗口置顶与否切换  
  918. if (g:iswindows && g:isGUI)  
  919.     let g:Current_Alpha = 255  
  920.     let g:Top_Most = 0  
  921.     func! Alpha_add()  
  922.         let g:Current_Alpha = g:Current_Alpha + 10  
  923.         if g:Current_Alpha > 255  
  924.             let g:Current_Alpha = 255  
  925.         endif  
  926.         call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)  
  927.     endfunc  
  928.     func! Alpha_sub()  
  929.         let g:Current_Alpha = g:Current_Alpha - 10  
  930.         if g:Current_Alpha < 155  
  931.             let g:Current_Alpha = 155  
  932.         endif  
  933.         call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)  
  934.     endfunc  
  935.     func! Top_window()  
  936.         if  g:Top_Most == 0  
  937.             call libcallnr("vimtweak.dll","EnableTopMost",1)  
  938.             let g:Top_Most = 1  
  939.         else  
  940.             call libcallnr("vimtweak.dll","EnableTopMost",0)  
  941.             let g:Top_Most = 0  
  942.         endif  
  943.     endfunc  
  944.    
  945.     "快捷键设置  
  946.     nmap <c-up> :call Alpha_add()<CR>  
  947.     nmap <c-down> :call Alpha_sub()<CR>  
  948.     nmap <leader>t :call Top_window()<CR>  
  949. endif  
  950.   
  951. " -----------------------------------------------------------------------------  
  952. "  < 自动注释 工具配置 >  
  953. " -----------------------------------------------------------------------------  
  954.   
  955. map fg : Dox<cr>  
  956. let g:DoxygenToolkit_authorName="zhangbo E-mail:zhangbo@hisome.com"  
  957. let g:DoxygenToolkit_licenseTag="My own license\<enter>"  
  958. let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"  
  959. let g:DoxygenToolkit_briefTag_pre = "@brief\t"  
  960. let g:DoxygenToolkit_paramTag_pre = "@param\t"  
  961. let g:DoxygenToolkit_returnTag = "@return\t"  
  962. let g:DoxygenToolkit_briefTag_funcName = "no"  
  963. let g:DoxygenToolkit_maxFunctionProtoLines = 30  
  964.    
  965. " =============================================================================  
  966. "                          << 以下为常用自动命令配置 >>  
  967. " =============================================================================  
  968.    
  969. " 自动切换目录为当前编辑文件所在目录  
  970. au BufRead,BufNewFile,BufEnter * cd %:p:h  
  971.    
  972. " =============================================================================  
  973. "                          << 其它 >>  
  974. " =============================================================================  
  975. " 注:上面配置中的"<Leader>"在本软件中设置为"\"键(引号里的反斜杠),如<Leader>t  
  976. " 指在常规模式下按"\"键加"t"键,这里不是同时按,而是先按"\"键后按"t"键,间隔在一  
  977. " 秒内,而<Leader>cs是先按"\"键再按"c"又再按"s"键;如要修改"<leader>"键,可以把  
  978. " 下面的设置取消注释,并修改双引号中的键为你想要的,如修改为逗号键。  
  979.    
  980. " let mapleader = ","  

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值