user2683458
user2683458

Reputation: 105

Search and Replace Key Bindings in Sublime Text

I want that when ever I press ctrl+alt+m the Sublime Text find and replace all (in selected text).

Find for (regex):

(\.\w+)[[:blank:]]*(\(.+),

replace with:

\1 \2,

how can I do so?

Upvotes: 2

Views: 509

Answers (1)

nicosantangelo
nicosantangelo

Reputation: 13736

As @longhua said, you could write a plugin for this, for example:

import sublime, sublime_plugin
import re

class ReplacerCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():
            selected_text = self.view.substr(region)
            new_text = re.sub("(\.\w+)[[:blank:]]*(\(.+)", '\1 \2,', selected_text)
            self.view.replace(edit, region, new_text)

Save it in your Packages folder, and then you can add a Keybinding to run it:

{ "keys": ["ctrl+alt+m"], "command": "replacer" }

Hope it helps

Upvotes: 1

Related Questions