1. 创建~/.vimrc文件
2. 写入如下内容:
map <F4> ms:call TitleDet()<cr>'s
function AddTitle() call append(0,"##############################################") call append(1,"#") call append(2,"# Author: WANG Zizhe - 344593137@qq.com") call append(3,"#") call append(4,"# QQ : 344593137") call append(5,"#") call append(6,"# Last modified: ".strftime("%Y-%m-%d %H:%M")) call append(7,"#") call append(8,"# Filename: ".expand("%:t")) call append(9,"##############################################") call append(10,"# Description: ") call append(11,"#!/bin/bash") echohl WarningMsg | echo "Successful in adding the copyright." | echohl Noneendfunction
function UpdateTitle()
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 "Successful in updating the copy right." | echohl Noneendfunction
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()endfunction3. 编辑脚本按F4键加入版本信息,每次修改后按F4更新"最后修改"信息