Sublime Forum

File type specific key bindings

#1

I want to set key bindings based on file type. Found this sublimetext.userecho.com/topic/2 … thon-code/

However, my attempt doesn’t seem to work. The coffeescript macro seems to be overriding the ruby one. Any suggestions? Thanks.

[code]// ruby specific macros
// hash rocket
{
“keys”: “ctrl+.”],
“command”: “run_macro_file”,
“args”: { “file”: “Packages/User/Ruby/HashRocket.sublime-macro” },
“context”: {
“key”: “selector”, “operator”: “equal”, “operand”: “source.ruby”
}
},

// coffeescript macros
{
    "keys": "ctrl+."],
    "command": "run_macro_file", 
    "args": { "file": "Packages/User/CoffeeScript/Arrow.sublime-macro" },
    "context": {
        "key": "selector", "operator": "equal", "operand": "source.coffeescript"
    }
}[/code]
0 Likes

#2

Sweet, that was it. Thanks!

0 Likes

#3

I am trying to add a hashrocket macro to my install. Would you consider sharing the final key bindings code incl. the context and the macro files? I am trying to create my own macro files but as a newbie I am about to give up.

Thank you!

[quote=“Axsuul”]I want to set key bindings based on file type. Found this sublimetext.userecho.com/topic/2 … thon-code/

However, my attempt doesn’t seem to work. The coffeescript macro seems to be overriding the ruby one. Any suggestions? Thanks.

[code]// ruby specific macros
// hash rocket
{
“keys”: “ctrl+.”],
“command”: “run_macro_file”,
“args”: { “file”: “Packages/User/Ruby/HashRocket.sublime-macro” },
“context”: {
“key”: “selector”, “operator”: “equal”, “operand”: “source.ruby”
}
},

// coffeescript macros
{
    "keys": "ctrl+."],
    "command": "run_macro_file", 
    "args": { "file": "Packages/User/CoffeeScript/Arrow.sublime-macro" },
    "context": {
        "key": "selector", "operator": "equal", "operand": "source.coffeescript"
    }
}[/code][/quote]
0 Likes

#4

Dude!
You were nearly there :smile:

There is an error in your context:

"context": { "key": "selector", "operator": "equal", "operand": "source.js" } ]

you see ? The context must be in an array!

Thank you for this it will really help me in the future !

0 Likes