在VSCODE片段中使用$

发布于 2025-01-21 11:33:57 字数 290 浏览 4 评论 0原文

我正在尝试创建一个包含$标志的片段,但是在输出中,VSCODE跳过$符号并选择文本。

"Color 1": {
        "prefix": "c1",
        "body": [
            "color: $c1;"
        ]
    }

Output

color: c1;

I have also tried using \ and ''.任何人都可以指导。

I am trying to create a snippet which includes a $ sign, but in output vscode is skipping the $ sign and making the text selected.

"Color 1": {
        "prefix": "c1",
        "body": [
            "color: $c1;"
        ]
    }

Output

color: c1;

I have also tried using \ and ''. Can anyone please guide.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

权谋诡计 2025-01-28 11:33:57

您可以逃脱$在带有双重拒绝<代码> \\ 的摘要中签名:

"Color 1": {
    "prefix": "c1",
    "body": [
            "color: \\$c1;"
    ]
}

You can escape $ sign in snippets with double backslash \\ like this:

"Color 1": {
    "prefix": "c1",
    "body": [
            "color: \\$c1;"
    ]
}
你好,陌生人 2025-01-28 11:33:57

来自 sminippet doc 页面


如何在粘贴脚本中放置一个变量?

要在粘贴脚本中具有变量,您需要逃脱$变量名称的'$',以使其不会被smippet扩展阶段解析。

"VariableSnippet":{
    "prefix": "_Var",
    "body": "\\$MyVar = 2",
    "description": "A basic snippet that places a variable into script with the $ prefix"
  }

这导致粘贴片段为:

$MyVar = 2

From the Snippet Doc page


How do I have a snippet place a variable in the pasted script?

To have a variable in the pasted script, you need to escape the '$' of the $variable name so that it isn't parsed by the snippet expansion phase.

"VariableSnippet":{
    "prefix": "_Var",
    "body": "\\$MyVar = 2",
    "description": "A basic snippet that places a variable into script with the $ prefix"
  }

This results in the pasted snippet as:

$MyVar = 2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文