Creating text snippet macros with Notepad++

notepadNotepad++ is one of my favorite applications, it is lightweight, flexible, and has all the tools I need to do my job. One of the great options it offers is a built in macro recorded, which among other things, allows you to create easily insertable text snippets into your files. Let’s take a look at how to insert an HTML comment (“<!–   –>”) with the push of a key combination.

First of all, open notepad and click the record button, which can be found toward the end of the toolbar, a big red circle. Once you clicked it, the app will start recording, so it’s time to type what you need, in our case: “<!– –>” (without the quotes). Once done, press the save button, which is the right most icon in that group and give it a title (eg. HTML Comment) and add a keyboard shortcut, in my case this was ctr + shift + c. Once saved you can press that combination any time to paste an HTML comment.

There are two things to watch out for when recording. First of all, don’t copy paste, since the copy paste action will be recorded, not the actual clipboard contents, so next time you invoke the action, the actual clipboard will be pasted. Secondly, your actions are all recorded, so pressing the arrow, or backspace and so on. This way you can record the same comment by pressing back 4 times after you typed it, and saving like that. This will place your cursor between the two dashes, which is where you will write your comment, saving your the time of pressing back every time you insert a comment.

This allows for a lot a fancy macros, but for now you can create simple text snippets. I’ll be covering a lot more advanced macros a bit later though.

4 Responses to “Creating text snippet macros with Notepad++”

  1. Mario Andrade
    11th of November, 2009 at 21:30

    I actually had a problem when creating a macro. I needed to replace a large amount of html code on over 90 pages but when executing the macro the pasted code was incomplete.

    Any idea why this is happening?

  2. Daniel Pataki
    11th of November, 2009 at 22:37

    Hi Mario!

    There could be any amount of problems, not least of which might be the 90 pages, since that’s a bigger chunk. If set up well, I doubt that length is a problem, but it could be, who knows?

    The other aspect is how you replace the code, can you be a bit more specific about how and what you are trying to do exactly? Macro’s are not difficult to use, but can take some time to get the hang of. If you’re a beginner in macro’s it is likely that you are not using them right. In this case I might be able to help, but if you’ve been using macros for ages I will probably be useless, I am not a huge expert in these matters, sorry :(

    I’ll do my best though :)

  3. Anand
    31st of January, 2010 at 04:49

    Hello,
    Please could you give me links and material on how to record a macro and what and all it can create in Notepad++. Many thanks in advance..

    cheers
    – Anand

Leave a Reply