Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1427|回复: 0
打印 上一主题 下一主题

【vim】插件管理及代码智能提示与补全环境的配置

[复制链接]

1228

主题

1997

帖子

7578

积分

认证用户组

Rank: 5Rank: 5

积分
7578
跳转到指定楼层
楼主
发表于 2019-4-11 16:36:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Qter 于 2019-4-12 16:17 编辑

https://www.cnblogs.com/zzqcn/p/4660615.html

这儿http://vim-scripts.org/vim/scripts.html 是一份vim扩展脚本的列表。

  • 管理插件的插件(插件管理器)
  • 最喜欢的配色方案
  • Doxygen注释自动生成
  • 代码智能提示与补全
2. 插件管理器
Vundle是一个流行的vim插件管理器,它的网址是https://github.com/VundleVim/Vundle.vim


以下是安装步骤:
  1. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2. " Vundle
  3. set nocompatible              " be iMproved, required
  4. filetype off                  " required

  5. " set the runtime path to include Vundle and initialize
  6. set rtp+=~/.vim/bundle/Vundle.vim
  7. call vundle#begin()
  8. " alternatively, pass a path where Vundle should install plugins
  9. "call vundle#begin('~/some/path/here')

  10. " let Vundle manage Vundle, required
  11. Plugin 'VundleVim/Vundle.vim'

  12. " The following are examples of different formats supported.
  13. " Keep Plugin commands between vundle#begin/end.
  14. " plugin on GitHub repo
  15. "Plugin 'tpope/vim-fugitive'
  16. " plugin from http://vim-scripts.org/vim/scripts.html
  17. "Plugin 'L9'
  18. " Git plugin not hosted on GitHub
  19. "Plugin 'git://git.wincent.com/command-t.git'
  20. " git repos on your local machine (i.e. when working on your own plugin)
  21. "Plugin 'file:///home/gmarik/path/to/plugin'
  22. " The sparkup vim script is in a subdirectory of this repo called vim.
  23. " Pass the path to set the runtimepath properly.
  24. "Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
  25. " Avoid a name conflict with L9
  26. "Plugin 'user/L9', {'name': 'newL9'}

  27. " All of your Plugins must be added before the following line
  28. call vundle#end()            " required
  29. filetype plugin indent on    " required
  30. " To ignore plugin indent changes, instead use:
  31. "filetype plugin on
  32. "
  33. " Brief help
  34. " :PluginList       - lists configured plugins
  35. " :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
  36. " :PluginSearch foo - searches for foo; append `!` to refresh local cache
  37. " :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
  38. "
  39. " see :h vundle for more details or wiki for FAQ
  40. " Put your non-Plugin stuff after this line


  41. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
复制代码


打开vim,运行 : PluginInstall 命令来自动安装插件,过程中有可能需要输入github用户名和密码。等待Vundle安装完成即可。


3. 配色方案
vim默认有一些配色方案,如果这些都不喜欢,可以从网上下载安装别的配色方案。solarized和molokai都是流行的配色方案,然而这两个主题在终端(terminal)模式下或者SecureCRT上使用都会有一些问题,而我目前最喜欢的khaki没有这个问题,它的样子如下图所示(其中设置了行号、当前号高亮、语法高亮等)
安装步骤:
  • 在~/.vimrc中的Vundle插件列表区域中添加khaki的源位置
    Plugin 'vim-scripts/khaki.vim'
    保存后退出,再打开vim,运行: PluginInstall命令安装。
  • 在~/.vimrc中,Vundle区域后面的某处,添加
    1. if !has("gui_running")                                          
    2.     set t_Co=256                                                
    3. endif                                                                                         
    4. colorscheme khaki
    复制代码
    保存后重启vim即可。

4. Doxygen注释自动生成
为自己的代码写好注释是一个良好的习惯,而编写Doxygen风格的注释更是可以通过doxygen工具为代码自己生成文档,非常好用。DoxygenToolkit(https://github.com/vim-scripts/DoxygenToolkit.vim)就是这样的一个插件。安装和使用:
  • 在~/.vimrc中的Vundle插件列表区域中添加DoxygenToolkit的源位置
    Plugin 'vim-scripts/DoxygenToolkit.vim'
    保存后退出,再打开vim,运行: PluginInstall命令安装
  • 在~.vimrc中,Vundle区域后的某处,设置DoxygenToolkit插件在@author区域自动填充的作者名称,比如
  1. let g:DoxygenToolkit_authorName="he_chengjin@outlook.com"
复制代码

  • 使用时,将光标定位到文件首行,输入: DoxAuthor将插入文件头注释骨架(第一次会让你输入文件版本号),如下:

  1. /**                                                               
  2.    * @file test.cpp                                                  
  3.    * @brief                                                                                       
  4.    * @author zzp@moon.net                                            
  5.    * @version 1.0                                                   
  6.    * @date 2015-08-21                                                
  7.    */
复制代码
并把光标停留在@brief 后面,等待输入文件描述。
在光标定位到数据结构声明或函数声明的第一行,运行: Dox,将生成数据结构或函数的注释骨架,如下:
  1. /**                                                            
  2.    * @brief                                                      
  3.    */                                                            
  4.   struct foo                                                      
  5.   {                                                               
  6.       char str;                                                   
  7.       void* ptr;                                                  
  8.   };                                                              
  9.                                                                   
  10.   /**                                                            
  11.    * @brief                                                      
  12.    *                                                                                             
  13.    * @param a                                                     
  14.    * @param b                                                     
  15.    *                                                              
  16.    * @return                                                      
  17.    */                                                            
  18.   int bar(int a, int b)                                          
  19.   {                                                               
  20.       return a+b;                                                
  21.   }
复制代码


5. 代码智能提示与补全
写代码的时候,变量名、函数名、类名等代码符号的智能提示和补全功能是非常有用的,可以大大提高编码效率。然而,在YouCompleteMe(简称YCM)这个神奇的插件出现之前,vim一直使用tag机制来完成这个功能。由于tag只会笨拙地分析代码中的字符串,并不能识别其语法说语义,导致代码的提示并不好用。随着clang的出现,使开发人员可以对程序代码进行事实上的语义分析(调用clang分析器之类的),于是真正的智能提示和补全插件出现了,它就是由 google 的工程师 Strahinja Val Markovic 所开发的YCM(https://github.com/Valloric/YouCompleteMe)。
5.1 YouCompleteMe的安装与配置
YCM使用C++和python开发,是一个复杂的插件,光是通过Vundle下载的文件就达到120多MB。另外YCM不只是有新的开发的功能,它还包含了其他一些有用的插件。下图是作者本人提示的演示动图:

除了代码提示与补全外,借助libclang强大的语法与语义分析能力,YCM还可以在编辑的时候提示出错的行与出错原因,如下图所示:
另外,YCM还可以补全路径,文件名等。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-4-29 08:45 , Processed in 0.076496 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表