Add shortcut key for multiple plugins in Sublime Text 3

…衆ロ難τιáo~ 提交于 2021-02-11 15:37:02

问题


I'm using CodeFormatter and SassBeautify plugins in Sublime Text 3 in order to provide syntax highlighting and formatting for .scss files as well as .js/.html files. I've been able to set up shortcut keys for either plugin, but not to work for both, depending on the type of file I'm in.

[{
    "keys": ["ctrl+alt+f"],
    "command": "sass_beautify"
}, {
    "keys": ["ctrl+alt+f"],
    "command": "code_formatter"
}]

Can someone suggest how do to it? I've tried to understand "contexts" but not well enough to do this.

Am I doing this all wrong? Is there another way I should be achieving this?

Corrected keymap file:

[{
    "keys": ["ctrl+alt+f"],
    "command": "sass_beautify",
    "context": [{
        "key": "selector",
        "operator": "equal",
        "operand": "source.scss"
    }]
}, {
    "keys": ["ctrl+alt+f"],
    "command": "code_formatter",
    "context": [{
        "key": "selector",
        "operator": "not_equal",
        "operand": "source.scss"
    }]
}]

回答1:


Add something similar to the following as a context entry

{ "key": "selector", "operator": "equal", "operand": "source.scss", "match_all": true }

{ "key": "selector", "operator": "equal", "operand": "(text.html, source.js)", "match_all": true }

The operand values are scope entries. There is a platform specific key binding to display scopes in the status bar, but I don't recall what they are off the top of my head. I personally use https://github.com/facelessuser/ScopeHunter to inspect scopes.



来源:https://stackoverflow.com/questions/22910586/add-shortcut-key-for-multiple-plugins-in-sublime-text-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!