Here is my C++ files template:
/*****************************************************************************
* @file <file_name>
*
* @date <date>
* @author John Doe
* @email jdoe@yourcompany.com
*
* @brief
*
* @detail
*
*****************************************************************************/
And here is what I have inside ~/.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()
Basically, I read the template file replacing the tags and with the actual information and insert the result at the beggining of the newly created file. The function s:insert_description()
is called whenever vim created a new file. This is set by the autocmd
at the last line.
You can base yourself at this code and create the equivalent for python.