vim+Doxygen实现注释自动生成
来源:互联网 发布:ubuntu没有vim命令 编辑:程序博客网 时间:2024/06/16 10:42
借鉴文章:https://www.cnblogs.com/zzqcn/p/4660615.html
为自己的代码写好注释是一个良好的习惯,而编写Doxygen风格的注释更是可以通过doxygen工具为代码自己生成文档,非常好用。DoxygenToolkit(https://github.com/vim-scripts/DoxygenToolkit.vim)就是这样的一个插件。Doxygen插件用Vundle插件管理器来自动安装,首先安装Vundle:
1、git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
如果目录.vim/bundle不存在请先创建
2、在~/.vimrc中添加如下内容
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Vundleset nocompatible " be iMproved, requiredfiletype off " required" set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()" alternatively, pass a path where Vundle should install plugins"call vundle#begin('~/some/path/here')" let Vundle manage Vundle, requiredPlugin '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 linecall vundle#end() " requiredfiletype 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"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
从其中的注释可以知道,Vundle支持多种形式的插件源,并给出了示例。这些插件源包括:github上的插件、http://vim-scripts.org/vim/scripts.html上的插件、非github上的git插件、本地硬盘上的插件等。
3、打开vim,运行 :PluginInstall 命令来自动安装插件,过程中有可能需要输入github用户名和密码。等待Vundle安装完成即可。
安装Doxygen:
在~/.vimrc中的Vundle插件列表区域中添加DoxygenToolkit的源位置
Plugin 'vim-scripts/DoxygenToolkit.vim'
.vimrc中Vundle区域如下:
保存后退出,再打开vim,运行:PluginInstall命令安装。
安装好Doxygen后,打开代码文件,即可通过:DoxLic,:DoxAuthor,:Dox添加license说明、作者版本说明和函数说明,我把license说明和作者版本说明整合了一下,并加入了公司名称的变量,并修改了作者版本说明字段对齐,这些修改在~/.vim/bundle/DoxygenToolkit.vim/plugin/DoxygenToolkit.vim中完成。代码如下:
先修改变量,licenseTag用COMPANY做公司名占位符,好用.vimrc中定义的公司名替换:
let s:licenseTag = "Unpublished copyright. All rights reserved. This material contains\<enter>"let s:licenseTag = s:licenseTag . "proprietary information that should be used or copied only within\<enter>"let s:licenseTag = s:licenseTag . "COMPANY, except with written permission of COMPANY.\<enter>"
if !exists("g:DoxygenToolkit_briefTag_lic_pre") let g:DoxygenToolkit_briefTag_lic_pre = "@brief: "endifif !exists("g:DoxygenToolkit_briefTag_pre") let g:DoxygenToolkit_briefTag_pre = "@brief: "endifif !exists("g:DoxygenToolkit_fileTag") let g:DoxygenToolkit_fileTag = "@file: "endifif !exists("g:DoxygenToolkit_authorTag") let g:DoxygenToolkit_authorTag = "@author: "endifif !exists("g:DoxygenToolkit_dateTag") let g:DoxygenToolkit_dateTag = "@date: "endifif !exists("g:DoxygenToolkit_versionTag") let g:DoxygenToolkit_versionTag = "@version: "endif
修改DoxygenLicenseFunc函数,整合作者版本信息,这里默认版本号为1.0,单独添加作者版本信息时要输入版本号
""""""""""""""""""""""""""" Doxygen license comment""""""""""""""""""""""""""function! <SID>DoxygenLicenseFunc() call s:InitializeParameters() " Test authorName variable if !exists("g:DoxygenToolkit_companyName") let g:DoxygenToolkit_companyName = input("Enter name of your company: ") endif if !exists("g:DoxygenToolkit_authorName") let g:DoxygenToolkit_authorName = input("Enter name of the author (generally yours...) : ") endif mark d " Get file name let l:fileName = expand('%:t') let l:year = strftime("%Y") let l:copyright = "Copyright (c) " let l:copyright = l:copyright.l:year." ".g:DoxygenToolkit_companyName."." let l:license = substitute( g:DoxygenToolkit_licenseTag, "\<enter>", "\<enter>".s:interCommentBlock, "g" ) let l:license = substitute( l:license, "COMPANY", g:DoxygenToolkit_companyName, "g" ) exec "normal O".s:startCommentBlock exec "normal o".s:interCommentTag.l:copyright."\<enter>".s:interCommentTag exec "normal o".s:interCommentTag.l:license exec "normal o".s:interCommentTag.g:DoxygenToolkit_fileTag.l:fileName exec "normal o".s:interCommentTag.g:DoxygenToolkit_briefTag_lic_pre mark d exec "normal o".s:interCommentTag.g:DoxygenToolkit_authorTag.g:DoxygenToolkit_authorName exec "normal o".s:interCommentTag.g:DoxygenToolkit_versionTag."1.0" let l:date = strftime("%Y-%m-%d") exec "normal o".s:interCommentTag.g:DoxygenToolkit_dateTag.l:date if( s:endCommentBlock != "" ) exec "normal o".s:endCommentBlock endif exec "normal `d" call s:RestoreParameters() startinsert!endfunction
然后在.vimrc增加如下代码块:
vi打开代码文件,即可通过快捷键进行代码注释了,公司名为xxxx,效果如下:
- vim+Doxygen实现注释自动生成
- doxygen + vim 自动生成C文档教程
- Doxygen生成文档注释
- Doxygen生成注释文档
- Doxygen生成注释文档
- 使用JavaDoc风格注释让doxygen自动生成文档
- Linux下使用doxygen自动生成注释和文档
- windows下vim和Doxygen自动生成代码文档
- windows下vim和Doxygen自动生成代码文档
- windows下vim和Doxygen自动生成代码文档
- 用doxygen为C/C++程序自动生成文档(二)-doxygen风格注释简介
- CentOS vim插件——Doxygen注释插件(用命令生成各种注释)
- vim自动生成main函数和自动添加注释
- doxygen使用~~用这个注释自动生成文档,炒鸡方便
- 用 Doxygen 自动生成文档
- doxygen --文档自动生成工具
- AutoHotkey辅助生成DoxyGen风格的注释
- xcode中使用Doxygen快速生成注释
- Android中putString()和getString()用法
- 关于list集合的remove和Iterator的remove
- c++与c# 在框架原理上的区别
- Java GC基本算法
- 大数据正式14
- vim+Doxygen实现注释自动生成
- “自顶向下,逐步求精”的方法
- c++ primer 8.1.2节练习(关于流的知识)
- 正则表达式基本语法之思维导图
- spring三种常用注入方式的测试与总结
- filter通过装饰者模式防止XSS攻击
- 机器学习小试(6)使用TensorFlow跑通一个通用增量学习流程-设计配置文件
- GROUP BY 与聚合函数 使用注意点
- 垃圾回收机制