想要在vim文件时,自动添加详细信息,只需要在/etc/vimrc文件下面加上:
map <F4> ms:call TitleDet()<cr>'s
function AddTitle()
call append(0,"#*******************************************************************************")
"call append(1,"#")
call append(1," #* Author : 韩")
"call append(3,"#")
call append(2," #* Email : hz7726@163.com")
"call append(5,"*")
call append(3," #* Last modified : ".strftime("%Y-%m-%d %H:%M"))
"call append(7,"#")
call append(4," #* Filename : ".expand("%:t"))
"call append(9,"#")
call append(5," #* Description : ")
""call append(11,"#")
call append(6," #* *****************************************************************************/")
call append(7,"#/bin/bash: ")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endf
"更新最近修改时间和文件名
normal m'
"execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
normal "
normal mk
"execute '/# *Filename:/s@:.*$@\=":\t\t".expand("%:t")@'
execute "noh"
normal 'k
"echohl WarningMsg | echo "\n" | echo "Successful in updating the copy right."| echohl None
"endfunction
"判断前10行代码里面,是否有Last modified这个单词,
"如果没有的话,代表没有添加过作者信息,需要新添加;
"如果有的话,那么只需要更新即可
function TitleDet()
let n=1
while n < 10
let line = getline(n)
if line =~'^\#\s*\S*Last\smodified:\S*.*$'
call UpdateTitle()
return
endif
let n = n + 1
endwhile
call AddTitle()
endfunction
在按F4键盘
当我们还要增加一些信息时,只需要修改
call append(页数,“要添加的信息”)即可