One of the most powerful features of Notepad++ is the capability to create and use macros.
Users who are well acquainted with MS Office (Microsoft Excel in particular) should be well aware of what a macro is. The next paragraph is a brief description of macros for users who are not familiar with them.
A macro is a sequence of user actions in a program that can be recorded and replayed. For example, if your everyday work requires repetition of the same sequence of actions, you can record this sequence of actions as a macro and then replay the whole thing at once each time you would need to repeat the sequence. A macro can be executed a by single mouse click or hot key combination after it is set up.
To record a macro, the user simply presses a record button and then manually completes the sequence of actions that they wish to store. The program converts their actions into the syntax of its macro programming language and saves it as a file.
A common macro programming language is VBA (Visual Basic for Applications), which is used in Microsoft Excel. Macro programming language may vary considerably between different programs. However, a common user can record and use macros with no knowledge of the programming language that implements the code.
To get an idea of how macros might be useful in Notepad++, consider some code that has some sections or pieces that repeat over and over again. These sections are called snippets. Without macros, snippets must be manually typed or copy-pasted each time they are used. Macros can be used to speed up and simplify this work by recording snippets and tying them to a hotkey. The snippets can then be inserted into a text using a single hot key combination.
Let’s look at the example of recording and using macros in Notepad++
The first thing that is important to know is which buttons control macro operation. The Notepad++ toolbar has are five macro buttons that are located in line toward the right end of the toolbar.
Here is the functionality of these buttons in sequence from left to right:
- Start macro record
- Stop macro record
- Playback recorded macro
- Repeat playback recorded macro
- Save recorded macro
Click the “Start macro record” button. After that the button will change color from red to gray, indicating that recording has begun. Make sure you accurately type the line mentioned earlier in the Notepad++ primary window.
After the line has been typed in, click the “Stop macro record” button. Notepad++ has recorded our actions. In this case it is a typed code line. To check whether the record is correct, let’s click the “Playback recorded macro” button. If everything has been done correctly, Notepad++ will precisely reproduce the line in question. If you need to repeat the recorded macro several times, you may repeatedly click the “Repeat playback recorded macro” button.
Now we need to save the recorded macro because if we don’t it will be kept in Notepad++ core memory only until close the program is closed. To save it, click the “Save recorded macro” button. A window will appear that allows you to set a hot key combination and a name for the saved macro. Choose any combination you like for the hotkey and enter the macro name as well.
There are two ways to check whether the macro has been saved or not. The first is to use the “Macros” menu. In the drop-down list our document.write() macro should appear alongside the Notepad++ system commands. The second way is to open the list of all saved macros. You can do this using the “Macros – Modify hot key/Delete macro” menu. Our macro should be displayed in the edit window that opens. In this window you can delete the saved macro using “Delete” button. You can also modify the hotkey combination for this macro with the “Modify” button.