很多程序员都想给自己的程序添加一些作者信息之类的信息,那么我们应该怎么实现这个要求呐?

已shell脚本为例,只需要修改/etc/vimrc配置文件,在文件末尾添加如下内容即可
注:vimrc文件中,注释行是以"标记的,否则会报错
复制时注释行单独复制,代码段可以一起复制,否则会造成缩进不正确
"当按F4键时添加作者信息,如果需要在添加一个python可以添加F5
map <F4> ms:call TitleDet()<cr>'s
function AddTitle()
call append(0,"#!/bin/bash")
call append(1,"##############################################")
call append(2,"#Author: Liuzhengwei - 1135960569@qq.com")
call append(3,"#QQ:1135960569")
call append(4,"#Last modified: ".strftime("%Y-%m-%d %H:%M"))
call append(5,"#Filename: ".expand("%:t"))
call append(6,"#Description: ")
call append(7,"##############################################")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
"修改文件修改时间和文件名
function UpdateTitle()
normal m'
execute '/#*Last modified:/s@:.*$@\=strftime(":%Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/#*Filename:/s@:.*$@\=":".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
"判断如果前10行中如果有Last modified:字段
"如果没有的话,则代表没有添加过作者的信息等条件,则重新添加
"如果有的话,那么只更新修改时间和文件名
function TitleDet()
let n=1
while n < 7
let line = getline(n)
if line =~ '^\#\s*\S*Last\smodified:\S*.*$'
call UpdateTitle()
return
endif
let n = n + 1
endwhile
call AddTitle()
endfunction添加完成之后,打开一个test.sh的文件,按F4就会出现如下信息。
[root@test3 tmp]# vim test.sh #!/bin/bash ############################################## #Author: Liuzhengwei - 1135960569@qq.com #QQ:1135960569 #Last modified: 2016-07-04 15:55 #Filename: test.sh #Description: ##############################################
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。