Search code examples
jsonvscode-snippets

Adding Dollar Sign($) in a VScode Code snippet


I was writing my custom code snippets for verilog files in VScode; VSCode uses JSON files for it.
I observed that $ before finish and dumpvars statements doesn't get printed when I use the snippet since it is a built-in keyword for including variables in strings in json file format, I have tried adding \ before $ but that didn't work.
Is there any way I can insert $ in my snippets?

This is the relevant code block I am using:

"dump statements": {
        "prefix": "dump",
        "body": [
            "initial begin", 
            "   dumpfile(\"${1:filename}\");",
            "   \$dumpvars();",
            "end"
        ],
        "description": "Prints the dump file and variables statements."
    },

Solution

  • Use a double backslash to escape it, like this \\$

    "dump statements": {
        "prefix": "dump",
        "body": [
            "initial begin", 
            "   dumpfile(\"${1:filename}\");",
            "   \\$dumpvars();",
            "end"
        ],
        "description": "Prints the dump file and variables statements."
    },