Enclose text in HTML tags

A brief howto showing how to use Geany to enclose text in HTML tags.

You need to have the Macros plugin installed and enabled to achieve this.


The Debian plugin package is called: geany-plugin-macro, though this gets installed when the overall Geany package is installed. In the gui, once installed, it can be found under the Tools menu → Plugin Manager menu item, where it is called: Macros and is subtitled Macros for Geany.

  1. For the purpose of recording this macro, if you have EditPreferencesEditorCompletionsXML/HTML tag auto-closing enabled, disable it. You can re-enable it after your Macros have been recorded.
  2. Insert some random text into a blank Geany document, e.g.: Lorem ipsum dolor sit amet.
  3. Select part of that text, e.g. ipsum dolor.
  4. Now select the: Tools menu → Record Macro menu item.
  5. Assign a macro trigger, e.g. Shift + F2 and give the macro a name e.g. h2.
  6. Then click the Record button.
  7. Now copy the selected text to the clipboard using the keyboard shortcut: Ctrl + c, or using the Edit menu → Copy menu item.
  8. Then, on a new line, type in the body of the Geany document you have open the html tag you want to automate, e.g.: <h2>. (Geany may autocomplete the tag by inserting the closing </h2> tag if XML/HTML tag auto-closing is enabled. You can still create a macro this way, but it will require more tidying up before it becomes usable.)
  9. Then paste previously copied text string from the clipboard.
  10. Then type the closing part of the html tag you are in the process of automating, e.g.: </h2>.
  11. Then select stop recording macro from the Tools menu.
  12. Test the macro by highlighting some text and using the macro trigger to trigger your macro.
  13. It might not work properly yet.
  14. To get it working properly, choose Edit Macros from the Tools menu, and adjust what had been recorded to get it to work the way you want it to. The macro editing interface is reasonably intuitive.
  15. Save your edits to the macro by clicking Ok.
  16. Test it again, you might have it working now. :-)

If everything has gone relatively smoothly, you should now be able to select some text in a Geany document, and then enclose it in <h2> tags by using your assigned trigger key combination to activate this macro. Repeat the above steps for any other tag pairs you would like to use to wrap around selected slabs of text.