出 处:https://www.cnblogs.com/su-root
使用的是Ubuntu系统,在用vim编写时,想自动插入作者信息,
可以修改 /etc/vim/vimrc 文件在末尾添加如下修改:
map <F2> :call TitleDet()<cr>
function AddTitle()
call append(0,"\#!/bin/sh")
call append(1,"# ******************************************************")
call append(2,"# Author : zdg ")
call append(3,"# Last modified: ".strftime("%Y-%m-%d %H:%M"))
call append(4,"# Email : 156047754@qq.com")
call append(5,"# blog : https://blog.csdn.net/zdg_c")
call append(6,"# Filename : ".expand("%:t"))
call append(7,"# Description : ")
call append(8,"# ******************************************************")
echohl WarningMsg | echo "Successful in adding copyright." | echohl None
endf
function UpdateTitle()
normal m'
execute '/# Last modified/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/# Filename/s@:.*$@\=":\t".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copyright." | echohl None
endfunction
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
之后用vim 编辑相关文件时,按F2便可自动的插入作者相关信息了。