1

Is there any way that we can create snippets in Atom with variables (someway like Emmet did in HTML)?

Here's an example that we want to achieve:

From: p4

To: padding: 4% 4% 4% 4%

( From: p[i] to padding: i% i% i% i% ) (the user input p+[i] , i is variable )

2
  • For me it's not really clear, what is the difference from $1 that you can use in snippet. Please add some more explanation Commented Jan 9, 2017 at 11:29
  • It's like: if you press in "p4" , the result will be "padding 4% 4%" . If you press in "p5" , the result will be "padding 5% 5%" . Something like that :) Commented Jan 9, 2017 at 16:01

1 Answer 1

2

To my knowledge you are not able to do that with Atom snippets because they are composed with just CSON (i.e. no scripting). So while you can't do that you can use a single variable and expand it into multiple locations in your snippet, something I learned in this blog that I read here

Taken from that post, here is example CSON to do that:

'.source.css':
   'Padding With Mostly Identical Values':
     'prefix': 'pwmiv'
     'body': 'padding: ${1:num}px ${1:num}$2px ${1:num}$3px ${1:num}$4px;'

Looking at it, it looks like you can also tab through each placeholder to edit any paddings that need to be different.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.