How do I limit the range of a find and replace operation? Say I want to change "foo" to "bar" within one function in a file, but *only* in that function. Is there a way to limit the find/replace operation to the current scope, block, or selection?
I can kinda-sorta do it in an awkward way by pulling up the find dialog, filling in my find and replace strings, closing the dialog, selecting the region, and doing "replace all in selection". What I'd like is to have the find dialog only operate on an already-selected region. Can this be done?
Also, "replace all in selection" acts in an unexpected way with column-based selections. Say I have the following text:
Lorem ipsum dolor Lorem ipsum dolor Lorem ipsum dolor Lorem ipsum dolor Lorem ipsum dolor Lorem ipsum dolor |---|
I want to change the first "ipsum" to "foo" in every line, so I make a column selection (marked by the |---| region) and do replace-all-in-selection. I end up with:
Lorem foo dolor Lorem ipsum dolor Lorem foo dolor Lorem ipsum dolor Lorem foo dolor Lorem ipsum dolor
The five-letter word got replaced with three letters and two extra spaces. If I do the opposite and replace "ipsum" with a longer word, the rest of the lines are shifted rightward accordingly. My expectation is that when I'm replacing with a shorter word the lines get shifted leftward to fill the gap, not that my replacement string will be padded with spaces. Bug or feature?
On 4/23/07, Steve King steve@narbat.com wrote:
Is there a way to limit the find/replace operation to the current scope, block, or selection?
If you hold down the Shift key when the Find dialog is open, the "Replace All" button changes to "In Selection", and replaces all in the selection.
This is slightly easier than your "awkward way". If you want something more sophisticated, such as limiting to the current scope, I imagine you would have to write a simple command.
Robin
Steve King wrote:
How do I limit the range of a find and replace operation? Say I want to change "foo" to "bar" within one function in a file, but *only* in that function. Is there a way to limit the find/replace operation to the current scope, block, or selection?
Selection, yes, by holding ⌥ down in the dialog and clicking "In Selection".
Scope, no. I'm keeping my fingers crossed for TM2 thought ;)
-Jacob