出 處: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 : [email protected]")
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便可自動的插入作者相關信息了。