Sublime Forum

"Unwrap" selection

#1

I find myself often attempting something like replacing double quotes with single-quotes.

Basically, I really really enjoy the “wrap” feature where you select some text, and then hit any of the keys like double-quote, single-quote, open-paren, open-bracket, etc., and it wraps your selection in those characters.

It’d be even more awesome if we had a shortcut key that could do something similar to this but enhanced. Hit a key and it will search out to select the text inside the nearest “wrapped” bit of text, then another shortcut which can remove those “wrapping” characters. Or it could automatically remove them because it’s super fast to re-make the same one anyway. This way a 3 keystroke combination can be used to modify the wrapping of stuff very quickly without having to manually do the closing.

Furthermore, this function can stack with the multi-cursor feature to allow you to perform this sort of operation on big swaths of code quickly. Have a bunch of double-quoted strings that are not structurally related but you want to replace certain ones with single-quotes? just ctrl+click in all the “regions”, and then fire off two keystrokes. I do believe there is a vast space of amazing cool things we can do with these multi-selects.

I’m sure this is a trivial task for somebody to write given the rich API that is exposed for querying and modifying selection, I just am too busy to look into it now :blush: :laughing:

Update: I realized that Ctrl+Shift+M (where Ctrl+M is find matching bracket) allows for selecting the contents wrapped by the nearest set of matching brackets containing the cursor. Will just need to extend this slightly to also include quote characters in this logic as well, and something for deleting/replacing those characters.

0 Likes

#2

Found this:

github.com/spadgos/sublime-ToggleQuotes

It’s really quite excellent and is so good at what it does that I can’t really justify building something very similar anymore.

0 Likes

#3

Also BracketHighlighter does that (and a lot of other awesome things!)

0 Likes

#4

Yes I have just re-discovered BH. This topic is completely obsolete. What an awesome plugin.

0 Likes