sublime text bind multiple functions on 1 button
- User
sublime text bind multiple functions on 1 button
- Assistant
sublime text bind multiple functions on 1 button
In Sublime Text, you can bind multiple commands to a single keyboard shortcut (key binding) by using a macro or a custom plugin to execute multiple functions in sequence. Sublime Text does not support binding multiple distinct functions directly to one keypress in its keymap files (Default.sublime-keymap). However, the two mentioned methods can effectively achieve the goal of performing multiple actions with a single button press.
Here's how you can do it with each approach:
A macro in Sublime Text allows you to record a series of commands and then run them all at once.
Record a Macro:
Tools -> Record Macro.Tools and selecting Stop Recording Macro.Save the Macro:
Tools -> Save Macro.... Save it in your User directory, which you can easily find through Preferences -> Browse Packages... then navigating to the User folder.Bind the Macro to a Key:
Preferences -> Key Bindings.{ "keys": ["ctrl+shift+m"], "command": "run_macro_file", "args": {"file": "Packages/User/your_macro_name.sublime-macro"} }
If you need more complex logic than what a macro can provide (such as conditionals or loops), or if you want to combine functions that can't be directly recorded in a macro, you can write a custom plugin.
Create a New Plugin:
Tools -> Developer -> New Plugin.... This will open a new file with some boilerplate code.Implement Your Command:
import sublime
import sublime_plugin
class MultiFunctionCommand(sublime_plugin.TextCommand):
def run(self, edit):
# Your custom command logic here
self.view.run_command('first_command')
self.view.run_command('second_command')
# Add more commands as needed
Save Your Plugin:
Packages/User) with an appropriate .py filename.Bind to a Key:
Preferences -> Key Bindings and add an entry for your new command. For example:
{ "keys": ["ctrl+shift+m"], "command": "multi_function" }
Make sure that "multi_function" matches the class name of your plugin converted from CamelCase to snake_case (MultiFunctionCommand -> multi_function).Using either a macro or a plugin, you can effectively bind multiple functions or commands to a single button or key combination in Sublime Text.