下载地址:http://www.vim.org/scripts/script.php?script_id=987
将其拷贝到如下目录:
Linux版本是CentOS6.4的版本路径:/usr/share/vim/vim72/plugin/
Ubuntu系统路径:/usr/share/vim/vim73/plugin
修改配置文件:/etc/vimrc
"自动排版
map <F8> gg=G
"插入块注释 /* */
vmap <F9> dO*/<Esc>PO/*<Esc>
"插入条件编译注释
vmap <F10> dO#endif<Esc>PO#if 0<Esc>
"F11自动在当前位置插入日期
map <F11> i<C-R>=strftime("%Y-%m-%d %H:%M:%S")<CR><Esc>
"添加函数头注释
map <F12> <Esc>:Dox<cr>
1) F8:自动排版
用法:命令模式下(按下ESC,下同)直接按F8,将完成整个代码的排版,按C/C++缩进风格缩进。
2) F9:插入块注释
用法:命令模式下,按v键,选择要注释的部分,按下F9插入块注释,即 /*内容*/
3) F10:插入条件编译注释
用法:命令模式下,按v键,选择要注释的部分,按下F9插入编译注释,即#if 0 内容#endif
4) F11:自动在光标当前位置插入日期
用法:命令模式下,按F11
5) F12:添加函数头注释
用法:命令模式下,在函数的第一行按下F12
"设置C自动缩进,缩进4个字节
set cindent shiftwidth=4
"设置TAB缩进为4个字节
set tabstop=4
set expandtab
"设置命令模式下按SHIFT缩进为4个字节
set softtabstop=4
set shiftwidth=4
配置路径:每个用户目录下创建一个.vimrc文件(例如/home/chenqin/),内容如下:
func SetComment()
call setline(1,"/**************************************************************")
call append(line("."), "* Copyright (C) 2006-".strftime("%Y")." All rights reserved.")
call append(2,"* @Version: 1.0")
call append(3,"* @Created: " . strftime("%Y-%m-%d %H:%M"))
call append(4,"* @Author: chenqin - [email protected]")
call append(5,"* @Description: ")
call append(6,"*")
call append(7,"* @History: ")
call append(8,"**************************************************************/")
endfunc
func Setifdef()
call setline(1,"/**************************************************************")
call append(line("."), "* Copyright (C) 2006-".strftime("%Y")." All rights reserved.")
call append(2,"* @Version: 1.0")
call append(3,"* @Created: " . strftime("%Y-%m-%d %H:%M"))
call append(4,"* @Author: chenqin - [email protected]")
call append(5,"* @Description: ")
call append(6,"*")
call append(7,"* @History: ")
call append(8,"**************************************************************/")
call append(9,"#ifndef")
call append(10, "#define")
call append(11, "")
call append(12, "")
call append(13, "#endif")
endfunc
autocmd BufNewFile *.c,*.cpp exec ":call SetComment()"
autocmd BufNewFile *.h exec ":call Setifdef()"
Author:可以修改成自己的名字
修改/etc/vimrc配置如下:
"let g:DoxygenToolkit_briefTag_pre="@Name: "
let g:DoxygenToolkit_paramTag_pre="@Param: "
let g:DoxygenToolkit_returnTag ="Returns: "
"letg:DoxygenToolkit_blockHeader="/*******************************************************"
"let g:DoxygenToolkit_blockFooter="*******************************************************/"
"let g:DoxygenToolkit_authorName="chenqin,[email protected]"
let g:DoxygenToolkit_licenseTag="Copyright (C) Infogo Technology LimitedCompany"
let g:DoxygenToolkit_briefTag_funcName="yes"
let g:doxygen_enhanced_color=1
由于我在vim配置文件中设置了快捷键,在使用过程中我只需要在把光标定位到函数第一行按下F12就可以在函数前自动生成注释了。赋图一张,图(一)