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 with a space indentation so 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:

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


I added two lines to my .vimrc.

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *