On Jul 13, 2016, at 08:59, Gustave Stresen-Reuter <[email protected]>
wrote:
> Is it possible to select a word, start typing, and at the same time update
> every instance of that word the same way the vertical selection works (select
> a column of text and start typing and all lines are updated)?
______________________________________________________________________
Hey Ted,
No. Based on recent changes I have to think this feature is bouncing around in
the back of Rich's brain though. :)
That sort of refactoring has been commonly available in various IDEs and
programming editors for a long time and is bloody useful, so I hope it makes
its way into BBEdit sometime soon.
In the meantime it's possible to do this in a less organic fashion with
AppleScript.
Select the word.
Hit a keyboard shortcut.
Popup a dialog.
Enter a string.
Hit the OK button.
All instances in the document are updated.
Selection is restored to the original instance.
This is most easily done on a whole word basis, but strings that begin words,
end words, and are within words could be managed with some clever scripting.
Here is a very basic example.
I've used word boundaries in the regex, so currently this will only work on a
string that has clear boundaries at beginning and end.
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2016/07/13 13:30
# dMod: 2016/07/13 14:06
# Appl: BBEdit
# Task: Refactor selection in front BBEdit text document.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Refactor, @Text
-------------------------------------------------------------------------------------------
tell application "BBEdit"
tell front text document's window
set selectedText to contents of selection
set regexPattern to "\\b" & selectedText & "\\b"
set replacementWord to getReplacementWord(selectedText) of me
replace regexPattern using replacementWord options {search mode:grep,
case sensitive:false, starting at top:true}
end tell
end tell
-------------------------------------------------------------------------------------------
--ยป HANDLERS
-------------------------------------------------------------------------------------------
on getReplacementWord(defaultText)
set replacementWord to text returned of (display dialog "Type your
replacement text:" default answer defaultText with title "Refactor")
return replacementWord
end getReplacementWord
-------------------------------------------------------------------------------------------
--
Best Regards,
Chris
--
This is the BBEdit Talk public discussion group. 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].
To post to this group, send email to [email protected].