Sublime Forum

Trigger find in all open files / project via Sublime command

#1

I have a plugin I’m working on to trigger finding the current selection within all open files / project (Find in Files…).

Anyone know how I trigger this via a Sublime command? I’ve gotten as far as grabbing the selection, or if there is no selection the word the cursor is currently within.

import sublime, sublime_plugin


class QuickSearchCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():
            line = self.view.word(region)
            if region.empty():
                # search with self.view.substr(line) here
            else:
                # search with self.view.substr(region) here
0 Likes

#2

You’ll definitely be able to open the find in files panel, but I don’t know if you’ll actually be able to initiate a search from your plugin (maybe try sending the “return” key?). In any case I don’t think you can find in files without going through the panel—the underlying functionality isn’t available through the API.

0 Likes

#3

Run this after selecting your string. This should get you the “Find in files” panel open with your selected string handy.

view.run_command('slurp_find_string') window.run_command('show_panel', {'panel': 'find_in_files'})

0 Likes