53

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.

pjpscriv
  • 866
  • 11
  • 20
Alex
  • 533
  • 1
  • 4
  • 4

5 Answers5

130

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)

pjpscriv
  • 866
  • 11
  • 20
amitchhajer
  • 12,492
  • 6
  • 40
  • 53
  • That will have to do. Thanks! – Alex Sep 01 '12 at 12:55
  • 5
    Very quick way to check out multiple syntaxes by just typing ss and select from that list (hint: you can use arrow keys to select the next/previous) – WOUNDEDStevenJones Sep 03 '13 at 19:23
  • 9
    For the record, on OS X, it's `⌘ + Shift + p` to pull up the command palette. – Andi Aug 11 '15 at 13:48
  • this doesn't actually answer the question at all. the response below by @dzhi does. use that. and pay attention to the comment about JavaScript for ST3. – WhiteRau Aug 07 '20 at 19:48
34

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"}
},
pjpscriv
  • 866
  • 11
  • 20
dzhi
  • 1,534
  • 2
  • 18
  • 29
2

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

Pushpam Kumar
  • 132
  • 1
  • 11
1

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.

0

dzhi's answer doesnt work anymore for JSON in Sublime 4.

The correct path is

Packages/JSON/JSON.tmLanguage

SomeGenericDev
  • 359
  • 2
  • 7