Sublime Forum

Binding a key to a succession of commands

#1

Hi everyone,

While the Find panel is opened, I wanted F3 to close that panel before going to the next match.
The only thing that I got to work was this:

import sublime,sublime_plugin
class findNextHidePanelCommand(sublime_plugin.WindowCommand):
	def run(self):
		self.window.run_command("hide_panel")
		self.window.run_command("find_next")

keymap FILE: { "keys": "f3"], "command": "find_next_hide_panel", "context": {"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}] },

Is there a simpler way to do this, for example inside of the keymap file ?

Thank you for you help
William.

0 Likes

#2

You can always record a macro (ctrl+q)…
Take a look at the Default folder and .sublime-macro files.

0 Likes

#3

[quote=“iamntz”]You can always record a macro (ctrl+q)…
Take a look at the Default folder and .sublime-macro files.[/quote]

This is the first solution I tried. Since I did not find how to store a recorded macro in a file, I created a .sublime_macro file containing the following:


	{"command": "hide_panel"},
	{"command": "find_next"}
]

But when I tried it, I had errors in the output

Unknown macro command hide_panel
Unknown macro command find_next
0 Likes

#4

After you record a macro, you go to tools->save macro.

0 Likes

#5

I tried the save macro menu, but no explorer window appeared, and I understand now that it was because the macro failed to record.
So how do you proceed for recording such a macro ?
I tried:

]Open the Find panel and make a valid search/]
]press ctrl+q (status = “starting to record macro”)/]
]press F3 to find the next match/]
]press echap to close the find panel/]
]press ctrl+q (status is “starting to record macro” again…)/]

0 Likes

#6

Should I conclude that this was the easier way to do it, after all ?
I was expecting something like the code below to work, but It executed only one of the commands (the last one if I remember correctly).

{ "keys": "f3"], "command": "find_next", "command": "hide_panel", "context": {"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}] },

0 Likes