Sublime Forum

How to override enter in find in files panel?

#1

Pressing enter always performs the search, unlike find or replace panels that are perfectly fine with:

{
   "keys": ["enter"],
   "command": "insert",
   "args": {"characters": "\n"},
   "context": [{"key": "panel", "operand": "find_in_files"}, {"key": "panel_has_focus"}]
},
0 Likes

#2

Are you trying to set up a key binding that executes the search when you press enter?

If so, there are already bindings to do that that you can check out; you want to use the find_all command instead:

	// Find in Files panel key bindings
	{ "keys": ["alt+enter"], "command": "find_all",
		"context": [{"key": "panel", "operand": "find_in_files"}, {"key": "panel_has_focus"}]
	},
	{ "keys": ["ctrl+alt+enter"], "command": "replace_all",
		"context": [{"key": "panel", "operand": "find_in_files"}, {"key": "panel_has_focus"}]
	},
0 Likes

#3

I’m actually trying to make enter insert a newline in the search box.

My problem is that the find_in_files doesn’t even have a rule for enter, and the ones I assign are ignored (but they work in both find and replace panels). I believe it to be hardcoded somewhere else.

0 Likes

#4

on Linux / Windows, enter newlines using Ctrl + Shift + Enter in the search box.

0 Likes

#5

@usig That works before you have a previously defined line

{ "keys": ["ctrl+shift+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line Before.sublime-macro"} },

I can bind any key other than enter when in find in files panel. Enter always performs the search.

0 Likes

#6

my bad.

Enter Ctrl + Enter to add a new line after the text
Enter Ctrl + Shift + Enter to add a new line before the text
Enter Enter to perform the search

0 Likes

#7

Yes, I know. That works because you have rules in your Default.sublime-keymap:

{ "keys": ["ctrl+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line.sublime-macro"} },
{ "keys": ["ctrl+shift+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line Before.sublime-macro"} },

If you are to change either of those lines to "keys": ["enter"] without a modifier, the rule will not be respected when in find in files panel. It will instead perform a search, without even logging the command (presumably find_all) in console.

The rule to bind find_all to enter in find in files panel does not exist in the default keybinds, and it cannot be overridden.

0 Likes

#8

The enter key is indeed currently hard-coded for the find in files dialog. We’ve got a fix for this in the works.

2 Likes