A filetype plugin for timestamping .vim files. It does only 2 things:
- insert a timestamp on demand;
- update a timestamp, on demand or automatically when a .vim file is saved.
cd ~/.vim/bundle
git clone https://github.com/sgolitsynskiy/vim-timestamp.git
To add a new timestamp, execute the :TimestampInsert
command.
To update an existing timestamp:
- save the file (
:write
command), or - execute the
:TimestampUpdate
command
Suggested mappings to add to your .vimrc:
nnoremap <leader>ti :TimestampInsert<CR>
nnoremap <leader>tu :TimestampUpdate<CR>
You may also override the timestamp format by specifyiing these global variables, like so:
let g:timestamp_prefix = 'Last tinkering: '
let g:timestamp_format = '%Y'
let g:timestamp_regex = '\d\{4\}'
Keep in mind that whereas specifying your own prefix (e.g., Last Updated vs. Modified vs. anything else...) is easy, changing the timestamp format requires making corresponding edits to the regex variable.
For example, the current format is %Y %b %d %X %Z
which renders as " Last Updated: 2001 May 25 06:00:00 AM PDT
The corresponding regex is: '\d\{4\} \a\{3\} \d\{2\} \d\{2\}:\d\{2\}:\d\{2\} [AP]M \a\+'
(note the single quotes and the escapes).
If you wanted to remove the timezone, you would remove %Z
from your format variable AND the trailing \a\+
from your regex variable.
There are many timestamp scripts that are language-agnostic and provide more options. I want to keep this one simple, lightweight, and specific to .vim files.
Suggestions and feedback are, certainly, welcome.
Inspired in part by a more general plugin by Gautam Iyer