Custom JavaScript snippets for emmet (in Sublime Text 2)

百般思念 提交于 2020-01-02 06:34:11

问题


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.


回答1:


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.

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

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.

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



来源:https://stackoverflow.com/questions/16924477/custom-javascript-snippets-for-emmet-in-sublime-text-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!