randomfox: (Default)
[personal profile] randomfox
The first set of Vim mappings will insert the current date. The second set of Vim mappings will update a line of the form "Last updated: date" so that it holds the current date.


" Returns the current date in string form.
" The substitution gets rid of the leading 0 in the day of the month.
function! Date_string()
    return substitute(strftime("%B %d, %Y"), " 0", " ", "")
endfunction

" F12 t inserts a date stamp.
" F12 t in visual mode replaces the selection with a date stamp.
nmap <F12>s i<C-R>=Date_string()<CR><ESC>
vmap <F12>s c<C-R>=Date_string()<CR><ESC>
imap <F12>s <C-R>=Date_string()<CR>

" F12 l updates a 'Last up-dated:' line
" Need to use a [s] here so that this macro won't change itself if
" invoked on this file.
let m = "1G/La[s]t updated:/e+0<CR>a <C-R>=Date_string()<CR><CR><ESC>dd"
execute "nmap <F12>l" m
execute "imap <F12>l <esc>" . m . "i"
execute "vmap <F12>l <esc>" . m
unlet m

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

randomfox: (Default)
randomfox

November 2012

S M T W T F S
    123
45678910
11121314151617
18192021222324
25262728 2930 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 13th, 2026 06:06 pm
Powered by Dreamwidth Studios