Creating a macro that uses search hangs NPP
-
I am trying to delete certain lines in a text file using a macro.
I hit the Record button.
I do a search for the phrase in the lines I want to remove.
I click back in the text document window, and press Home, hold shift, Down x2 to highlight 2 lines for deletion.
I press Delete.
I stop recording.So now, in theory, I can run this macro to the end of the document, and it will delete all lines I wish to delete. Except it does and then hangs the program because there are no more search results to find, yet it continuously tries to find the phrase because it hasn’t “officially” reached the end of the file (?) and locks the program.
The “wrap around” option in the search is turned off.
Suggestions?
-
@Jason-Quattrini I’m not sure how to do it as a macro but, if you are using regular expression mode your search pattern can be
.*pattern.*\R.*\R.*
The first
.*
is all of the line before your pattern of whatever it is you are searching for. This bypasses the need for you to press the Home key.The
.*\R
after your pattern goes from the end of the pattern that matched to the end of that line plus\R
for the invisible end-of-line character(s) that are at the end of each line.The second
.*\R
picks up all of the second line including the end of line character(s). The third part with.*
but no\R
picks up all of the third line but not the end-of-line character(s) themselves.You can then do search-replace using
Replace All
and it’ll do what you want without needing to use a macro.