17

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

dreftymac
  • 31,404
  • 26
  • 119
  • 182
Jess
  • 8,628
  • 6
  • 49
  • 67

2 Answers2

43

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?

Community
  • 1
  • 1
Liam Cain
  • 13,283
  • 5
  • 39
  • 29
  • This helped me a ton. I was able to bind ctrl+r to the run_apex_script MavensMate command. Thanks a bunch! – Charles Naccio Sep 14 '15 at 16:39
  • on Ubuntu 18.04 Sublime build 3211 I get an error: `>>> sublime.log_commans(True) Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'log_commans'` – Michał Lepczyński Mar 18 '21 at 13:53
10

Another way is to crack open the .sublime-commands files.

Let's say you've installed Sublime Package Control (which you really want to do!) and then open it up in the command palette (⌘⇧p on os x) and install the Search Stack Overflow package. You'll now have two new commands in the command palette, the "Stackoverflow: Search Selection" and "Stackoverflow: Search from Input" commands.

OK, open the .sublime-commands file for the package. You need to find it first. If you're hardcore you do View > Show Console, and enter print(sublime.packages_path())

Otherwise it should be here

  • Windows: %APPDATA%\Sublime Text 2\Packages
  • OS X: ~/Library/Application Support/Sublime Text 2/Packages
  • Linux: ~/.Sublime Text 2/Packages
  • Portable Installation: Sublime Text 2/Data/Packages

and then "Search Stack Overflow/Default.sublime-commands"

This is the file that make the commands show up in the command palette in the first place.

It's another JSON file with entries like these

{
    "caption": "Stackoverflow: Search from Input",
    "command": "stackoverflow_search_from_input"
}

see, that's the command name right there: stackoverflow_search_from_input

Now just open the user key bindings JSON file and add the key binding like @BoundinCode said.

PapaFreud
  • 3,636
  • 4
  • 34
  • 45
  • **See also:** The "installed packages" subdirectory if you do not find it in any of the above-suggested locations. – dreftymac Jul 19 '18 at 00:01
  • and if your package is in `Installed Packages` then you will need to open the archive file (like e.g.: `Terminus.sublime-package`) to be able to navigate to `Default.sublime-commands` – Michał Lepczyński Mar 18 '21 at 13:59