Sublime Forum

Toggle between two syntaxes shortcut

#1

Hello!

This is my first post here so first of all I’d like to congratulate whoever is concerned for choosing discourse as a forum app and sublime devs for this amazing app which keeps getting better and better.

So for my question:
I use mostly haml and liquid (together on the same pages) for my web developments and I keep switching back and forth between the two syntaxes depending on what I concentrate on, either markup or logic. I’ve googled and searched here but I can’t find a way to have a single shortcut (for a macro maybe?) that would do that.
Any clue or directions on how to achieve this would be more than welcome.

Thanks in advance.

0 Likes

#2

Hi,

Welcome to the forums :slightly_smiling:

It is possible with two keybindings, both of which can be bound to the same key, one that will be active in a HAML context and one in a Liquid context.

please can you link to the HAML and Liquid packages you are using on Package Control, to help us ensure we get the keybindings right for you? :slightly_smiling:

0 Likes

#3

:thumbsup: Yes, I’m using Steleaf liquid syntax and I’m not sure about haml:

0 Likes

#4

I forgot to ask what you want the shortcut to be :smiley: I’ll use alt+; in my example.

So, the important thing is to get the “base scope” and file path of the 2 syntaxes:

and here is the necessary keybindings:

{ "keys": ["alt+;"], "command": "set_file_type", "args": { "syntax": "Packages/Rails/Ruby Haml.sublime-syntax" },
    "context":
    [
        { "key": "selector", "operator": "equal", "operand": "text.html.liquid" },
    ]
},
{ "keys": ["alt+;"], "command": "set_file_type", "args": { "syntax": "Packages/Siteleaf Liquid Syntax/HTML (Liquid).tmLanguage" },
    "context":
    [
        { "key": "selector", "operator": "equal", "operand": "text.haml" },
    ]
},
3 Likes

#5

Thank you very much!

I had to reverse the order of the bindings to have it work since I open haml files in the first place:

{ "keys": ["alt+z"], "command": "set_file_type", "args": { "syntax": "Packages/Siteleaf Liquid Syntax/Syntaxes/HTML (Liquid).tmLanguage" },
    "context":
    [
        { "key": "selector", "operator": "equal", "operand": "text.haml" },
    ]
},
{ "keys": ["alt+z"], "command": "set_file_type", "args": { "syntax": "Packages/Rails/Ruby Haml.sublime-syntax" },
    "context":
    [
        { "key": "selector", "operator": "equal", "operand": "text.html.liquid" },
    ]
}

Very happy indeed :smiley:

0 Likes

#6

You can also use the command palette. I don’t know how often you switch, but it’s likely that a shortcut will still be better.

Just letting you know about this because it’ll (100% sure :smile:) be useful in the future: You can do this from the command palette:

  • ctrl+shift+p
  • ssruh for example (to select Set Syntax: Ruby Haml)
0 Likes