我的VIM配置(C/C++和PHP)

19 篇文章 0 订阅

http://blog.csdn.net/wh_luosangnanka5/article/details/7779139

首先找到配置文件位置, 我的系统是Ubuntu 12.04, 安装的vim是vim 7.3, 如果你不知道你的配置文件在哪里的话,就随便使用vim打开一个文件vim test, 输入:version即可看到你的vimrc位置,然后使用命令

[php]  view plain copy
  1. cp /usr/share/vim/vimrc /home/root  
  2. mv ~/vimrc ~/.vimrc  

你的主目录下的.vimrc文件即是你的配置文件

    如果你使用插件, 下载后插件放置位置即在~/.vim/plugin下(没有即可则新建), 帮助文档放在~/.vim/doc下(没有即可则新建)

    我使用的插件有:

        CtagsTaglista.vimc.vimminibufexpl.vim、perdirvimrc.vimphp-doc.vimphp.vimprojtags.vim


配置文件如下,如果有补充欢迎邮件交流:jiangyeziwh@gmail.com:

[plain]  view plain copy
  1. " 在处理未保存或只读文件的时候,弹出确认  
  2. set confirm  
  3. " 带有如下符号的单词不要被换行分割  
  4. set iskeyword+=_,$,@,%,#,-  
  5. " 不使用vi默认键盘布局  
  6. set nocompatible  
  7.   
  8. "设置编码  
  9. set encoding=utf-8  
  10. set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936  
  11. set fileencodings=utf-8,ucs-bom,chinese  
  12.   
  13. "语言设置  
  14. set langmenu=zh_CN.UTF-8  
  15.   
  16. " 显示行号  
  17. set number    
  18. " 智能对齐  
  19. set smartindent   
  20. " 括号匹配模式   
  21. set showmatch  
  22. " 显示状态行     
  23. set ruler    
  24.   
  25. "设置配色方案  
  26. colorscheme torte  
  27.   
  28. "可以在buffer的任何地方使用鼠标  
  29. set mouse=a  
  30. set selection=exclusive  
  31. set selectmode=mouse,key  
  32.   
  33. set incsearch                                
  34. " tab键为4个空格  
  35. set tabstop=4  
  36. set shiftwidth=4   
  37. set softtabstop=4  
  38. " 自动对齐  
  39. set autoindent   
  40. if &term=="xterm"  
  41.     set t_Co=8  
  42.     set t_Sb=^[[4%dm  
  43.     set t_Sf=^[[3%dm  
  44. endif  
  45.   
  46. " C语言格式对齐  
  47. set cindent                
  48. " 不要备份文件  
  49. set nobackup               
  50. " 与windows共享剪贴板   
  51. set clipboard+=unnamed     
  52.   
  53. syntax on   
  54. "打开文件类型自动检测功能  
  55. filetype on         
  56.   
  57. "设置taglist  
  58. "显示多个文件的tags  
  59. let Tlist_Show_One_File=0     
  60. "非当前文件,函数列表折叠隐藏  
  61. let Tlist_File_Fold_Auto_Close=1   
  62. "在taglist是最后一个窗口时退出vim  
  63. let Tlist_Exit_OnlyWindow=1   
  64. "单击时跳转  
  65. let Tlist_Use_SingleClick=1   
  66. "打开taglist时获得输入焦点  
  67. let Tlist_GainFocus_On_ToggleOpen=1   
  68. "不管taglist窗口是否打开,始终解析文件中的tag  
  69. let Tlist_Process_File_Always=1   
  70. nmap <F7> :TlistToggle <CR>  
  71.   
  72. " 配置cvim  
  73. filetype plugin on  
  74.   
  75. " C的编译和运行  
  76. map <F5> :call CompileRunGcc()<CR>  
  77. func! CompileRunGcc()  
  78. exec "w"  
  79. exec "!gcc % -o %<"  
  80. exec "! ./%<"  
  81. endfunc  
  82.   
  83. " C++的编译和运行  
  84. map <F6> :call CompileRunGpp()<CR>  
  85. func! CompileRunGpp()  
  86. exec "w"  
  87. exec "!g++ % -o %<"  
  88. exec "! ./%<"  
  89. endfunc  
  90.   
  91. " =====================================================  
  92. "       PHP  
  93. " =====================================================  
  94. " The php doc plugin  
  95. " source ~/.vim/php-doc.vim  
  96. inoremap <C-P> <ESC>:call PhpDocSingle()<CR>i  
  97. nnoremap <C-P> :call PhpDocSingle()<CR>  
  98. vnoremap <C-P> :call PhpDocRange()<CR>  
  99.    
  100. " run file with PHP CLI (CTRL-M)  
  101. :autocmd FileType php noremap <C-M> :w!<CR>:!/usr/bin/php %<CR>  
  102.    
  103. " PHP parser check (CTRL-L)  
  104. :autocmd FileType php noremap <C-L> :!/usr/bin/php -l %<CR>  
  105.    
  106. " Do use the currently active spell checking for completion though!  
  107. " (I love this feature :-)  
  108. set complete+=kspell  
  109.    
  110. " disable tabs  
  111. set expandtab  
  112. set shiftwidth=4  
  113. set softtabstop=4  
  114.    
  115. " highlt matches  
  116. set hlsearch  
  117.    
  118. " Taken from http://peterodding.com/code/vim/profile/vimrc  
  119. " Make Vim open and close folded text as needed because I can't be bothered to  
  120. " do so myself and wouldn't use text folding at all if it wasn't automatic.  
  121. set foldmethod=marker foldopen=all,insert foldclose=all  
  122.    
  123. " Enable enhanced command line completion.  
  124. set wildmenu wildmode=list:full  
  125.    
  126. " Ignore these filenames during enhanced command line completion.  
  127. set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files  
  128. set wildignore+=*.jpg,*.bmp,*.gif " binary images  
  129. set wildignore+=*.luac " Lua byte code  
  130. set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files  
  131. set wildignore+=*.pyc " Python byte code  
  132. set wildignore+=*.spl " compiled spelling word lists  
  133. set wildignore+=*.sw? " Vim swap files  
  134.    
  135. " Enable completion dictionaries for PHP buffers.  
  136. autocmd FileType php set complete+=k~/.vim/dict/PHP.dict  
  137.    
  138. " PHP Autocomplete  
  139. autocmd FileType php set omnifunc=phpcomplete#CompletePHP  
  140. set ofu=syntaxcomplete#Complete  
  141.    
  142. " You might also find this useful  
  143. " PHP Generated Code Highlights (HTML & SQL)  
  144. let php_sql_query=1  
  145. let php_htmlInStrings=1  
  146. let g:php_folding=2  
  147. set foldmethod=syntax  
  148.    
  149. " --------------------  
  150. " Project  
  151. " --------------------  
  152. map <A-S-p> :Project<CR>  
  153. map <A-S-o> :Project<CR>:redraw<CR>/  
  154. nmap <silent> <F3> <Plug>ToggleProject  
  155. "let g:proj_window_width = 30  
  156. "let g:proj_window_increment = 150  
  157.   
  158. nnoremap <silent> <F8> :TlistToggle<CR>  
  159. let Tlist_Exit_OnlyWindow = 1     " exit if taglist is last window open  
  160. let Tlist_Show_One_File = 1       " Only show tags for current buffer  
  161. let Tlist_Enable_Fold_Column = 0  " no fold column (only showing one file)  
  162. let tlist_sql_settings = 'sql;P:package;t:table'  
  163. let tlist_ant_settings = 'ant;p:Project;r:Property;t:Target'  
  164.    
  165. " auto change directory from: http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file  
  166. autocmd BufEnter * if expand("%:p:h") !~ '^/tmp' | lcd %:p:h | endif  
  167.    
  168. " when we reload, tell vim to restore the cursor to the saved position  
  169. augroup JumpCursorOnEdit  
  170.  au!  
  171.  autocmd BufReadPost *  
  172.  \ if expand("<afile>:p:h") !=? $TEMP |  
  173.  \ if line("'\"") > 1 && line("'\"") <= line("$") |  
  174.  \ let JumpCursorOnEdit_foo = line("'\"") |  
  175.  \ let b:doopenfold = 1 |  
  176.  \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |  
  177.  \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |  
  178.  \ let b:doopenfold = 2 |  
  179.  \ endif |  
  180.  \ exe JumpCursorOnEdit_foo |  
  181.  \ endif |  
  182.  \ endif  
  183.  " Need to postpone using "zv" until after reading the modelines.  
  184.  autocmd BufWinEnter *  
  185.  \ if exists("b:doopenfold") |  
  186.  \ exe "normal zv" |  
  187.  \ if(b:doopenfold > 1) |  
  188.  \ exe "+".1 |  
  189.  \ endif |  
  190.  \ unlet b:doopenfold |  
  191.  \ endif  
  192. augroup END  
  193.    
  194. " PHP code sniffer  
  195. " If code sniffer is installed you can run it on current php file by running  
  196. " :Phpcs  
  197. function! RunPhpcs()  
  198.     let l:filename=@%  
  199.     let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)  
  200. "    echo l:phpcs_output  
  201.     let l:phpcs_list=split(l:phpcs_output, "\n")  
  202.     unlet l:phpcs_list[0]  
  203.     cexpr l:phpcs_list  
  204.     cwindow  
  205. endfunction  
  206.   
  207. set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"  
  208. command! Phpcs execute RunPhpcs()  


快捷键说明:

F1:打开帮助

F3:打开项目管理

F5:编译C

F6:编译C++

F7:打开文件目录

F8:打开标签目录

Ctrl + L:PHP语法检查

Ctrl + N:PHP代码自动补全

Ctrl + P:添加PHP风格的代码注释



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值