Skip to content

Notepad++ Macros Example

This post is part 2 of 5 in the series Notepad++ Tips and Tricks
Logo for blog post "Record and Run Notepad++ Macros to Automate Repetitive Steps"

Do you ever find yourself doing the same things over and over and over again when working on your text files? You can save a lot of time by recording and running Notepad++ macros to automate these repetitive steps. Just record your steps once, then run them as many times as you need!

Animation showing how to record and run Notepad++ macros

Recording and Running Notepad++ Macros

In this example, we want to transform an ordered list of names into a comma-separated list with each name inside single quotes. To do this, we will record the steps we make on one line, and then run the steps on all the remaining lines.

It would not take a lot of time to rewrite this particular list manually, but it takes a fraction of the time using macros. As with any kind of automation: the more data you work with, the more time you save :)

Example: Notepad++ Macros that Run on All Lines

1. Make sure that you have the Word Wrap option disabled. Notepad++ macros work on lines, and having word wrap enabled might interfere with your results:

Screenshot of Word Wrap being disabled
Click View → Disable Word Wrap

2. Paste your text, and place the caret at the start of the first line. We will record our macro on this first line, so this will be the starting position.

Screenshot of placing caret at start of first line
Place caret at start of first line

3. Click Start Recording. You can use either the button on the toolbar or through the menu MacroStart Recording:

Screenshot of starting recording from toolbar or button
Click Macro → Start Recording

4. Edit the text step by step in a way that is repeatable for each line. This might require a few attempts to get right the first time, until you get used to thinking like a macro :)

In this example, we did the following steps:

  • Deleted the number using CTRL+Delete
  • Deleted the period and spaces using CTRL+Delete
  • Added single quote
  • Moved caret to end of line using End
  • Added single quote and comma
  • Deleted the line break using CTRL+Delete

Once you have made your edits, ensure that the caret is placed at the beginning of the next line or block of text:

Screenshot showing caret at start of next text block
Ensure caret is at start of next line or block of text

5. Click Stop Recording. You can use either the button on the toolbar or through the menu MacroStop Recording:

Screenshot of stopping recording from toolbar or button
Click Macro → Stop Recording

6. Click Playback to run your macro once. This is useful for testing. You can use either the button on the toolbar or through the menu MacroPlayback:

Screenshot of running from toolbar or button
Click Macro → Playback

7. Click Run a Macro Multiple Times to run your macro on multiple lines or until the end of the file. You can use either the button on the toolbar or through the menu MacroRun a Macro Multiple Times:

Screenshot of running multiple times from toolbar or button
Click Macro → Run a Macro Multiple Times
Screenshot of running until end of file
Choose number of times to run or run until end of file

8. After running your macro, verify the results. It can help to enable Word Wrap again. In this example, we may also want to remove the trailing comma:

Screenshot showing end result after enabling Word Wrap again
Click View → Enable Word Wrap

Tips for Recording Macros

Keep in mind that the actions will be played back exactly as they are recorded, so use CTRL to work on whole words rather than single characters:

  • Move caret to previous or next word using CTRL+arrows
  • Mark words using CTRL+SHIFT+arrows
  • Delete words using CTRL+Backspace or CTRL+Delete
  • Move caret to start or end of line using HOME and END.

Summary

Save time by using Notepad++ macros to automate repetitive steps. Record your steps once, then run them as many times as you need!

This is a very handy feature that is easy to learn and use. It has some limitations and you may have to try a few times to get it right. However, once you master Notepad++ macros, you probably won’t ever go back to manually doing the same steps over and over and over again :)

About the Author

Cathrine Wilhelmsen is a Microsoft Data Platform MVP, BimlHero Certified Expert, Microsoft Certified Solutions Expert, international speaker, author, blogger, and chronic volunteer who loves teaching and sharing knowledge. She works as a Senior Business Intelligence Consultant at Inmeta, focusing on Azure Data and the Microsoft Data Platform. She loves sci-fi, chocolate, coffee, craft beers, ciders, cat gifs and smilies :)

Comments

Hi! This is Cathrine. Thank you so much for visiting my blog. I'd love to hear your thoughts, but please keep in mind that I'm not technical support for any products mentioned in this post :) Off-topic questions, comments and discussions may be moderated. Be kind to each other. Thanks!

nice clean tutorial, many thanks.

Clean, clear and useful! Perfect, many thanks!

I have created a macro to replace few of the contents in my xml file. I tried the macro once on the active file and it worked fine. As i try the same on a different file, it doesnt work but the notepad icon in the taskbar flickers and the change wont get reflected. But wheni copy the content to a new page and tried, the macro worked out well. I want it to work in the same page without copying the content to a new page.

Kindly help.

Hi Hari. Are the files open in two different instances? By instances I mean in two separate windows with two different icons on the taskbar? It is not possible to record a macro in one instance and play it in another instance. In that case you would have to copy the content to a new tab in the instance where you recorded the macro to be able to play it. However, it is possible to record a macro in one tab and play it in another tab if they are in the same instance.

superb tutorial many thanks .

