I am using Vim as my primary text editor on Fedora 34 workstation. I need to create and maintain a log file for one of my courses for the purpose of tracking time and work done. It should look something like this:
John Doe Log for XYZ 1101, Fall 2021 ***** IN: Thu Aug 26 08:13:11 PM EDT 2021 Enter my log notes here ***** OUT: Thu Aug 26 09:22:13 PM EDT 2021
NOTE: two spaces after IN: and one space after OUT:
I would love to automate this process so that every time I open this document (if not possible, then on a given command)
***** IN: date gets printed and the cursor gets placed at the beginning of the second line below. Also, every time I close the document (or on a given command)
***** OUT: date (and a blank line after that) should be printed two lines below my last text entry. That will assure that there is always an empty line in between two given entries and in between my notes and entry dates.
Can anyone please help me do this or at least guide me to completing it? I have never done any scripting or messed with advanced vim settings.
EDIT: Using a comment from @muru and after looking up how to use
autocmd, I was able to come up with the following.
autocmd VimEnter ~/test.log $pu=strftime('***** IN: %c') autocmd ExitPre ~/test.log $pu=strftime('***** OUT: %c')
It works, but it is not perfect. The problems are:
It does not leave me with an extra empty line in between text. I would love to be able to add 2 line breaks. How can I do that using Vims put command? Or is there any other way?
ExitPrecommand was the only on that somewhat worked for me. However, every time I do
:x) the OUT date gets written and the program does not exit. Instead, I have to save it again and the force an exit with
:q!. I don't really consider this elegant option. I would want this to happen in the background so that I can exit only once, and then see the OUT date next time I open the document. Other commands like
VimLeave(before exiting Vim, after writing the viminfo file) did not work at all.
Any help would be appreciated!