I thought it would be fun to solve this problem using a macro... here is the macro:
var
BeginPt : TPOINT;
EndPt : TPOINT;
BeginCaret : TPOINT;
begin
with BeginPt do
begin
x := 0;
y := 0;
end;
with EndPt do
begin
x := 0;
y := 0;
end;
with BeginCaret do
begin
x := BeginPt.x;
y := BeginPt.y;
end;
if Caller.SelAvail then
begin
BeginPt := Caller.BlockBegin;
EndPt := Caller.BlockEnd;
with BeginCaret do
begin
x := BeginPt.x;
y := BeginPt.y;
end;
//ShowMessage('BeginPt.x: ' + IntToStr(BeginPt.x) + ' ' +
// 'BeginPt.y: ' + IntToStr(BeginPt.y) + ' ' +
// 'EndPt.x: ' + IntToStr(EndPt.x) + ' ' +
// 'EndPt.y: ' + IntToStr(EndPt.y));
end;
ecReplace; // do the search and replace
if BeginPt.x <> 0 then
begin
Caller.BlockBegin := BeginPt;
Caller.BlockEnd := EndPt;
Caller.CaretXY := BeginCaret;
end;
end.
It's written in such a way that if nothing is selected the macro's action are the same as the actions done by the original replace command.
if there is text selected then, it does the replacement with the addition that the text _stays_ selected ready for a next replace operation to be done on it. That way, it is not even necessary to re-select the text since it stays selected.
Two possible ways of using the macro are:
1. re-assign the current key combination assigned to the "replace" command to this macro (default is ctrl-r) if going that route, do it in two steps, first delete the key assigned to "replace" then assign it to the macro. This because, if it's not deleted first, the key re-assignment eventually gets lost. This way effectively replaces the current action with this macro's action.
2. assign any unused key combination to this macro. This way, there are two ways of performing a replace operation, the original one and this new one that keeps the text selected ready for another replace operation.
HTH.
ETA:Just for the record, the variable BeginCaret isn't really needed. BeginPt has the same information.