【问题标题】:Can a VSCode snippet make three substitutions?VSCode 片段可以进行三个替换吗?
【发布时间】:2019-10-01 21:50:44
【问题描述】:

我编写了一个 VSCode sn-p,它对剪贴板内容进行了两次替换。 例如,这个 sn-p 将“a”字符变为“x”,将“e”字符变为“y”

    "t2": {
        "prefix": "t2",
        "body": [
            "${CLIPBOARD/(a)|(e)/${1:?x:y}/g}"
        ],
        "description": "Makes two substitutions to the clipboard"
    },

使用这个 sn-p,如果我剪切文本“这个 sn-p 更改剪贴板”并执行 sn-p,粘贴的文本是“This snippyt chxngys thy clipboxrd”。 我的问题是:是否可以创建一个应用三个替换的 sn-p?例如,将“a”转换为“x”,将“e”转换为“y”,将“i”转换为“z”,得到上例中的“Thzs snzppyt chxngys thy clzpboxrd”。

【问题讨论】:

    标签: visual-studio-code vscode-snippets


    【解决方案1】:

    是的,您可以随意更改。我做了这个 sn-p 以获得另一个答案:

    "color conditional": {
        "prefix": "_hex",
        "body": [
    
          "let color = '${1};",      
          "let hex = '${1/(white)|(black)|(red)/${1:+#fff}${2:+#000}${3:+#f00}/}';" //works      
        ],
        "description": "conditional color"
      },
    

    vscode if/else conditions in user defined snippet

    举一个例子,但在你的情况下尝试:

    "${CLIPBOARD/(a)|(e)|(i)/${1:+x}${2:+y}${3:+z}/g}"

    您可以使用任意数量的if,而不是使用 if/else 条件。

    【讨论】:

    • 非常感谢您的回答。我尝试使用连续的ifs,但没有成功。有了你的例子,现在我明白了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    • 2021-11-30
    • 2020-09-22
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    相关资源
    最近更新 更多