工欲善其事,必先利其器。在開發過程中,方便、快捷的開發環境,能提高工作效率;優美的界面能讓我們心情愉悅;最重要的是,能保持我們在外行嚴重高深莫測的牛逼~
如果在創建新的源程序文件時希望能自動產生一些注釋,比如作者、創建日期,聯系方式等,可以這樣做:
編輯~/.vimrc 文件,加入代碼:
/* 當新建 .h .c .hpp .cpp 等文件時自動調用SetTitle 函數*/ autocmd BufNewFile *.[ch],*.hpp,*.cpp exec ":call SetTitle()" /* 加入注釋 */ func SetComment() call setline(1,"/*==================================") call append(line("."), "* Copyright (C) ".strftime("%Y")." All rights reserved.") call append(line(".")+1, "* ") call append(line(".")+2, "* 文件名稱:".expand("%:t")) call append(line(".")+3, "* 創 建 者:herb") call append(line(".")+4, "* 創建日期:".strftime("%Y年%m月%d日")) call append(line(".")+5, "* 描 述:") call append(line(".")+6, "*") call append(line(".")+7, "================================================================*/") endfunc /* 定義函數SetTitle,自動插入文件頭 */ func SetTitle() call SetComment() if expand("%:e") == 'hpp' call append(line(".")+8, "#ifndef _".toupper(expand("%:t:r"))."_H") call append(line(".")+9, "#define _".toupper(expand("%:t:r"))."_H") call append(line(".")+10, "#ifdef __cplusplus") call append(line(".")+11, "extern \"C\"") call append(line(".")+12, "{") call append(line(".")+13, "#endif") call append(line(".")+14, "") call append(line(".")+15, "#ifdef __cplusplus") call append(line(".")+16, "}") call append(line(".")+17, "#endif") call append(line(".")+18, "#endif //".toupper(expand("%:t:r"))."_H") elseif expand("%:e") == 'h' call append(line(".")+8, "#pragma once") elseif &filetype == 'c' call append(line(".")+8,"#include \"".expand("%:t:r").".h\"") elseif &filetype == 'cpp' call append(line(".")+8, "#include \"".expand("%:t:r").".h\"") endif endfunc