sponsor Vim development Vim logo Vim Book Ad

timestamp.vim : Plugin to automatically timestamp files

 script karma  Rating 168/66, Downloaded by 6472  Comments, bugs, improvements  Vim wiki

created by
gi1242 gi1242
script type
When a file is written, and the filename matches |timestamp_automask|, this plugin will search the first and last |timestamp_modelines| lines of your file. If it finds the regexp |timestamp_regexp| then it will replace it with a timestamp. The timestamp is computed by first doing a |token_substitution| on |timestamp_rep| and passing the result to |strftime()|.

The plugin tries to stay out of your way, and make the change as transparent as possible. Your search (and all other) history is unaltered, however you might find an extra mark in your jumplist.

All the default variables and actions can be changed by buffer / global vim variables. See |timestamp_examples for two simple examples.

By default, this plugin will timestamp ANY file that matches the regexp |timestamp_regexp| in the first and last 'modelines' (default 5) lines of your file. The default value of |timestamp_regexp| will EITHER match 'TIMESTAMP' or a time (in the format of strftime("%c")) FOLLOWED by a 'Last changed:' or 'Last modified:'. For instance, if you create a new file and want to stamp it with a creation date and a last modified date, make the first few lines: >

    Created:            TIMESTAMP
    Last Modified:      TIMESTAMP

When you first write the file, these lines will change to: >

    Created:            Thu 26 Feb 2004 03:15:54 PM CST
    Last Modified:      Thu 26 Feb 2004 03:15:55 PM CST

On subsequent writes of the file, the first line will remain unchanged and the second will be stamped with the time of writing.

NOTE: If you find that on subsequent writes of the file, the second line is also unchanged, it is probably because the time returned by strftime is NOT is the format above. [Look closely and see if there is a leading 0 or timezone missing]. If you are using version 1.11 and higher and still have this problem, please report it to me. As a temporary fix, you can put the line >

    let timestamp_regexp = '\v\C%(<Last %([cC]hanged?|[Mm]odified):\s+)@<=.*$'

in your .vimrc. This however has the disadvantage of eating all the text after the colon in any timestamp line.

Read the complete htmlised documentation at http://math.stanford.edu/~gautam/opensource/xterm16/timestamp-doc.html
install details
Extract the files by:  "tar -xjvf timestamp.tbz2" (Use WinRAR if you're using M$ Window$ and don't have bzip2)

Put 'timestamp.vim' in $VIMRUNTIME/plugin for global installation. Put it in ~/.vim/plugin for local installation. Put 'timestamp.txt' in $VIMRUNTIME/doc (for global) or in ~/.vim/doc for local installation. Don't forget to run ':helptags ~/.vim/doc'

Do ':help add-global-plugin' and ':help add-local-help' for more information installing plugins.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
timestamp-1.21.tbz2 1.21 2009-03-25 7.0 gi1242 gi1242 Add |DisableTimestamp|, |EnableTimestamp| and |b:timestamp_disable| to enable / disable time stamping temporarily.
timestamp-1.20.tbz2 1.20 2007-06-21 7.0 gi1242 gi1242 Optionally ignore missing "AM/PM" in default timestamp. Thanks to Fabian Holler for pointing this out.
timestamp-1.19.tbz2 1.19 2006-05-18 7.0 gi1242 gi1242 Better preserves your undo history: Timestamping is not done unless writing the timestamp will cause a change.
timestamp-1.18.tgz 1.18 2006-04-04 7.0 gi1242 gi1242 Minor bugfix: Timestamping now works with zipped files / netrw. Also your jumplist is preserved. (This version works on vim6.4 and vim7)
timestamp-1.17.tbz2 1.17 2004-11-13 6.0 gi1242 gi1242 Reduce Vim's initial load time significantly. On my system, Vim with timestamp-1.16 loads in about 1.1 seconds. With timestamp-1.17, it loads in only 0.3 seconds! The system calls to initialise the uid / username were taking time. Calls to these functions have been disabled by default, and further postponed untill the are necessary (and not on Vim startup). These calls can be enabled by setting the variable |timestamp_UseSystemCalls|.
timestamp-1.16.tbz2 1.16 2004-09-25 6.0 gi1242 gi1242 No changes in the script. Updated the documentation to include a note to windows users having trouble with the timezone. Thanks to Shishir Ramam for pointing this out.
timestamp-1.16.tbz2 1.16 2004-09-17 6.0 gi1242 gi1242 Made all g:timestamp_* variables also available as buffer local variables except for g:timestamp_automask. Thanks to Lars Wilke for doing this. Also fixed default values for |timestamp_hostname|, |timestamp_Hostname|, |timestamp_userid| and |timestamp_username|. Thanks again to Lars Wilke for testing on various platforms.
timestamp.tbz2 1.15 2004-07-20 6.0 gi1242 gi1242 Modified the default timestamp regexp to support timestamps in other languages by default. This only works if the day and month names in your language do not use accented characters. If accented characters are present you should set the default timestamp regexp in your .vimrc. English users should not notice any difference.
timestamp.tbz2 1.14 2004-05-20 6.0 gi1242 gi1242 Now also works in compatible mode.
timestamp.tbz2 1.13 2004-03-29 6.0 gi1242 gi1242 A bug caused timestamp.vim to make changes in all lines in the |timestamp_modelines| range. Corrected the code so that now changes are made only when there is a timestamp in a particular line. This makes undoing changes a lot nicer, and keeps timestamp-ing out of your way. Also cleaned up some code :)
timestamp.tbz2 1.12 2004-03-09 6.0 gi1242 gi1242 Some Micro$oft machines don't support the timezone ('%Z'). Made the timezone optional in the default settings. The script (with default settings) should now work on both Linux / Window$ machines. Thanks to Krall Ed-P27726 for testing this.
timestamp.tbz2 1.11 2004-03-08 6.0 gi1242 gi1242 The format of strftime("%c") is not standard among all systems / locales. This caused default timestamps on some systems to fail. Changed the default value of "timestamp_rep" to the expanded version of "%c", and included a note in the documentation on how to fix this problem.
timestamp.tbz2 1.1 2004-03-05 6.0 gi1242 gi1242 Does not modify any marks or the search history list. Tries to make timestamping as "transparent" as possible.
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.