Sublime Text 2 - key binding to change syntax

BindingSyntaxSublimetext2Key Bindings

Binding Problem Overview


I want to make a new key binding to change syntax to, let's say, HTML or CSS. I searched the official and unofficial documentation to see if there are any answers to my problem.

Binding Solutions


Solution 1 - Binding

Use the following key combination to pull up the command palette:

Ctrl+Shift+P

then type:

sshtml (for example, to set the syntax to HTML)

Solution 2 - Binding

This is how i roll, if that's what you meant exaclty:

// Syntax Change
{"keys": ["alt+shift+h"], "command": "set_file_type",
"args": {"syntax": "Packages/HTML/HTML.tmLanguage"}
},


{"keys": ["alt+shift+m"], "command": "set_file_type",
"args": {"syntax": "Packages/Markdown/Markdown.tmLanguage"}
},


{"keys": ["alt+shift+p"], "command": "set_file_type",
"args": {"syntax": "Packages/PHP/PHP.tmLanguage"}
},


{"keys": ["alt+shift+j"], "command": "set_file_type",
"args": {"syntax": "Packages/Javascript/JSON.tmLanguage"}
},

Solution 3 - Binding

There is an easy way to do that.
On the right bottom, there is a button, click on that button you will get all the available syntax. enter image description here

Solution 4 - Binding

You can use the Command Pallet (ctrl + shift + p) to change the Syntax, but sometimes using "ss" or "sshtml" brings up other commands that are un-related to the "Set Syntax" options.

You can also add a new Key Binding User Preference that brings up the Command Pallet with the text "Set Syntax: " already in it. Then you just have to type the language you want to set it to.

To setup this key-binding shortcut:

  1. Open the Command Pallet (ctrl + shift + p)
  2. Find and select the "Preferences: Key Bindings" option
  3. Update your User ".sublime-keymap" file to have the "keys" json-object listed in the array:
[    "// additonal/exsiting key comands go here...",    { "keys": ["ctrl+alt+l"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": "Set Syntax: "} }
]

Now you can use ctrl+alt+l to bring up the command prompt. Then just type HTML, CSS, or whatever language you're looking to switch too.

Feel free to change the "keys" combination from ctrl+alt+l to anything else you want the shortcut to be too.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexView Question on Stackoverflow
Solution 1 - BindingamitchhajerView Answer on Stackoverflow
Solution 2 - BindingdzhiView Answer on Stackoverflow
Solution 3 - BindingPushpam KumarView Answer on Stackoverflow
Solution 4 - BindingSteven SouleView Answer on Stackoverflow