Search code examples
sublimetext3key-bindings

Sublime text: how to add a key binding to hex_viewer package command


I've installed the Hex Viewer package on sublime text 3, to toggle it i use ctrl+shift+p to open the command palette, then i search for "hex" and select the command of the package to toggle the hex view.

I was wondering how to bind a key to the specific package command, I'm aware of the key bindings configuration file but I don't know what JSON line should I add to call the package command.

This is my first question on stackoverflow, sorry if I did something wrong, have a nice day!

EDIT: This is the github of the package: https://github.com/facelessuser/HexViewer It says:

There are 10 commands available via the command palette or by key-bindings.

This is the one I should like to bind

Hex Viewer: Toggle Hex View

And this is the string I've tried to paste on the key-bindings JSON file:

{"keys":["ctrl+shift+h"] , "command":"Hex Viewer: Toggle Hex View"}

Solution

  • You need to add a key binding for the Hex Viewer keymap.

    To do this, after installing Hex Viewer via Package Control, navigate to Package Settings -> Hex Viewer -> Key Bindings - Default and add the following:

    [
        {
            "keys": ["ctrl+shift+h"],
            "command": "hex_viewer"
        }
    ]
    

    To save the file, you need to ensure that the %APPDATA%\Sublime Text 3\Packages\HexViewer directory exists, assuming this is your package directory.

    There's also an example key map available on the GitHub link you mentioned with the other available commands.

    Example.sublime-keymap

    [
        {
            "keys": ["ctrl+shift+b","ctrl+shift+h"],
            "command": "hex_viewer"
        },
        {
            "keys": ["ctrl+shift+b","ctrl+shift+i"],
            "command": "hex_show_inspector"
        },
        {
            "keys": ["ctrl+shift+b","ctrl+shift+f"],
            "command": "hex_finder"
        },
        {
            "keys": ["ctrl+shift+b","ctrl+shift+e"],
            "command": "hex_editor"
        },
        {
            "keys": ["ctrl+shift+b","ctrl+shift+x"],
            "command": "hex_writer"
        },
        {
            "keys": ["ctrl+shift+b","ctrl+shift+u"],
            "command": "hex_discard_edits"
        },
        {
            "keys": ["ctrl+shift+b","ctrl+shift+="],
            "command": "hex_checksum",
            "args": {"panel": true}
        },
        {
            "keys": ["ctrl+shift+b","ctrl+shift+-"],
            "command": "hash_selection"
        },
        {
            "keys": ["ctrl+shift+b","ctrl+shift+g"],
            "command": "hash_eval"
        }
    ]