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 ametand 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+Xor menu equivalent) - type
<a> - paste (
Ctrl+Vor 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.xmlmacro syntax: https://npp-user-manual.org/docs/config-files/#macros
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login