Modify all instances of selection a la columnar selection

149 views
Skip to first unread message

Gustave Stresen-Reuter

unread,
Jul 13, 2016, 9:59:48 AM7/13/16
to bbe...@googlegroups.com
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)?

TIA,

Ted

Christopher Stone

unread,
Jul 13, 2016, 4:07:13 PM7/13/16
to BBEdit-Talk
On Jul 13, 2016, at 08:59, Gustave Stresen-Reuter <tedmas...@gmail.com> 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

Fletcher Sandbeck

unread,
Jul 13, 2016, 4:31:52 PM7/13/16
to bbe...@googlegroups.com
The menu shortcuts make replacements like this pretty fast. Select the text you need to change, Command-E to set the find pattern, replace the text and re-select it, Command-Option-E to set the replacement pattern, and then Command-Option-= to replace all. I think those are all standard shortcuts.

I usually modify this slightly. I have Command-Option-F set to Replace and Find Next so I usually cycle through the document that way rather than doing a Replace All, glancing at the replacements as I go to make sure they are all valid. If any aren't, I use Command-G to skip over them.

[fletcher]


--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"sup...@barebones.com" 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 bbedit+un...@googlegroups.com.
To post to this group, send email to bbe...@googlegroups.com.

Gustave Stresen-Reuter

unread,
Jul 14, 2016, 4:11:02 AM7/14/16
to bbe...@googlegroups.com
Thanks. I've been resorting to the Find and Replace myself but when programming, it would be so nice to just have it all happen at the same time so I don't stupidly miss one.

I too smell a new feature coming (hey, we can already underline all instances of a word) but who knows… There may be higher priorities!

Ted

Neil Faiman

unread,
Jul 14, 2016, 8:56:14 AM7/14/16
to BBEdit Talk Mailing List

> On Jul 13, 2016, at 4:31 PM, Fletcher Sandbeck <flet...@cumuli.com> wrote:
>
> The menu shortcuts make replacements like this pretty fast. Select the text you need to change, Command-E to set the find pattern, replace the text and re-select it, Command-Option-E to set the replacement pattern, and then Command-Option-= to replace all. I think those are all standard shortcuts.

But note that this replaces all occurrences of the STRING, not all occurrences of the SYMBOL. If the symbol you want to modify is a substring of some other symbol, or if you use symbols with the same name in different places in a file, you get an unwelcome surprise.

Neil Faiman

Barbara Snyder

unread,
Jul 14, 2016, 9:53:07 AM7/14/16
to BBEdit Talk
Select, Copy, Find, Paste, Replace all - Selected text only (if appropriate)

If I understand your question correctly, that's how I do it.
Reply all
Reply to author
Forward
0 new messages