如何确定Sublime Text 3中自定义包快捷键绑定的参数?
Let's break down why your keybind code is throwing errors and how to fix it, specifically for the Hex Viewer package.
Why Your Current Code Fails
The issue is likely twofold:
- You're using the wrong command name (not all packages use their exact name as the command identifier)
- The
argsstructure might not match what Hex Viewer expects for the "setb" action
Step 1: Find the Exact Command & Parameters
The most reliable way to get the correct command details is to log Sublime's internal command activity:
- Open the Sublime Text console with `Ctrl+`` (backtick key)
- Paste this command and press Enter:
sublime.log_commands(True) - Manually perform the "setb" action you want to bind (e.g., via Hex Viewer's menu or command palette)
- Check the console output—you'll see a line like:
(or with args if the action requires them, e.g.,command: hex_viewer_setbcommand: hex_viewer_setb {"some_param": "value"})
This line tells you the exact command name and any required args for the action.
Step 2: Update Your Keybind
Using the command from the console, update your keybind. For example, if the console showed command: hex_viewer_setb, your keybind would look like:
{ "keys": ["ctrl+shift+12"], "command": "hex_viewer_setb" }
If there were required args, add them exactly as shown in the console:
{ "keys": ["ctrl+shift+12"], "command": "hex_viewer_setb", "args": {"param_name": "param_value"} }
Alternative Ways to Find Command Details
If logging commands doesn't work for some reason:
- Check the package's source files: Navigate to
Preferences > Browse Packages > Hex Viewerand look for aDefault.sublime-commandsfile. This file lists all the package's exposed commands and their parameters. - Check the package's documentation: Many packages include a README or documentation file in their folder that outlines available commands and keybind examples.
Quick Note on Key Combinations
ctrl+12 might be reserved by your OS or another application. If the keybind doesn't trigger, try a different combination like ctrl+shift+12 or alt+ctrl+12 to avoid conflicts.
内容的提问来源于stack exchange,提问作者Ghoul Fool

