Question

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"
    }]
}]
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top