Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code snippet - escape ${file}

Tags:

I'd like to create a snippet in VS Code, which includes exact string ${code}. However, when I enter it in this form, VS Code tries to interpret it as snippet parameter. How should I escape it properly?

like image 699
Spook Avatar asked Mar 08 '17 10:03

Spook


People also ask

How do you escape VS Code?

An extension for VS Code that allows you to escape/unescape quotes in the selected string. After installing the extension, when you select text and right-click on it, a new Escape quotes menu will appear.

Where are VS Code snippets stored?

Project-folder snippets are created with the New Snippets file for ' '... option in the Preferences: Configure User Snippets dropdown menu and are located at the root of the project in a . vscode folder. Project snippet files are useful for sharing snippets with all users working in that project.

How do I create a custom snippet in VS?

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.

How can I see snippets in VS Code?

In VS Code, snippets appear in IntelliSense ( Ctrl+Space gives you a suggestion list), they are mixed in with other suggestions. You can also access them in a dedicated snippet picker by using the 'Insert Snippet' command. This combines all user, extension, and built-in snippets for that language into a single list.


1 Answers

"}" AND "$" can be escaped with "\\". Some cases "$" can be escaped with "$$" but not in your case.

Your snippet should look like this.

"Return Code With Squirly And Dollar": {
    "prefix": "code_snippet",
    "body" : [
        "\\${code\\}"
    ],
    "description": "Code Snippet"
}

This should help you

like image 94
Quentin Avatar answered Feb 07 '23 15:02

Quentin