Hi Jose,
Below is a 90-line macro that does exactly what you specified:
"Imagine you're on top (cursor) of a variable name you don't like. The macro would do this (when triggered) :
Open the Replace dialog, with the "Replace From" already filled with the word under cursor (the bad variable name) , then followed by the same word again, on the Replace To Field and finally, for the options, it would be with the default value "GIW". One could change any of these fields, of course."
Use <[Shift] Tab> to switch fields, <Enter> to do the replace, or <Escape>.
Carlo
/*
Replace command as specified by Jose Adriano Baltieri on 20 Jan 2026
in the TSE mailing list.
*/
integer field = 1
integer stop = TRUE
proc after_getkey()
case Query(Key)
when <Tab>
stop = FALSE
if field == 3
field = 1
else
field = field + 1
endif
Set(Key, -1)
PushKey(<Enter>)
PushKey(<end>)
when <Shift Tab>
stop = FALSE
if field == 1
field = 3
else
field = field - 1
endif
Set(Key, -1)
PushKey(<Enter>)
PushKey(<end>)
endcase
end after_getkey
proc Main()
string replace_from [MAXSTRINGLEN] = GetWord()
string replace_to [MAXSTRINGLEN] = GetWord()
string replace_options [12] = 'giw'
if replace_from == ''
replace_from = GetHistoryStr(_FIND_HISTORY_, 1)
endif
if replace_to == ''
replace_to = GetHistoryStr(_REPLACE_HISTORY_, 1)
endif
if replace_options == ''
replace_options = GetHistoryStr(_REPLACEOPTIONS_HISTORY_, 1)
endif
PopWinOpen(3, 5, Query(ScreenCols) - 3, 5 + 7, 1, 'Replace',
Query(MenuTextAttr))
PutStrAttrXY(1, 1, Format('From:' :-255), '', Query(MenuTextAttr))
PutStrAttrXY(1, 2, Format(replace_from :-255), '', Query(TextAttr))
PutStrAttrXY(1, 3, Format('To:' :-255), '', Query(MenuTextAttr))
PutStrAttrXY(1, 4, Format(replace_to :-255), '', Query(TextAttr))
PutStrAttrXY(1, 5, Format('Options:' :-255), '', Query(MenuTextAttr))
PutStrAttrXY(1, 6, Format(replace_options:-255), '', Query(TextAttr))
Hook(_AFTER_GETKEY_, after_getkey)
repeat
stop = TRUE
case field
when 1
VGotoXY(1, 2)
Read(replace_from , _FIND_HISTORY_)
when 2
VGotoXY(1, 4)
Read(replace_to , _REPLACE_HISTORY_)
when 3
VGotoXY(1, 6)
Read(replace_options, _REPLACEOPTIONS_HISTORY_)
endcase
until stop
UnHook(after_getkey)
PopWinClose()
if stop
and (Query(Key) in <Enter>, <GreyEnter>)
and replace_from <> replace_to
Replace(replace_from, replace_to, replace_options)
endif
PurgeMacro(CurrMacroFilename())
end Main