To automate the process somewhat, here's an AppleScript that will
prompt for the search string. I've provided two versions of the
search, one that excludes, one that includes the line; just comment
out the one you want.   You will probably have to remove line breaks
in the "find" statement  that are inserted by Google Mail. If you put
this in BBEdit's Scripts folder, you can assign it a keyboard in the
Window /Palette/Scripts menu. (By the way, I started writing this
script by recording a simple search.)

Steve
_______________________________________
(* Search up to Line Containing Specified Text
*)
tell application "BBEdit"
        set _searchto to the text returned of (display dialog "Enter search
string" default answer "")
        set _sstring to "(?s).+?(?=((?-s)^.*" & _searchto & ".*$))" --exclude
line with search text
        -- set _sstring to "(?s).+?((?-s)^.*" & _searchto & ".*$)"  --
include  the line
        open find window
        find _sstring searching in text 1 of front document options {search
mode:grep, starting at top:false, wrap around:true, backwards:false,
case sensitive:false, match words:false, extend selection:false} with
selecting match
end tell
_________________________________________

On Mar 14, 2:40 pm, Simdude <[email protected]> wrote:
> Thanks again Steve. Actually, I wanted to perform an operation within
> a selection to mimic what vi can do by specifying a range. i.e. do a
> search and replace but only in a certain range. While it appears you
> can't directly do this in BBedit, your tip will allow me to first
> create a selection region, and then I can operation on that region.
>
> thanks!
>
> On Mar 13, 10:39 am, Steve Samuels <[email protected]> wrote:
>
>
>
> > Mark, your original question was how to select  all text from the
> > cursor up to the _line_ that
> > contains specified text. Here are solutions.
>
> > Exclude the line from the selection: (?s).+?(?=((?-s)^.*HELLO.*$))
> > Include the line in the selection:   (?s).+?((?-s)^.*HELLO.*$)
>
> > These will fail if the current line contains the text.
>
> > Steve
>
> > On Mar 10, 5:39 pm, Steve Samuels <[email protected]> wrote:
>
> > > You are welcome, Mark. To give you a head start, with manual
> > > references:
>
> > > "(?s)" extends the search over line endings (p. 188)
>
> > > ".+?HELLO" searches text up through the first occurrence of HELLO (non-
> > > greedy matching, p. 177)
>
> > > "(?=HELLO)" says to search up to "HELLO" but not include "HELLO" in
> > > the found text (positive lookahead, pp. 187,190).
>
> > > Parentheses around "HELLO" are a stylistic choice and don't affect
> > > this search, though they might be important in other, more complicated
> > > searches.
>
> > > Steve
>
> > > On Mar 10, 2:49 pm, Simdude <[email protected]> wrote:
>
> > > > Wow. Thanks Steve. I have to give this a try as soon as I get home.
> > > > And I guess it's time to dig into the BBedit docs some more!
>
> > > > On Mar 10, 2:35 pm, Steve Samuels <[email protected]> wrote:
>
> > > > > Searching for  "(?s).+?(HELLO)" will select all text from the cursor
> > > > > up through the first "HELLO" and "(?s).+?(?=HELLO)" will select all
> > > > > text up to first "HELLO">.
>
> > > > > Steve
>
> > > > > On Mar 10, 8:35 am, Simdude <[email protected]> wrote:
>
> > > > > > Thanks Chris. I did know about the selection operations but when you
> > > > > > have to do this repeatedly in a file, it's not as efficient. 
> > > > > > Scripting
> > > > > > is probably a better option but I'll have to improve my Applescript
> > > > > > skills to be able to do this faster.
>
> > > > > > For any Barebones guys, adding something like to to a future BBedit
> > > > > > would be a killer feature. With the help of some books, I've used vi
> > > > > > to rearrange sections of large documents by using commands like this
> > > > > > to find and move sections.  The problem is while you can do this 
> > > > > > with
> > > > > > a single line in vi, it can take 30 minutes to figure out what to 
> > > > > > type
> > > > > > in that line!
>
> > > > > > Mark
>
> > > > > > On Mar 9, 5:26 pm, Christopher Stone <[email protected]>
> > > > > > wrote:
>
> > > > > > > On Mar 09, 2011, at 10:28, Simdude wrote:> Is there a way in 
> > > > > > > BBedit to operate on ranges of data? For example, when I use vi, 
> > > > > > > if I want to do a search and replace on all text from my current 
> > > > > > > cursor to the line that contains "HELLO", I would do this:
>
> > > > > > > > :.,/HELLO/ s/this/that/g
>
> > > > > > > > Can BBedit do this sort of range stuff?
>
> > > > > > > ______________________________________________________________________
>
> > > > > > > Hey Mark,
>
> > > > > > > Not directly.  But you can script that kind of search, or you can 
> > > > > > > find/replace in the current selection.  So you could find + 
> > > > > > > 'extend selection' to select your range and then find/replace 
> > > > > > > *within* the range.
>
> > > > > > > --
> > > > > > > Best Regards,
> > > > > > > Chris

-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to