emmet的自定义JavaScript代码段(在Sublime Text 2中) [英] Custom JavaScript snippets for emmet (in Sublime Text 2)

查看:118
本文介绍了emmet的自定义JavaScript代码段(在Sublime Text 2中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些自定义的javascript片段和缩写添加到Emmet的snippets.json文件中,但我无法让它工作! (我使用的是Sublime Text 2。)

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.)

如果我把它放到settings.json的末尾

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

"javascript": {

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

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

没有任何反应。 (我明确地将文件的语法设置为javascript)

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

但如果我用'css'替换'javascript':

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

"css": {

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

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

它正确覆盖了内置的CSS代码段,并且工作正常。
(我显然将语法设置为css [否则它不起作用])

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

我缺少什么?根据这个: http://docs.emmet.io/customization/snippets/
我应该能够以这种方式定义自定义语言的片段。

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.

注意:我也尝试过'js'作为语言名称。

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

推荐答案

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

You should use js as syntax name since Sublime Text defines JavaScript scope as source.js. In future, you should use source.(SYNTAX_NAME) part for syntax name.

你不应该使用缩写片段部分,因为缩写定义了元素块,应该写为HTML元素。使用片段部分。

And you shouldn’t use abbreviations section for snippets since abbreviations defines element blocks and should be written as HTML element. Use snippets section.

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

Note that in JS files in ST editor you have to use Ctrl+E to expand abbreviations since Tab key is disabled for this syntax.

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

And, as Protractor Ninja noted, it’s not a good idea to use Emmet snippets in editors that supports native ones.

这篇关于emmet的自定义JavaScript代码段(在Sublime Text 2中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