4

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"}
dreftymac
  • 31,404
  • 26
  • 119
  • 182
Matteo Rigoni
  • 43
  • 1
  • 1
  • 4
  • **See also:** https://stackoverflow.com/questions/11834652/bind-shortcut-to-command-palette-command for a general solution on adding keybindings, not specific to this package. – dreftymac Jul 18 '18 at 23:55

3 Answers3

8

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"
    }
]
DaV
  • 755
  • 2
  • 8
  • 17
3

Your binding should be

{ "keys": ["ctrl+shift+h"] , "command":"hex_viewer"}
hsarret
  • 446
  • 1
  • 3
  • 10
1

you could use something like this to assign a key biding to a plugin

-> Preference -> key - bending - user

then add this

[
    { "keys": ["ctrl+shift+x"], "command": "the name of plugin." }

]
Kosh
  • 6,140
  • 3
  • 36
  • 67