Search code examples
vimformattingcode-snippets

in vim how can you insert the current date/time into a note


What script might i use in (vanilla) Vim to insert a snippet with the current date and time into each and every new note generated.


Solution

  • You can use for example:

    :pu=strftime('%c')
    

    To put a timestamp into a file in the default timestamp format. The format is adjustable.

    You could bind this action to a key (here F5 as an example). Put it to your .vimrc file without the colon in the beginning to make it permanent.

    :nnoremap <F5> "=strftime("%c")<CR>P
    

    More examples: https://vim.fandom.com/wiki/Insert_current_date_or_time