VS代码-代码段将文本转换为带空格的测试方法

时间:2019-03-19 19:37:56

标签: visual-studio-code code-snippets

一段时间以来,我在 Sublime Text 3 中有一个有用的代码段,但我试图用 VS Code 复制它,但没有成功。

<snippet>
    <content><![CDATA[
/** @test */
public function ${1/\s/_/g}()
{
    ${0:// ${1:type name of method with spaces}}
}
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>phpunit</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.php</scope> -->
</snippet>

我基本上已经在 VS Code 中创建了相同的代码段,但是它抱怨\s是无效的转义符。

Picture showing snippet error in VS Code

我要去哪里错了?是否缺少寻找空格字符的支持?

由于它可以节省时间,因此希望此代码段再次运行。

1 个答案:

答案 0 :(得分:0)

只需两次转义即可:

public function ${1/\\s/_/g}()

,它将正常工作。参见transform examples and escaping

  

示例在双引号中显示,因为它们会出现在摘录主体中,以说明需要对某些字符进行两次转义。

相关问题