Sublime Text 2 - key binding to change syntax
Asked Answered
B

5

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.

Bandmaster answered 1/9, 2012 at 12:38 Comment(0)
B
133

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)

Burka answered 1/9, 2012 at 12:43 Comment(4)
That will have to do. Thanks!Bandmaster
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)Loughlin
For the record, on OS X, it's ⌘ + Shift + p to pull up the command palette.Tourneur
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.Zebulen
F
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"}
},
Flack answered 2/11, 2012 at 11:32 Comment(3)
~/Library/Application Support/Packages/User/Default (OSX).sublime-keymapJemina
To find other .tmLanguage files, I went to Sublime's Preferences > Browse Packages.Stricklan
As of Sublime Text 3 build 3126 this is also working with the exception that javascript is under the path /Packages/JavaScript/ (capital S for Script)Renfred
I
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

Ingenious answered 7/5, 2019 at 8:29 Comment(0)
B
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.

Bootie answered 12/9, 2019 at 18:16 Comment(0)
S
0

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

The correct path is

Packages/JSON/JSON.tmLanguage

Substituent answered 5/8, 2022 at 8:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.