Custom Date Insert Plugin for Notepad++

Posted on 2014-03-07 in  editors

I've been using Notepad++ on my Windows machine at work. It's the best free editor for Windows that I'm aware of, and does pretty much everything I can think of, with one notable exception.

Any editor that calls itself a programmer's editor should be scriptable. While you can develop your own plugins for Notepad++, it's not at all a trivial affair. Something like inserting the current date and time in a specific format is a trivial task, and shouldn't require a compiled C++ project made up of a dozen files.

Luckily, someone handy with C++ realized the same thing, and developed a plugin to allow Python scripting of Notepad++.

My specific need was to frequently insert the current date and time into the editor with the format YYYY-MM-DD HH-mm. The kitchen-sink TextFX plugin provides an Insert Date function, but only supports the standard "short" and "long" formats specified in your Windows system preferences.

Here's how I got it working.

  1. Install the NPPPythonScript plugin. See the excellent documentation for assistance if you don't know how to install plugins.
  2. Create the following ridiculously trivial Python script using the plugin:
  3. import datetime
    now =
    editor.addText(now.strftime("%Y-%m-%d %H:%M "))
    This allows you to run it from the Python Script plugin's menu. But I need to run this script a lot, so a keyboard shortcut is... key.
  4. Use the Python Script plugin's Configuration dialog to add a menu item for my new script.
  5. Use Notepad++'s Shortcut Mapper to map a keyboard shortcut to my script. Its found in the Plugins section of the Shortcut Mapper.

... and voila.

The scripts are created/saved in the C:\Users\[user name]\AppData\Roaming\Notepad+\plugins\config\PythonScript\scripts folder.

Leave a Comment:

Blog Search

Some Tags

Programming Is Fun

This is a blog about programming for the sheer joy of it. More...