MattsBits
MattsBits

MattsBits

Create Notepad++ Macro To Replace Text  

by Matt Hawkins, 14/06/2011
Categories : General

Notepad++ allows you to create macros which you can use to perform repetitive tasks. These macros are stored in the shortcuts.xml file and this can be manually edited to create new macros.

So you can record a macro, view the shortcut.xml file and extract the resulting lines. These can be modified and pasted to create a more complicated macro.

One important thing to note is that Notepad++ refreshes the shortcuts.xml file on exit so you are best editing the file in a separate text editor otherwise your edits may be overwritten.

I wanted to replace multi blocks of text so I recorded a macro, saved it and then examined the shortcuts.xml file to find out what the required commands were. Macro definitions are included within the <Macros> block and in the example below you can see the definition of a macro called "Matts Macro" :

...
<InternalCommands />
<Macros>
  <Macro name="Matts Macro" Ctrl="no" Alt="no" Shift="no" Key="0">
    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
    <Action type="3" message="1601" wParam="0" lParam="0" sParam="&lt;table&gt;" />
    <Action type="3" message="1625" wParam="0" lParam="1" sParam="" />
    <Action type="3" message="1602" wParam="0" lParam="0" sParam="[table]" />
    <Action type="3" message="1702" wParam="0" lParam="512" sParam="" />
    <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
  </Macro>
</Macros>
<UserDefinedCommands>
...


This macro replaces <table> with [table]. Not how the triangle brackets are represented with their HTML entity equivalents.

The block of six lines can be repeated to perform multiple replaces.

Before running the macro from the "Macro" menu make sure the cursor is at the beginning of the text as the replace works forward from the cursor to the end of the file.

Author : Matt Hawkins  Last Edit By : Matt Hawkins
PHP Powered  MySQL Powered  Valid XHTML 1.0  Valid CSS  Firefox - Take Back The Web  EUKHost - Recommended Webhosting Solutions

MattHawkins CMS v3.0 - Copyright 2009-2013