Closed GoogleCodeExporter closed 9 years ago
Why can't you set up it with an autocommand?
I for myself did it...
Original comment by habamax
on 10 Jun 2012 at 7:57
Even though I found those scripts, but I do not know which one is better
(through read the source code), and how to do with autocommand. I want to do
with autocommand before I post issue here. But I found I can not put those
script into vimrc function. then call function behind autocmd. That's why I ask
for feature.
So, if you have done this with autocmd, can you let me reference your vimrc
about how to do this ?
Original comment by numbch...@gmail.com
on 11 Jun 2012 at 12:35
add those into your .vimrc:
" Check no more than 30 lines from start for 'Last Change:' and update it with
" the current datetime.
function! LastChangeUpdate() "{{{
for linenr in range(1, min([30, line('$')]))
let line = getline(linenr)
if line =~ 'Last Change:'
let line = substitute(line, 'Last Change:.*$',
\ 'Last Change: '.strftime("%Y-%m-%d %H:%M"), '')
call setline(linenr, line)
break
endif
endfor
endfunction "}}}
au BufWritePre *.wiki call LastChangeUpdate()
Original comment by habamax
on 12 Jun 2012 at 9:29
works good. Thanks for this.
Original comment by numbch...@gmail.com
on 12 Jun 2012 at 1:42
I think this will be useful for me, but what I find disorienting, is when I
type 'u' for undo after writing the file. Since changing the timestamp is that
last edit, it jumps to the top of the file.
Is there any way to change this?
Original comment by stu.andrews
on 15 Jun 2012 at 3:42
I don't know the right way to bypass vim's undo system here.
The only thing that comes up is to change date using readfile/writefile.
Another way, which is to use undojoin in the beginning of the function:
" Check no more than 30 lines from start for 'Last Change:' and update it with
" the current datetime.
function! LastChangeUpdate() "{{{
undojoin
for linenr in range(1, min([30, line('$')]))
let line = getline(linenr)
if line =~ 'Last Change:'
let line = substitute(line, 'Last Change:.*$',
\ 'Last Change: '.strftime("%Y-%m-%d %H:%M"), '')
call setline(linenr, line)
break
endif
endfor
endfunction "}}}
au BufWritePre *.wiki call LastChangeUpdate()
It looks like it works, but I have not tested it much
Original comment by habamax
on 15 Jun 2012 at 7:15
Original issue reported on code.google.com by
numbch...@gmail.com
on 10 Jun 2012 at 11:47Attachments: