The trick is to insert the replace string in column mode with overstrike mode on while nothing is selected.
The following macro which needs the macro property
Continue if a Find with Replace not found checked will do it, if your file does not contain the character
».
A short description for understanding the macro function:
First the macro inserts » at the current cursor position to mark it. Next you can enter the search string for a standard search, no regex.
All occurencies of the entered string from current cursor position till end of file are marked next also with the » character before the search string. The cursor position will not be changed by this replace.
If the search string is not found, the macro will exit with switching back to windows clipboard and undo the insertion of character ».
Then you have to enter the replace string which is cutted to clipboard 9. Now the mode is switched to column mode with overstrike mode. In a loop on every occurence of » (except the first one inserted at start of the macro) the » is deleted and the replace string is pasted over the current content.
After the loop the cursor is positioned back to initial cursor position which is still marked by the inserted ». The marking character is deleted now and the default edit mode is restored before the macro exits.
Note: This is a true find/replace in overstrike mode. If your search string is longer then the replace string, the longer end part of the search string will remain in the file.
InsertMode
ColumnModeOff
HexOff
Clipboard 9
"»"
GetString "Enter search string:"
StartSelect
Find Up Select "»"
Key RIGHT ARROW
Cut
EndSelect
Find "^c"
Replace All "»^c"
IfNotFound
Key BACKSPACE
ClearClipboard
Clipboard 0
ExitMacro
EndIf
GetString "Enter replace string:"
StartSelect
Find Up Select "»"
Key RIGHT ARROW
Cut
EndSelect
ColumnModeOn
OverStrikeMode
Loop
Find "»"
IfNotFound
ExitLoop
Else
Delete
Paste
EndIf
EndLoop
InsertMode
ColumnModeOff
Find Up "»"
Delete
ClearClipboard
Clipboard 0
Well, a more easier solution to replace a shorter search string by a longer replace string with overstrike would be to use the following regular expression. But this regex replace fails if the search string is near the end of the line and there are not enough characters between the end of the search string and the end of the line. This is an UltraEdit style regex search/replace.
- Code: Select all
Find What: short search text??
Replace With: longer replace text
As you can see, the replace string is 2 bytes longer than the search string, so 2 ? must be added at the end of the search string. ? = matches any single character except newline in UltraEdit style.