Thursday, July 30, 2015

Re: Flexible auto-insertion of date at end of file.

On 2015-07-30 20:30, Erik Christiansen wrote:
> function! Append_Date()
> normal G
> :r !date '+\%d.\%m: '
> normal A
> endfunction

You're on the right track. As an aside, you can just specify the
line before the :r command and the ":" is superfluous. To simplify
matters further, vim has its own strftime() function that you can use
instead of shelling out for the date. Finally, after your "normal
A", vim returns to normal mode because you're still in a function.
Fortunately, vim also provides a ":startinsert" command to start
insertion mode.

> Desired Enhancement:
> make the date format a function argument
>
> function! Append_Date()
> normal G
> :r !date a:1
> normal A
> endfunction

So combining those above with your enhancement request, I came up
with the following function which seems to do what you want:

function! Append_Date(fmt)
$put=strftime(a:fmt)
startinsert!
endfunction

-tim



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: