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
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).
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.
It's actually very easy to find the name of a command but it requires a few steps.
sublime.log_commands(True)
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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With