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 promptstrftime('%Y-%m-%d %H:%M')evaluates to the current local date/time<CR>confirms the expressionpputs 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
Pinstead ofpwhen you need the value inserted before the cursor