vimtricks.wiki Concise Vim tricks, one at a time.

How do I insert a timestamp computed by Vimscript directly from Normal mode?

Answer

"=strftime('%Y-%m-%d %H:%M')<CR>p

Explanation

The expression register lets you evaluate Vimscript on demand and paste the result immediately. This is a fast way to insert dynamic values like timestamps, counters, or computed strings without leaving your editing flow. For changelogs, incident notes, and commit scratch buffers, it removes repeated manual typing and formatting mistakes.

How it works

"=strftime('%Y-%m-%d %H:%M')<CR>p
  • "= opens the expression register prompt
  • strftime('%Y-%m-%d %H:%M') evaluates to the current local date/time
  • <CR> confirms the expression
  • p puts the resulting string after the cursor

Example

Before:

Deployment started at: 

After running the command:

Deployment started at: 2026-03-28 19:45

Tips

  • Change the format string to match your team style, for example ISO-like '%Y-%m-%dT%H:%M:%S'
  • This pattern works with any Vimscript expression, not only strftime()
  • Use P instead of p when you need the value inserted before the cursor

Next

How do I regenerate help tags for every installed plugin in one command?