C
C
creatoroftheworld2016-07-12 12:48:39
HTML
creatoroftheworld, 2016-07-12 12:48:39

How to set default syntax for Sublime Text 3 new tab. Or allow Emmet snippets to be used for Plain Text syntax?

The goal is to have emmet available when creating a new tab in sublime. So, there are two ways:
1. Set html to the default syntax, which is not in "preferences" -> "settings - default".
2. Allow emmet for Plain Text syntax. In Emmett's config, I found that you can do this:

"syntaxProfiles": {
  "html": "xhtml",
  "css": "css_line",
  "plain text": "xhtml" // * вот тут не хавает, хотя я пробовал по всякому: plain_text, plainText и тд
}

but, in general, it does not work, although everything seems to be simple. I would be glad if someone points out where I blunted ^^

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sasha Chernykh, 2016-07-16
@creatoroftheworld

1. Creating your own plugin
PreferencesBrowse Packages...→ in the folder, Usercreate a file default_syntax.pywith the following content:

import sublime, sublime_plugin
class DefaultSyntaxCommand(sublime_plugin.EventListener):
  def on_new(self, view):
    view.set_syntax_file('Packages/HTML/HTML.tmLanguage')

We save. Now, by default, new files will open with the HTML syntax where Emmet works.
"syntax_mapping": {
    "Packages/Python/Python.sublime-syntax": ["import"],
},

Don't get confused by the JSON syntax , make sure you use quotes, parentheses, and commas correctly. For example, my AutoSetSyntax.sublime-settings file looks like this:
{
    "syntax_mapping": {
        "ANSIescape/ANSI.tmLanguage": ["^\\s*\\[[email protected]*\\] git l\\b"],
        "Packages/PHP/PHP.sublime-syntax": ["<\\?php", "<\\?="],
        "Packages/Python/Python.sublime-syntax": ["import"],
    },
    "working_scope": "(?x)^(text.plain | source.diff)\\b"
}

Save the file → after entering the import statement, the syntax of the new file should be defined as Python.
Sublime Text 3 API Additional Links ,
ApplySyntax Plugin Documentation ,
Configuring Automatic Syntax Detection d... ,
Babel script highlighting not working in Sublime Text 3... ,
Thanks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question