4

I am trying to add some custom javascript snippets and abbreviations to the snippets.json file of Emmet, but I can't get it to work! (I am using Sublime Text 2.)

If I put this into the end of the settings.json

"javascript": {

    "abbreviations": {
        "while": "while(true)\n{\n\t\n}"
    },

    "snippets": {
        "asdf": "qwerty"
    }
}   

nothing happens. (I set the syntax of the file to javascript obviously)

But if I replace 'javascript' with 'css':

"css": {

    "abbreviations": {
        "while": "while(true)\n{\n\t\n}"
    },

    "snippets": {
        "asdf": "qwerty"
    }
}

it correctly overwrites the built in CSS snippets, and works fine. (I obviously set the syntax to css [otherwise it does NOT work])

What am I missing? according to this: http://docs.emmet.io/customization/snippets/ I should be able to define snippets for custom languages this way.

Note: I have tried 'js' for the language name too.

4

1 回答 1

8

您应该使用jsas 语法名称,因为 Sublime Text 将 JavaScript 范围定义为source.js. 将来,您应该使用source.(SYNTAX_NAME)part 作为语法名称。

并且您不应该将abbreviations部分用于片段,因为缩写定义了元素块并且应该写为 HTML 元素。使用snippets部分。

请注意,在 ST 编辑器的 JS 文件中,您必须使用 Ctrl+E 来展开缩写,因为此语法禁用了 Tab 键。

而且,正如 Protractor Ninja 所指出的,在支持原生代码的编辑器中使用 Emmet 代码片段并不是一个好主意。

于 2013-06-05T15:32:11.060 回答