這裏是我的C++文件模板:
/*****************************************************************************
* @file <file_name>
*
* @date <date>
* @author John Doe
* @email [email protected]
*
* @brief
*
* @detail
*
*****************************************************************************/
這裏是我裏面~/.vimrc
:
" Reads the template file replacing the tags by the actual
" information and insert the result at the beginning of the buffer. At
" the end, creates two blank lines at the end of the file and
" position the cursor at the first one.
function! s:insert_description()
let template = $HOME . "/.vim/template/cpp.template"
let file_name = expand("%:t") " Get file name without path
let date = strftime("%Y") " Get the current year in format YYYY
let i = 0
for line in readfile(template)
let line = substitute(line, "<file_name>", file_name, "ge")
let line = substitute(line, "<date>", date, "ge")
call append(i, line)
let i += 1
endfor
execute "normal! Go\<Esc>k"
endfunction
autocmd BufNewFile *.{c++,cpp,cc,c,h,hpp} call <SID>insert_description()
基本上,我讀的模板文件替換標籤與實際信息和將結果插入新創建的文件的開始處。當vim創建一個新文件時,函數s:insert_description()
被調用。這由最後一行的autocmd
設置。
你可以根據這段代碼創建python的等價物。
文件創建和編輯日期以及作者身份和版本信息均由源代碼管理進行維護。我不明白用於在文件本身中添加冗餘(可能不準確或已過期)此信息副本的用例。將您的版權/許可證信息放入您的LICENSE文件中,並將其保留在源代碼之外。它在那裏沒有任何用處。項目版本信息應該在項目中的某處存在,而不是在每個文件的標題中。聯繫信息放在您的自述文件中。簡而言之,這些標籤都不屬於源代碼的頂部。 – 2013-08-30 07:45:16