This answer is based upon pb2q's, but makes it more extensible. Define a function to do the creation, so you can use it for a variety of comment types:
function UpdateModifiedTime(comment)
let savedPosition = getpos(".")
call cursor(1, 1)
let modified = a:comment . 'Modified:'
if search(modified, 'e') > 0
execute 'substitute/' . modified . '.*/' . modified . ' ' . strftime('%b %d, %Y %T') . '/'
endif
call setpos(".", savedPosition)
endfunction
(Note: it is my practice to use the longer forms whenever possible in scripting Vim, unless I am golfing, because I value code readability and normal commands are arcane).
You can then define autocommands such as:
autocmd BufWrite *.sh,*.ksh,*.bash call UpdateModifiedTime('## ')
autocmd BufWrite *.vim call UpdateModifiedTime('" ')
autocmd BufWrite *.py call UpdateModifiedTime('')
autocmd BufWrite *.c call UpdateModifiedTime('// ')
Note that I gave an empty comment character for Python. That's because I had '''
strings in my file header for the commenting. You can use '# '
or '## '
or whatever tickles your fancy.
You can do something similar with Created
.