Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping the $ character in snippets

I find myself doing a ton of jQuery these days, so I started to abstract out some of the common things I do into snippets. I look forward to sharing these with the community, but I'm running into an issue right now.

The literals in snippets are defined by adding dollar signs ($) around the name of the literal to delimit where the value you would like to provide will go. This is difficult because jQuery uses the dollar sign notation in order to use a lot of its functionality.

What is the escape sequence for snippets, so I am able to use the dollar sign, and have my snippets still function?

like image 501
cory-fowler Avatar asked Jul 09 '10 18:07

cory-fowler


People also ask

How do I edit snippets?

To edit an existing Snippet, click on the Pencil in the top right corner of any Snippet. A new window will pop up, where you can replace the default text or settings with something new. To save your changes, click Update. To delete a Snippet, click the Trash Can in the top right corner of that Snippet.

How do you enter code snippets?

With a code file open in the editor, choose Snippets > Insert Snippet from the right-click menu, then My Code Snippets. You should see a snippet named Square Root. Double-click it. The snippet code is inserted in the code file.


2 Answers

To have a literal $ try doubling it: $$

like image 108
Ahmad Mageed Avatar answered Oct 07 '22 16:10

Ahmad Mageed


This is the right way for Visual Studio Code: \\$.

This makes the $ a literal part of the snippet rather than the start of a $-prefixed construct.

like image 37
Jesus David Sanchez Suarez Avatar answered Oct 07 '22 17:10

Jesus David Sanchez Suarez