Got really tired of not remembering to update the timestamps in the bash header I use.  The way it works is it will look for the words “Last modified: in the first 20 lines of any *.sh scripts I create.  Upon :wq it will auto-update the timestamp at last modified section.   This works great, if you just open your file but make no modifications then it will not update the timestamp. So if you wonder why it’s not working, try updating the file.. =)
Put this in your ~/.vimrc file
” If buffer modified, update any ‘Last modified: ‘ in the first 20 lines.
” ” ‘Last modified: Sun 12 Aug 2012 04:37:51 PM PDT
” ” Restores cursor and window position using save_cursor variable.
function! LastModified()
if &modified
let save_cursor = getpos(“.”)
let n = min([20, line(“$”)])
keepjumps exe ‘1,’ . n . ‘s#^\(.\{,20}Last modified: \).*#\1’.
\ strftime(‘%c’) . ‘#e’
call histdel(‘search’, -1)
call setpos(‘.’, save_cursor)
endif
endfun
autocmd BufWritePre * call LastModified()
:au BufWritePre *.sh exe “norm mz”|exe ‘%s/\(<!– DATE –>\).\{-\}\d\d:\d\d:\d\d/\1’.strftime(“%c”).”/e”|norm `z