Hi Catherine–I just discovered Notepad++ and am well-impressed. It opens large datasets fast and lets you get right at the data, etc. What I was trying to do when I found your article was actually use some slightly more complex rules to parse the data–perhaps add a comma every time a ‘(‘ appears in the string for the first time… something along those lines. Do you know if this is possible in Notepad++… also, is there a way of seeing and editing the macro code you have generated, do you know? Thanks for the content.

Yes, you can use more complex rules with Regular Expressions (regex). Find / replace in Notepad++ supports Regular Expressions. I’m afraid I can’t help you with the actual regex, though, I only know the basics myself :)

You can save your recorded macros and view / edit the steps in a file called shortcuts.xml located in the %AppData%Notepad++ folder. (In Windows 7 / 8 the full path is most likely C:UsersAppDataRoamingNotepad++shortcuts.xml)

Hope that helps :)

Thanks for the great tips !

Immensely helpful. Thanks!

I regularly paste large data sets with repeating rows from Excel, in which I need to find the number of unique values. I use the “TextFX Tools/Sort lines case insensitive” command with the “Sort outputs only UNIQUE” option set so that duplicates are weeded out. However, when I attempt to record the macro (select all, click TextFX, click TextFX Tools, click Sort lines case insensitive), running it inserts a bunch of ASCII characters instead of running. Do macros work with menu selections? Or am I stuck with just keyboard actions?

Hi David. If you’re already using Excel I would actually recommend using Excel function instead of Notepad++ macros. The Data → Remove Duplicates function in Excel will tell you how many duplicates have been removed and how many unique values are left.

It is possible to use menu selections in macros. You can for example start recording, select all the text, click Edit → Line Operations → Sort Lines in Ascending Order, stop recording and play the macro (but this won’t remove duplicates). However, I get the same problem with TextFX as you do. It could be because TextFX is a plugin and handles data differently than macros, but I’m afraid I don’t know the reason why it doesn’t work.

Thank you so much!

Hi,
Thanks for the post. I have a question.
Which software did you use to make the gif picture on the top of the page? I tried some software like: Free Video to GIF Converter, KickMyGraphics and Cute Video to GIF Converter. But none of them were up to my expectations(good quality and less file size.)

Hi Arvind, I used a free program called GifCam. You can find it here: http://blog.bahraniapps.com/gifcam/

Really awesome piece of software! Thanks again Cathrine, wish you good luck.

Awesome Tutorial. Thanks a lot

Hi Catherine,

Thanks for the useful tutorial.

Regards,
said

Many thanks Catherine!!! So useful and saves me a lot of time.

Thanks Catherine, this kind of technique I was looking for a long time in notepad!!!!

Super presentation! Thanks!

Simple and useful!

Thanks Catherine, Nice tutorial.

Hello Catherine – I need to create a macro for editing a xml file. I will copy a string from Line1, search where all it is present in the file and then Replace the content. I have to perform this operation on from Line 2 – 10. I did the command properly but the macro is not working.

Hi Santhosh, I have not been able to create macros with values that are copied and pasted during recording. For your task, it sounds like you will have to do multiple find and replace values manually.

Hi Catherine – I’m using Google Translate to do some quick and dirty translation of Madcap Flare HTML5 documentation output. I followed Jose Sermeno’s helpful blog entry Plugging Topics into Google Translate https://www.madcapsoftware.com/blog/2012/06/07/topics-into-google-translate/ and can select the appropriate languages to which to translate. I save the translated pages individually and bring them into Notepad++ where I hit them with a macro that does a series of search and replaces to correct the HTML so that it plays nicely within Flare (changing <!DOCTYPE… to <?xml…, removing etc). I end the macro with Ctrl-A Ctrl C and manually paste the corrected output over the appropriate language file in Flare. It’s quick and dirty and CHEAP!!! But I have a lot of individual HTML topics to deal with.

Within the downloaded Google Translate file in Notepad++, I can see the name of the original source file within a comment. However, when I attempt to locate and isolate the name with a “()” and “2” replace statement, cut it to the clipboard (no path, just the name ie Catherine.html) and paste it within the Save As dialog within a recorded macro, it is not getting recorded. I works fine when I am recording – the Save As dialog appears and I can paste appropriately into it – but it does not play back correctly on the next file.

What is the appropriate way to do a save-as within the macro, if at all?

Thank you so much!!!!

Hi Thomas, I haven’t had any success with copying and pasting in macros, unfortunately :/ You can record the macro, but it gets all scrambled when you play it. Perhaps others who read this post have any suggestions?

Thanks for the quick reply!!!!! Wish me luck!

BTW, I also posted here: https://forums.madcapsoftware.com/viewtopic.php?f=13&t=28153&p=123628#p123628

thank you so much for your simple and lucid illustrations..

Perfect! This solution just answered my need! Thank you! It was great!

Pingback: Notepad++ Review – A Powerful, Free Code Editor Packed With Features - PallaviGupta

Pingback: Notepad++ Review – A Powerful, Free Code Editor Packed With Features - WordPress Community | powered by Mpress Studios

thank you.. easy to understand

Thanks! this will help a lot.

This is the best thing ever. <3 <3 <3

Hi! This is Cathrine (again). Just a reminder. I'd love to hear your thoughts, but please keep in mind that I'm not technical support for any products mentioned in this post :) Off-topic questions, comments and discussions may be moderated. Be kind to each other. Thanks!

Leave a Reply to Andrea Cancel reply