Thursday, July 30, 2015

Flexible auto-insertion of date at end of file.

What I have so far is:

"Autoinsert date at end of file, _after_ reading modelines:

au BufWinEnter ~/Data/rainfall/*/* call Append_Date()

function! Append_Date()
normal G
:r !date '+\%d.\%m: '
normal A
endfunction

Problem:
The "normal A" moves the cursor to the end of the inserted date, but
does not enter insert mode. (Stays in normal)
Appending a ^V^M to the second line doesn't help.
How should I hold my mouth for the "normal A" to take effect?

Desired Enhancement:
This is ambitious, but if I could make the date format a function
argument, then the one function could serve a multitude of autocommands,
each with an application-specific date format. But *function-argument*
in the help does not overflow with allowable syntax description. This
simple attempt:

au BufWinEnter ~/Personal/rainfall/*/* call Append_Date("'+\%d.\%m: '")

function! Append_Date()
normal G
:r !date a:1
normal A
endfunction

disappointingly gives:

E118: Too many arguments for function: Append_Date

There is presumably some concise (readable|(arcane&cryptic)) way to pass
a simple literal string to a function in an autocommand?

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Apr 2 2015 20:12:09)
Included patches: 1-688

That's the latest package for debian 7.8.0, very recently installed.
Could take the source path, if that were necessary.

Erik

--
manual, n.:
A unit of documentation. There are always three or more on a given item.
One is on the shelf; someone has the others.
The information you need is in the others. - Ray Simard

--
--
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:

Post a Comment