Create Snippet with variables in Atom

折月煮酒 提交于 2019-12-04 03:14:48

Update 2016-09

This is now supported in Atom - please see the other answer for how to use it. I can't delete this answer since it is the accepted one...

Old Answer

The documentation for the snippets package has an example that shows how to predefine the default value for a variable:

'.source.js':
  'console.log':
    'prefix': 'log'
    'body': 'console.log(${1:"crash"});$2'

In the above example, crash is used as the default value for the log statement, allowing you to provide your own value by overwriting the crash default.

I guess what you're asking is whether there's a way to automatically use a value you typed and then apply it to the other instances of the same placeholder. So in your example, when you're at variable $1 and type foo, that it uses foo for all other occurrences of ${VAR}, right?

That's currently not possible from what I understand. I suggest you open a feature request at the snippets package's repo, or even better take a stab at adding this functionality and then creating a pull request.

Sorry if this doesn't help you, but you asked whether there was a way of doing this with the current version of Atom. The answer seems to be No at the present time.

Current version of Atom can support this kind of snippet. You can just put $1 at every places you want.

'.source.coffee':
  'For-Loop':
    'prefix': 'fori'
    'body': 'for (int ${1:i} = $2; ${1:i} < $3; ${1:i}++) {\n\t$4\n}'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!