"进行版权声明的设置
"添加或更新头
map <F4> :call TitleDet()<cr>'s
function AddTitle()
call append( 0, "/*=============================================================================")
call append( 1, "# COPYRIGHT NOTICE")
call append( 2, "# Copyright (c) 2014")
call append( 3, "# All rights reserved")
call append( 4, "#")
call append( 5, "# @author :Shen")
call append( 6, "# @name :")
call append( 7, "# @file :".expand("%:p:h")."\\".expand("%:t"))
call append( 8, "# @date :".strftime("%Y/%m/%d %H:%M"))
call append( 9, "# @algorithm :")
call append(10, "=============================================================================*/")
call append(11, "")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
"更新最近修改时间和文件名
function UpdateTitle()
normal m'
execute '/# @date /s@:.*$@\=strftime(":%Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/# @file /s@:.*$@\=":".expand("%:p:h")."\\".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
"判断前10行代码里面,是否有COPYRIGHT NOTICE这个单词,
"如果没有的话,代表没有添加过作者信息,需要新添加;
"如果有的话,那么只需要更新即可
function TitleDet()
let n = 2
"默认为添加
let line = getline(n)
let str = '^# COPYRIGHT NOTICE$'
if line =~ str
call UpdateTitle()
return
endif
call AddTitle()
endfunction