Adding an insert datestamp or timestamp macro to Notepad++

I had been looking off and on for a few years for a way to insert a timestamp into a file in Notepad++, preferably by a hotkey. The no-longer-in-development TextFX plugin frequently comes up in Google searches as one way of doing this, but the plugin doesn’t offer any ability to customize the format of the date or time stamp.

I found this article: http://sourceforge.net/p/notepad-plus/discussion/331753/thread/3458d1da that explains, briefly, how to do this using the Python Script plugin. I’ve been curious about Python for awhile, too, so I was willing to give it a shot. The SourceForge project page for Python Script is at http://sourceforge.net/projects/npppythonscript/.

So, here’s a quick tutorial on adding a customizable insert datestamp/timestamp macro to Notepad++.

Download the Python Script plugin from http://npppythonscript.sourceforge.net/download.shtml and install it. Do not download it from within Notepad++ by clicking Plugins | Plugin Manager | Show Plugin Manager, scrolling down the Available plugins list to Python Script, checking the box and clicking Install, because it just won’t work (and you may get an older version of the plugin).

Restart Notepad++ and you’ll find that Python Script has been added to the Plugins menu.

To create the script that will insert the timestamp, click Plugins | Python Script | New Script. Enter a filename for the script file you are about to create, like “Time.py”, and click Save.

A new, blank tab will appear in Notepad++. Paste in the following text:

import time 
editor.addText( time.strftime( '%Y-%m-%d %I:%M %p' ) )

Save the Time.py file to the default location in your user profile.

Add the Time.py script to Notepad++ by clicking on Plugins | Python Script | Configuration, highlighting Time.py, clicking the Add button above Menu items, and then clicking OK.

But, you probably want to be able to run this as a macro from a keyboard shortcut. Close the Time.py tab and then exit and relaunch Notepad++. Click on Settings | Shortcut Mapper… and choose the Plugin commands tab. The Time script should be listed here somewhere (in my case, it is usually somewhere around number 27). Highlight it, click Modify and assign it to a shortcut.

I choose to map my Time script to F5, because this mirrors the timestamp functionality built into Windows notepad.exe, but Notepad++ already uses that keystroke for the Run command. I never use the Run command, so I just remove the shortcut from that command by clicking on Settings | Shortcut Mapper… and choosing the Main menu tab, scrolling down to the Run item and either removing the mapping by changing the shortcut to None or changing it to something else, such as Ctrl+F5. For me, Run was located in the Shortcut mapper under Main menu around number 208. Close the Shortcut Mapper and you’re ready to use your new timestamp hotkey.

You can change the datetime formatting using variables! Just modify the contents of the Time.py file located at “%AppData%\Notepad++\plugins\Config\PythonScript\scripts”. See: https://docs.python.org/2/library/time.html#time.strftime

17 thoughts on “Adding an insert datestamp or timestamp macro to Notepad++

  1. Dude

    After updating to Notepad++ Python Script v1.0.8 it works now. This is a great tutorial and fixes the one thing about Notepad++ I had disliked since I started using it.

  2. Fedon

    You can install the “pork2sausage” plugin and define a command like this:
    [Insert CurrDate]
    progPath=C:\cygwin\bin\bash.exe
    progCmd=C:\cygwin\bin\bash.exe -c “echo -n $(date )”
    workDir=C:\cygwin\bin

    Note: Yes, I use Cygwin in my PC.

  3. Yuvraj

    If Time.py doesn’t show up in Shortcut Mapper, Go to Plugins > Python Script > Configuration
    Add Time.py to Menu Items, Change Initialisation to ATSTARTUP, Click Ok and Restart Notepad++

  4. Van

    I want to set shortcut of timestamp to Enter (hostkey) on Settings | Shortcut Mapper,
    but I can’t.
    On Shortcut Mapper, it only able set with Ctrl/Alt + Shift + Enter while my device sends Enter key.

    Who can show me the way to set shortcut to only Enter key

  5. James

    I have bookmarked this link and reference it about twice a year 😉
    At the time of writing, the Python Script Plugin in NPP Plugin Manager is out of date v1.0.6.0, and I find that it hast not worked with these instructions since some time in 2014. Instead, I upgrade to the latest Python Script Plugin v1.0.8.0 by downloading the MSI and installing directly from here: https://sourceforge.net/projects/npppythonscript/
    Then these instructions still work.
    Thanks for providing them!

  6. nila

    Super. Able to set it up following instructions. very useful and has been searching for a while now. This is working only for 32 bit Notepad++. Is there a way to use for 64 bit version ?

  7. Tim L Pfeiffer

    Installed python as suggested installing the latest MSI v1.0.8.0.

    New laptop Windows 10 64 bit.

    Starting Notepad ++ Python is not showing up in the plugins.

    Am I missing a step I downloaded and installed the MSI – shut down and restarted Notepad ++

    Any ideas?

  8. Erol Bayburt

    Useful!
    A couple of tweaks/quirks
    1. Apparently “import datetime” is now needed instead of “import time”
    2. Using editor.replaceSel instead of editor.addText lets one select e.g. “Date Goes Here” text and replace it on running the script, rather than inserting the datestamp and then having to delete the text afterwards.

Comments are closed.