Search code examples
sublimetext3sublimetext2key-bindings

Bind shortcut to command palette command?


I just installed a plugin called CodeSniffer (http://soulbroken.co.uk/code/sublimephpcs), and I want to link one of it's commands from the command palette to a keyboard shortcut because I use it so often.

Is there any easy way to do this? Or will I just need to ask the developer what the name of the command is (in the command palette it is 'PHP CodeSniffer: Clear sniffer marks')?

Thanks


Solution

  • It's actually very easy to find the name of a command but it requires a few steps.

    • Open Sublime Text's built-in console (control+`)
    • Type in sublime.log_commands(True)
    • Trigger the command from the command palette

    The name of the command will be logged to the console. Then open your user keybindings and create a new keybinding like this:

    { "keys": ["YOUR_SEQUENCE"], "command": "YOUR_COMMAND" }
    

    I provided a similar answer here: Keymap Sublime Text 2 File Type?