Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code snippet invalid control character

I have the following user snippet:

{
/*
    // Place your snippets for JavaScript React here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    "Print to console": {
        "prefix": "log",
        "body": [
            "console.log('$1');",
            "$2"
        ],
        "description": "Log output to console"
    }
*/
    "Small comment": {
        "prefix": "//=",
        "body": [
            "// ===================================",
            "// ${1:COMMENT}",
            "// ==================================="
        ],
        "description": "Small comment"
    }
}

I get the following error on the second body line:

Invalid characters in string. Control characters must be escaped.

I thought that ${1:somestring} was a valid placeholder. What am I doing wrong in constructing this snippet?

like image 517
Gurnzbot Avatar asked Sep 21 '17 13:09

Gurnzbot


People also ask

Why are snippets not working in VS code?

This fixed the problem for me: remove and then re-add all code snippet folders with the code snippet manager. Tools->Import and Export settings->Reset all settings. Chose reset and over write the existing settings options! Bingo.

How do I enable snippet code in Visual Studio?

For example, in Visual Basic there's a code snippet that inserts a property. To insert the snippet, choose Snippet > Insert Snippet from the right-click or context menu in a Visual Basic code file. Then, choose Code Patterns > Properties, Procedures, Events > Define a Property.

How do I edit a snippet code?

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 do you use a snippet?

You can also insert a snippet when logging an activity or leaving a comment on a record using the HubSpot mobile app for Android. There are two ways to add a snippet: Type the # symbol into the text editor. Start typing the snippet shortcut, then select the snippet from the dropdown menu.


Video Answer


1 Answers

I just found this question when looking for an answer, I used snippet generator so assumed the format for each would be the same but without thinking I pasted in code that had tabs in it.

Removing the tabs and used spaces instead for the formatting fixed it for me.

Hope this helps. :)

like image 147
Mr Duck Avatar answered Oct 10 '22 00:10

Mr Duck