Skip to content

Auto insert date when starting Vim

I have a file where I keep notes / ideas. And I try to have 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 type one letter;
  • The file opens in insert mode;
  • the current date and time are inserted;
  • and Vim starts a new line where I can start typing, right away.

I edited just two files to achieve this.

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

~/.bashrc
alias i="vim -c 'startinsert' /home/jan/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.

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

Also published on Medium.

Tags:

Leave a Reply

Your email address will not be published.