On Feb 07, 2013, at 20:38, Zephyr Mays <[email protected]> wrote:
> I'd like to change all instances of a character in a selection without 
> invoking the find/replace dialog (in this case the _ character).
> 
> I hope to select/highlight this: These_Underscores_Should_Be_Spaces
> 
> Hit a keyboard shortcut and have this: These Underscores Should Be Spaces
______________________________________________________________________

Hey Zephyr,

Sounds like a job for Applescript.

Both scripts below require the handler.

Case-sensitive is turned on but can be changed in the regex: (?i)regexStr.

You can replicate the first script and change to any character (or regex) you 
want.  Save as an Applescript using the Applescript Editor.  Put the script in 
BBEdit's script folder:

 ~/Library/Application Support/BBEdit/Scripts/<Your_Script>

Give it a keyboard shortcut in BBEdit's prefs, and go-to-town.

The second script pops up a dialog that wants a find/replace string in the 
format:

 <find>/<replace>

This will let you do impromptu find/replace actions.  (I have not bothered to 
escape the slash character, so at this time it cannot be used as part of a 
regular expression.  It can be done though if needed.)

Note that it's also possible to do ASOGS (all kinds of good stuff) using text 
filters that employ Perl, Python, Ruby, etc.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on bbReplSel(fndStr, repStr)
  tell application "BBEdit"
    tell selection of text of front text window
      replace fndStr using repStr options {search mode:grep, case 
sensitive:true}
    end tell
  end tell
end bbReplSel
-------------------------------------------------------------------------------------------


-------------------------------------------------------------------------------------------
# Character-Specific find/replace in Selection.
-------------------------------------------------------------------------------------------
bbReplSel("_", " ")
-------------------------------------------------------------------------------------------


-------------------------------------------------------------------------------------------
# User-Selectable find/replace in Selection.
-------------------------------------------------------------------------------------------
try
  
  set fndReplStr to text returned of (display dialog "Enter String to Replace" 
default answer "Find/Replace")
  set AppleScript's text item delimiters to "/"
  set {fStr, rStr} to (text items of fndReplStr)
  bbRepl(fStr, rStr)
  
on error e number n
  if n ≠ -128 then
    set e to e & return & return & "Num: " & n
    tell me to set dDlg to display dialog e with title "ERROR!" buttons 
{"Cancel", "Copy", "OK"} default button "OK"
    if button returned of dDlg = "Copy" then set the clipboard to e
  end if
end try
-------------------------------------------------------------------------------------------

-- 
-- 
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>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to