Tapatalk

Run macro on selected text only

Run macro on selected text only

1

PostJun 04, 2025#1

I'm trying to figure out how to run my macro on only my selected text. 

Example: I want a macro to replace all words in only my selection; append " at each end, remove trailing spaces, etc. I haven't found a way to just to this on my selected text, it runs the macro on the whole file.

Anyone know how to achieve this?

6,825625
Grand MasterGrand Master
6,825625

PostJun 04, 2025#2

Macros can be recorded which is the easiest method to create them. The recorded macros can be later edited to add conditions or loops.

Macro to trim trailing normal spaces and horizontal tabs on current selection only:

Code: Select all

IfSel
TrimTrailingSpaces
EndIf
Well, a macro just trimming trailing spaces on only the current selection instead of the entire file is not really useful as there can be simply executed directly the command Trim trailing spaces (by hotkey) after making the selection.

Macro to append " at the end of each selected line if not already ending with a double quote:

Code: Select all

IfSel
InsertMode
ColumnModeOff
PerlReOn
Find MatchCase RegExp SelectText "(?!\").\K$"
Replace All "\""
EndIf
Note: The Perl regular expression character $ means end of line (not matching the newline characters), end of file and end of character stream processed by the replace which is the selected text. The selection of multiple lines should end therefore at end of a line (newline characters of last selected line not included in selected text) or the beginning of the next line (newline characters of last selected line included in selected text), but not somewhere in the middle of a line.

Replacing words in the current selection can be done also with a Find SelectText "wordX" and Replace All "wordY".