Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 933
Ben Avatar asked Aug 06 '12 19:08

Ben


People also ask

What is the shortcut key for command line?

The quickest way to open a Command Prompt window is through the Power User Menu, which you can access by right-clicking the Windows icon in the bottom-left corner of your screen, or with the keyboard shortcut Windows Key + X. It'll appear in the menu twice: Command Prompt and Command Prompt (Admin).

How do I add a shortcut to Visual Studio code?

All keyboard shortcuts in VS Code can be customized via the keybindings. json file. To configure keyboard shortcuts through the JSON file, open Keyboard Shortcuts editor and select the Open Keyboard Shortcuts (JSON) button on the right of the editor title bar. This will open your keybindings.


2 Answers

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?

like image 71
Liam Cain Avatar answered Oct 25 '22 19:10

Liam Cain


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.

like image 24
PapaFreud Avatar answered Oct 25 '22 21:10

PapaFreud