Vscode: How to use multi-line in Custom Snippets body part?

Created on 8 Nov 2016  路  11Comments  路  Source: microsoft/vscode

  • VSCode Version: 1.7.1
  • OS Version: window 10

Steps to Reproduce:

When I add some custom snippets into my *.json file, it's very inconvenient to use "" in each line, is there any ways like use "multi-line codes" there?

needs more info snippets

Most helpful comment

@jrieken Why is this issue even closed. Snippets seriously need a refactor.

All 11 comments

@kanlidy What do you mean by 'multi-line codes'? Can you add an example of a snippet you have?

Hacky-solution: http://codepen.io/mrmlnc/pen/GqrqPg
Demo:
2016-11-08_17-36-19

You can also have a single string that uses \n in it.

Closing. Please return with more information on this

While the codepen hacky fix is helpful, it seems like a step back from sublime snippets, doesn't it? In sublime, the code didn't really need to be messed with too much to get it into the snippet. Lots of examples at https://webdevstudios.com/2016/08/16/snippets-saved-life-how-sublime-text-3-snippets-changed-everything/

@jrieken what sort of information did you have in mind?

@kanlidy What do you mean by 'multi-line codes'? Can you add an example of a snippet you have?

@jcrben

Take the example on the documentation page Creating your own Snippets which looks like this in the jqAjax in this jQuery snippet collection:

"jqAjax": {
    "prefix": "jqAjax",
    "body": [
        "$.ajax({",
        "\ttype: \"${method}\",",
        "\turl: \"${url}\",",
        "\tdata: \"${data}\",",
        "\tdataType: \"${dataType}\",",
        "\tsuccess: function (response) {",
        "\t\t$0",
        "\t}",
        "});"
    ],
    "description": "Perform an asynchronous HTTP (Ajax) request."
},

Meanwhile, this is how it looks in a Sublime snippet:

<snippet>
  <content><![CDATA[
\$.ajax({
    type: "$1",
    url: "$2",
    data: "data",
    dataType: "dataType",
    success: function (response) {

    }
});


  <!-- in theory add scripts to run javascript at the end -->
</body>
</html>
]]></content>
  <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
  <tabTrigger>jqAjax</tabTrigger>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <!-- <scope>source.python</scope> -->
</snippet>

In this case, you only have to escape the $ in Sublime snippets, which makes it easier to tweak your code into snippets and easier to read the snippets. That blog post I linked above has some other examples.

@jrieken Why is this issue even closed. Snippets seriously need a refactor.

I agree. It's obviously too painful to write multi-line snippet this way.

Atom uses something like this

body: {
  """
  Your multiline stuff here
  """
}

IMO I would not invent another flavor of JSON here, but use an existing and established syntax such as JSON5.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vsccarl picture vsccarl  路  3Comments

mrkiley picture mrkiley  路  3Comments

curtw picture curtw  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments

DovydasNavickas picture DovydasNavickas  路  3Comments