[TxMt] Limiting range of 'find'.

Steve King steve at narbat.com
Mon Apr 23 18:34:44 UTC 2007


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?

-- 
Steve King, <steve at narbat.com>



More information about the textmate mailing list