最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Visual Studio Code JS Snippet escape curly bracket - Stack Overflow

programmeradmin1浏览0评论

I want to create a Snippet for Javascript in Visual Studio Code, with a placeholder that includes curly brackets, but Visual Studio doesn't seem to track bracket nesting.

My Snippet looks something like this:

"MySnippet": {
    "prefix": "snippet",
    "body": [
        "OuterFunction(() => {",
        "   //code",
        "   ${1:InnerFunction(() =>{",
        "       $2",
        "   },timeout);}",
        "});"
    ],
    "description": "create a thing"
}

and I expect this output:

OuterFunction(() => {
       //code
       InnerFunction(() => {

       },timeout);
    });

with the setTimeout Syntax as a placeholder.

Instead I get this:

OuterFunction(() => {
   //code
   InnerFunction(() => {

   ,timeout)};
});

which obviously doesn't work.

I have tried escaping the curly bracket like this \{and this {{ but it doesn't seem to work. Is there a simple way to do this or do I simply have to go with two seperate snippets for the outer and the inner function?

I want to create a Snippet for Javascript in Visual Studio Code, with a placeholder that includes curly brackets, but Visual Studio doesn't seem to track bracket nesting.

My Snippet looks something like this:

"MySnippet": {
    "prefix": "snippet",
    "body": [
        "OuterFunction(() => {",
        "   //code",
        "   ${1:InnerFunction(() =>{",
        "       $2",
        "   },timeout);}",
        "});"
    ],
    "description": "create a thing"
}

and I expect this output:

OuterFunction(() => {
       //code
       InnerFunction(() => {

       },timeout);
    });

with the setTimeout Syntax as a placeholder.

Instead I get this:

OuterFunction(() => {
   //code
   InnerFunction(() => {

   ,timeout)};
});

which obviously doesn't work.

I have tried escaping the curly bracket like this \{and this {{ but it doesn't seem to work. Is there a simple way to do this or do I simply have to go with two seperate snippets for the outer and the inner function?

Share Improve this question asked Mar 23, 2017 at 8:47 Fritz LloydFritz Lloyd 1201 silver badge11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Could this work?:

"MySnippet": {
    "prefix": "snippet",
    "body": [
        "OuterFunction(() => {",
        "   //code",
        "   ${1:InnerFunction(() => { $2 \\}, timeout);}",
        "});"
    ],
    "description": "create a thing"
}

Produces:

OuterFunction(() => {
   //code
   InnerFunction(() => {  }, timeout);
});

Where InnerFunction(() => { }, timeout); is selected, then inside the brackets after tabbing.

发布评论

评论列表(0)

  1. 暂无评论