Sublime Forum

Convert selected text ' to " and back

#1

I want a way to convert ’ inverted commas to " double interted commas

and bind them to a key. like [Ctrl + k ,’ ] [ Ctrl + k ," ]

If this is possible please help me !

0 Likes

#2

Something like this would do it:

class MyReplaceCommand(sublime_plugin.TextCommand):

    def run(self, edit, **kwargs):
        selection = self.view.sel()
        for region in selection:
            self.view.replace(
                edit,
                region,
                self.callback(self.view.substr(region), {"src":"'","dst":'"'})
            )

    def callback(self, text, opts):
        return text.replace(opts["src"],opts["dst"])

    def is_enabled(self):
        return len(self.view.sel()) > 0

Simple command to replace ’ by " on selected regions, you can tweak it easily to accept generic arguments (args) to replace other type of characters you’d like or just using the whole view if you don’t want it to act on selected regions.

But… out of curiosity, why alt+f3 isn’t good enough to replace matches?

0 Likes

#3

Well thanks ,
Will try out what you have stated. Well i work with codeigniter and its a pain to convert ’ to ". So i have a need for something like what you have stated for selected region.

0 Likes