sublime-text-plugin icon indicating copy to clipboard operation
sublime-text-plugin copied to clipboard

How to write a snippet for javascript?

Open BigTolly opened this issue 4 years ago • 4 comments

For example, how to do this: "cl": "console.log(' $ ');" $ - cursor

Emmet.subling-settings: { "config": { "html": { "snippets": { "test": ".gg", // working "c": "{Hello}", // working } }, "css" : { "snippets" : { "pss" : "padding: 1px 2px 1px 2px;" // working } }, "markup" : { "snippets" : { "cl": "console.log();" // does not work } } } }

BigTolly avatar Aug 26 '21 06:08 BigTolly

It's better to use native Sublime Text snippets in your case. If you still want to create Emmet snippet, you should wrap custom text with {}, e.g. {console.log()}.

Emmet snippets are actually aliases for Emmet abbreviations, you define output structure with it

sergeche avatar Aug 26 '21 07:08 sergeche

{ "config": { "html": { "snippets": { "cl": "{console.log();}, // it works in html } }, "css" : { "snippets" : { "cl": "{console.log();}, // it works in css } }, "markup" : { "snippets" : { "cl": "{console.log();}" // it doesn't work in js (javascript) } } } }

BigTolly avatar Aug 26 '21 08:08 BigTolly

Not sure what you mean. Emmet doesn't work in JS by default, only in JSX with prefixed mode: https://github.com/emmetio/sublime-text-plugin#jsx-support

sergeche avatar Aug 26 '21 09:08 sergeche

OK, thanks.

BigTolly avatar Aug 26 '21 09:08 BigTolly