Auto insert date when starting Vim

I have a file where I keep notes / ideas. And I want as less friction as possible to add ideas to this file. To achieve this I made it so that when I am at my terminal I only have to type one letter, the file opens in insert mode, inserts the current date and time and start a new line where I can start typing.

I edited two files to achieve this.

An alias in .bashrc to type just one letter and start the file in Vim in insert mode:

alias i="vim -c 'startinsert' /root/notes/ideas.txt"

Two edits in .vimrc.

The first inserts the date: 2021-11-05 21:40:50 (conform ISO 8601).
The second start a fresh new line.

autocmd VimEnter ideas.txt $pu=strftime('%Y-%m-%d %H:%M:%S')
autocmd VimEnter ideas.txt $pu=''

Also published on Medium.


Leave a Reply

Your email address will not be published.