Bind shortcut to command palette command?

后端 未结 2 1281
醉酒成梦
醉酒成梦 2021-01-31 20:46

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 shortcu

相关标签:
2条回答
  • 2021-01-31 21:24

    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.

    0 讨论(0)
  • 2021-01-31 21:38

    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?

    0 讨论(0)
提交回复
热议问题