I just discovered how to do something I've been wanting to do for a long time, and I figured I would share it in case someone else finds it useful.
I wanted to be able to use word-processor-like capabilities with HTML files. Specifically, to highlight text and use a keystroke to automatically enclose it in certain HTML tags, for example, CTRL-B for bold, CTRL-I for italics, CTRL-1 for H1, CTRL2 for H2, etc. It saves me from having to type my most commonly used tags.
It sounded like a job for a Macro, but the problem was positioning the cursor correctly to close the tag, since the length of the selected text is arbitrary. I could position the cursor at the beginning of the selected text and insert the opening tag, but then I was stuck as to how to get to the end of the selected text to insert the closing tag.
So I just realized, I could use Cut and Paste to do it. The steps are:
Highlight the text
Macro -> Start Recording
CTRL-X to cut
Type the opening tag
CTRL-V to paste (The cursor will now be positioned at the end of what used to be the selected text)
Type the closing tag
Macro -> Stop Recording
Assign the macro to the correct key combination, and there you go.
The only drawback is that because it uses Cut and Paste, it leaves the selected text on the clipboard. In most cases that shouldn't be an issue.
It doesn't have to be just for HTML files. Use it for any in-line markup that starts and ends with some kind of delimiter. It doesn't work so well for curly braces in C or begin/end in Pascal because they won't be aligned correctly. It's easier just to type them.
I hope others can find this useful. (Or if you want to embarrass me by showing me a simpler or more obvious way to do this, go right ahead)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Select text.
Press CTRL+F to copy the selected text to the Find Dialog.
Press Esc to quit the Dialog.
Press CursorLeft key to move to the start of the found selected text.
Type the opening tag.
Press F3 to find the text: it will be selected again.
Press CursorRight key to move to the end of the selected text.
Type closing tag.
This doesn't mess with the Clipboard, but of course it does with your last search.
Be sure, before you perform these actions, all settings in the CTRL+F Find Dialog are correct.
For instance, uncheck Regular Expression and be sure the Search Direction matches the order in which you want to perform your changes (in this case: Down).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This doesn't seem to work because of the CTRL+F Find Dialog not being recorded into the Macro.
I tried using CTRL+F3 and then immediately CTRL+SHIFT+F3 to select the first time and CTRL+F3 to select the second time. Unfortunately, this will select no text the second time and the cursor will move just one position to the right from the start of the selected text. So this also doesn't work. Apparently, the selected text isn't remembered when replaying the Macro.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This doesn't work in Notepad++ for me. I tried and when I playback the macro I get a bunch of garbage. Here is my example (wrapping a few lines as a paragraph '<p></p>'):
This is
some
text.
After running the macro I get:
<p>T"NUL" Key="0" />
"SOH""NUL""NUL""NUL"</p>This is
some
text.
The letters in quotes show up as reversed text with a rounded rectangle behind them. What's that all about?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Menu_____ : TextFX
Submenu__ : TextFX Viz Settings
Option___ : +Viz Paste/Append binary (uncheck this option)
The checkmark may not be visible (in the current version). Just select/click the option and try to paste. If it's not right, select/click it again and try again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just discovered how to do something I've been wanting to do for a long time, and I figured I would share it in case someone else finds it useful.
I wanted to be able to use word-processor-like capabilities with HTML files. Specifically, to highlight text and use a keystroke to automatically enclose it in certain HTML tags, for example, CTRL-B for bold, CTRL-I for italics, CTRL-1 for H1, CTRL2 for H2, etc. It saves me from having to type my most commonly used tags.
It sounded like a job for a Macro, but the problem was positioning the cursor correctly to close the tag, since the length of the selected text is arbitrary. I could position the cursor at the beginning of the selected text and insert the opening tag, but then I was stuck as to how to get to the end of the selected text to insert the closing tag.
So I just realized, I could use Cut and Paste to do it. The steps are:
Highlight the text
Macro -> Start Recording
CTRL-X to cut
Type the opening tag
CTRL-V to paste (The cursor will now be positioned at the end of what used to be the selected text)
Type the closing tag
Macro -> Stop Recording
Assign the macro to the correct key combination, and there you go.
The only drawback is that because it uses Cut and Paste, it leaves the selected text on the clipboard. In most cases that shouldn't be an issue.
It doesn't have to be just for HTML files. Use it for any in-line markup that starts and ends with some kind of delimiter. It doesn't work so well for curly braces in C or begin/end in Pascal because they won't be aligned correctly. It's easier just to type them.
I hope others can find this useful. (Or if you want to embarrass me by showing me a simpler or more obvious way to do this, go right ahead)
How about this:?
Select text.
Press CTRL+F to copy the selected text to the Find Dialog.
Press Esc to quit the Dialog.
Press CursorLeft key to move to the start of the found selected text.
Type the opening tag.
Press F3 to find the text: it will be selected again.
Press CursorRight key to move to the end of the selected text.
Type closing tag.
This doesn't mess with the Clipboard, but of course it does with your last search.
Be sure, before you perform these actions, all settings in the CTRL+F Find Dialog are correct.
For instance, uncheck Regular Expression and be sure the Search Direction matches the order in which you want to perform your changes (in this case: Down).
This doesn't seem to work because of the CTRL+F Find Dialog not being recorded into the Macro.
I tried using CTRL+F3 and then immediately CTRL+SHIFT+F3 to select the first time and CTRL+F3 to select the second time. Unfortunately, this will select no text the second time and the cursor will move just one position to the right from the start of the selected text. So this also doesn't work. Apparently, the selected text isn't remembered when replaying the Macro.
This doesn't work in Notepad++ for me. I tried and when I playback the macro I get a bunch of garbage. Here is my example (wrapping a few lines as a paragraph '<p></p>'):
This is
some
text.
After running the macro I get:
<p>T"NUL" Key="0" />
"SOH""NUL""NUL""NUL"</p>This is
some
text.
The letters in quotes show up as reversed text with a rounded rectangle behind them. What's that all about?
Read about it in this message:
"RE: Notepad++ v4.9.2 has been released"
http://sourceforge.net/forum/message.php?msg_id=4959517
in the thread:
"Notepad++ v4.9.2 has been released" (Open Discussion forum)
http://sourceforge.net/forum/forum.php?thread_id=2035296&forum_id=331753
Menu_____ : TextFX
Submenu__ : TextFX Viz Settings
Option___ : +Viz Paste/Append binary (uncheck this option)
The checkmark may not be visible (in the current version). Just select/click the option and try to paste. If it's not right, select/click it again and try again.