Posted on 2010-07-29 12:26
浩毛 阅读(7692)
评论(1) 编辑 收藏 引用 所属分类:
杂七杂八
编辑~/.vimrc 加入以下代码
1 autocmd BufNewFile *.[ch],*.hpp,*.cpp exec ":call SetTitle()"
2
3 "加入注释
4 func SetComment()
5 call setline(1,"/*===============================================================")
6 call append(line("."), "* Copyright (C) ".strftime("%Y")." All rights reserved.")
7 call append(line(".")+1, "* ")
8 call append(line(".")+2, "* 文件名称:".expand("%:t"))
9 call append(line(".")+3, "* 创 建 者:蒋浩")
10 call append(line(".")+4, "* 创建日期:".strftime("%Y年%m月%d日"))
11 call append(line(".")+5, "* 描 述:")
12 call append(line(".")+6, "*")
13 call append(line(".")+7, "* 更新日志:")
14 call append(line(".")+8, "*")
15 call append(line(".")+9, "================================================================*/")
16 endfunc
17
18 "定义函数SetTitle,自动插入文件头
19 func SetTitle()
20 call SetComment()
21 if expand("%:e") == 'hpp'
22 call append(line(".")+10, "#ifndef _".toupper(expand("%:t:r"))."_H")
23 call append(line(".")+11, "#define _".toupper(expand("%:t:r"))."_H")
24 call append(line(".")+12, "#ifdef __cplusplus")
25 call append(line(".")+13, "extern \"C\"")
26 call append(line(".")+14, "{")
27 call append(line(".")+15, "#endif")
28 call append(line(".")+16, "")
29 call append(line(".")+17, "#ifdef __cplusplus")
30 call append(line(".")+18, "}")
31 call append(line(".")+19, "#endif")
32 call append(line(".")+20, "#endif //".toupper(expand("%:t:r"))."_H")
33 elseif expand("%:e") == 'h'
34 call append(line(".")+10, "#pragma once")
35 elseif &filetype == 'c'
36 call append(line(".")+10,"#include \"".expand("%:t:r").".h\"")
37 elseif &filetype == 'cpp'
38 call append(line(".")+10, "#include \"".expand("%:t:r").".h\"")
39 endif
40 endfunc
41