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.

.bashrc

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"

.vimrc

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.

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

Leave a Reply

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