Timestamp/Datestamp keyboard shortcut in Notepad++

I’ve been using Notepad++ daily for about 10 years and have mostly worked out of one file for a day or two and then move on to another file.  I just name them for the date they were created.  This allows me to have an idea of when tasks/meetings/etc happened when I’m searching for something.

I just came across a great post that talks about how Jeff Huang has used a single text file for the last 12 years.  Check it out here, I am intrigued.  I like how he starts the day with date and then time stamps throughout the day.  I figured I would give it a go but quickly learned that typing the date and time is cumbersome.  Notepad++ has a ton of plugins and macros, there must be a way to have a keyboard shortcut for a timestamp.  I started my search and all the top results were related to TextFX which was shut down a long time ago.

Then I found it…  Oliver Baty used the Python Script plugin to create a script that could then be utilized as a keyboard shortcut.  Quick and easy.

He posted his steps almost 6 years ago though, would they still work?  They mostly do with a few tweaks.  That’s why I’m posting this, to update on what Oliver posted so long ago.

First, read through the original article to see what needs to happen.  The first change I made was that I used the Plugins | Plugin Manager to install the Python Script plugin.  I found that the most recent version of the plugin was available in the Plugin Manager.

The second thing I did was just to create 2 scripts; one for the date and one for the time.  That way I can hit one key to start my day and then hit another key to put the current time throughout the file.

The first script for the date looks like this:

import time 
editor.addText( time.strftime( "##  %Y-%m-%d %A" ) )

There are a couple things going on here. First is the ## at the beginning of the string. This is because I use markdown in my text files for a bit of formatting. Every date stamp will be formatted as header 2. Next I have the year, month, and day followed by the day of the week. You can edit this as you like. Here’s a good link for formatting.

The second script for the time looks like this:

import time 
editor.addText( time.strftime( "###  %H:%M" ) )

Again with the markdown formatting to start, this time it’s header 3. The time is formatted as 24 hour; my preference.

There you go, follow Oliver’s post with my tweaks and you’ll have keyboard shortcuts in a matter of minutes.

Have fun with it

 



Leave a comment