Sublime Forum

Create a command in Command Palette for quirk search in specific files

#1

Dear all,

I am somewhat new to sublime text and I want to create a command in command palette that quick search for a query.

For example, the command would have the format:
Search: {query}

And the query would be performed (project-wise) in the folders having pre-defined regex rules (ex: .txt,.csv)

So basically, I want to build a command that automatically place the “Find” option with “{query}” and the “Where” option with a fixed pre-defined regex (ex “.txt,.csv”)

Is this possible? If yes, how to do this?

0 Likes

#2

Basically you can add various “Find” commands with all sorts of preset-values by adding something like the following to Packages/User/Default.sublime-commands.

	{
		"caption": "Find ...",
		"command": "show_panel",
		"args": {
			"panel": "find",
			"pattern": "",
			"replace_pattern": "",
			"reverse": false,
			"regex": false,
			"in_selection": false,
			"whole_word": false,
			"preserve_case": false,
			"use_gitignore": true,
			"highlight": true,
			"wrap": true,
			"toggle": true,
			"toggle_when_not_focused": true
		},
	}

To be able to enter a search query, a plugin would be needed, which provides an TextInputHandler to capture it and call the show_panel command with user input applied to pattern argument. Not sure it is more efficient than directly entering a search query in find panel.

Find++ already provides various commands such as Find in Open Folders, Find in Project, etc.

1 Like