Selecting and tagging with custom tags
-
Hey all – I’ve used N++ for years but never explored many of it’s deeper features, using it as a better find/replace in text files that default notepad.
I’ve got a project I’m working on that I have a feeling N++ can handle, but I’m not sure how exactly.
I have a set of custom tags I’m using for a project. What I want to be able to do is select portions of a text file, hit some key, and automatically add one of these tags to the start and end of the selected text. For example:
If I were to select this text:
lorem ipsum dolar sit amet
and hit a defined key combination, the result I would get is this:
<a>lorem ipsum dolar sit amet</a>
Is there some way to do this in N++? If not, does anyone have thoughts on how I could do it?
Thanks!
-
Well, the easiest way is to install the HTML Tag Plugin, which has buttons which do just that.
But if you’re really thinking about the generic procedure, rather than the
<a>...</a>
wrapping specifically, you could record a macro:- Select Text
- Macro > Start Recording
- Cut (
Ctrl+X
or menu equivalent) - type
<a>
- paste (
Ctrl+V
or menu equivalent) - type
</a>
- Macro > Stop Recording
- Macro > Save Current Recorded Macro
- optionally assign a keyboard shortcut that you will remember.
From then on, using that macro (from the Macro menu or from the keyboard shortcut) will place the selected text between
<a>...</a>
. Since the macro is saved inshortcuts.xml
, it will still be available the next time your run Notepad++.(Please note that this macro does clobber your current clipboard contents; if this bothers you, using the HTML Tag plugin will be better)
- Online UserManual: Macro Overview: https://npp-user-manual.org/docs/macros/
- Online UserManual:
shortcuts.xml
macro syntax: https://npp-user-manual.org/docs/config-files/#macros