Qter 发表于 2019-4-11 16:36:00

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

本帖最后由 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

以下是安装步骤:
[*]git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
如果目录.vim/bundle不存在请先创建
[*]打开~/.vimrc,在文件头加入以下内容
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vundle
set nocompatible            " be iMproved, required
filetype off                  " required

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

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

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

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


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

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


3. 配色方案vim默认有一些配色方案,如果这些都不喜欢,可以从网上下载安装别的配色方案。solarized和molokai都是流行的配色方案,然而这两个主题在终端(terminal)模式下或者SecureCRT上使用都会有一些问题,而我目前最喜欢的khaki没有这个问题,它的样子如下图所示(其中设置了行号、当前号高亮、语法高亮等)https://images0.cnblogs.com/blog2015/520290/201508/211457213948245.png安装步骤:
[*]在~/.vimrc中的Vundle插件列表区域中添加khaki的源位置
Plugin 'vim-scripts/khaki.vim'
保存后退出,再打开vim,运行: PluginInstall命令安装。
[*]在~/.vimrc中,Vundle区域后面的某处,添加if !has("gui_running")                                          
    set t_Co=256                                                
endif                                                                                       
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区域自动填充的作者名称,比如
let g:DoxygenToolkit_authorName="he_chengjin@outlook.com"

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

/**                                                               
   * @file test.cpp                                                
   * @brief                                                                                       
   * @author zzp@moon.net                                          
   * @version 1.0                                                   
   * @date 2015-08-21                                                
   */并把光标停留在@brief 后面,等待输入文件描述。
在光标定位到数据结构声明或函数声明的第一行,运行: Dox,将生成数据结构或函数的注释骨架,如下:/**                                                            
   * @brief                                                      
   */                                                            
struct foo                                                      
{                                                               
      char str;                                                   
      void* ptr;                                                
};                                                            
                                                                  
/**                                                            
   * @brief                                                      
   *                                                                                             
   * @param a                                                   
   * @param b                                                   
   *                                                            
   * @return                                                      
   */                                                            
int bar(int a, int b)                                          
{                                                               
      return a+b;                                                
}

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不只是有新的开发的功能,它还包含了其他一些有用的插件。下图是作者本人提示的演示动图:https://images0.cnblogs.com/blog2015/520290/201508/211543058945772.gif
https://images0.cnblogs.com/blog2015/520290/201508/211543058945772.gif除了代码提示与补全外,借助libclang强大的语法与语义分析能力,YCM还可以在编辑的时候提示出错的行与出错原因,如下图所示:https://images0.cnblogs.com/blog2015/520290/201508/241618022497532.png另外,YCM还可以补全路径,文件名等。
页: [1]
查看完整版本: 【vim】插件管理及代码智能提示与补全环境的配置