Sublime Forum

Programmatic 'Find in files'

#1

Hi all,

Is there a command to trigger ‘find in files’, say from a plugin? If so, what is the command and what does it return? I ask as I have just written a plugin that needs to search open folders given a set of regexp patterns. I use pss, a python clone of ack and it works well but I’d rather use a built in mechanism if available.

cheers,
Rob Cowie

0 Likes

#2

Is it possible to create a text command that will run find in files?

0 Likes

#3

Yes. You can if you wanted to.

import sublime
import sublime_plugin

class CustomFindInFilesCommand(sublime_plugin.TextCommand):

	def run(self, edit):
		self.view.window().run_command("show_panel", {
			"panel": "find_in_files",
			"where": "<current file>",
			"whole_word": True,
			"preserve_case": True,
			"regex": True,
			"show_context": True,
			"use_buffer": False,
			"case_sensitive": True
		})
1 Like

#4

Thanks :slight_smile:

That does what I want. :slight_smile:

Does anyone know where the find_in_files, slurp_find_string, find_all are defined? They are not in the Default folder plugins, I would like to take a peek of all the possible args to them.

class SideFind(sublime_plugin.TextCommand):
    def run(self, edit):
        # prepare find
        self.view.window().run_command("show_panel", {
            "panel": "find_in_files",
            "preserve_case": True,
            "case_sensitive": True,
            "whole_word": True,
            "use_buffer": False,
            # "where": "<current file>",
            # "regex": True,
            # "show_context": True,
        })
        # select word or selection under cursor
        self.view.window().run_command("slurp_find_string")
        # perform find
        self.view.window().run_command("find_all")
0 Likes

#5

For find_in_files, I just had a snippet saved on my local machine for all of it’s args after I read some answer on either the forum or SO and I don’t think those args are defined anywhere in the Default plugins or keybindings. People have just used trial & error to find the args. As for slurp_find_string & find_all, I don’t think they have any args defined on them.

I usually use this yaml file as a reference for all commands and it’s nearly complete & accurate :- https://github.com/SublimeText/PackageDev/blob/master/plugins/command_completions/builtin_commands_meta_data.yaml#L21

0 Likes

#6
0 Likes