January 25, 2008

Auto update last modified user/time vim script


From Tip #890: Last modified: <CURRENT DATETIME>

" Search the first 8 lines for Last Updated: and update the current user/datetime
function! LastMod()
 if &modified
  if line("$") > 8
   let l = 8
  else
   let l = line("$")
  endif
  let time = strftime("%m\\\/%d, %Y")
  exe "1," . l . "g/Last Updated: /s/Last Updated: .*/Last Updated: yyhuang " . time . "/"
  endif
endfun

" This autocommand will call LastMod function everytime you save a file
autocmd BufWrite * ks|call LastMod()|'s