0

I've had this useful snippet in Sublime Text 3 for a while, and I am trying to replicate it in VS Code but with no success.

<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>

I've basically created the same snippet in VS Code but it complains that \s is an invalid escape character.

Picture showing snippet error in VS Code

Where am I going wrong? Is it missing support for finding space characters?

Would like to get this snippet working again as it's a useful time saver.

jsonUK
  • 345
  • 3
  • 9

1 Answers1

0

Just double-escape it:

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

and it'll work fine. See transform examples and escaping:

The examples are shown within double quotes, as they would appear inside a snippet body, to illustrate the need to double escape certain characters.

Mark
  • 143,421
  • 24
  • 428
  • 436
  • Thanks - but afraid double escaping has no effect. – jsonUK Mar 20 '19 at 10:38
  • I see I had made a typo previously - I just fixed it above and I had previously tested it. It works. – Mark Mar 20 '19 at 14:39
  • Ah right - you **must** press "tab" again after typing for the transform to take affect. On Sublime, you see it transform as you type. Confirm that double escaping (your example above) works :) – jsonUK Mar 20 '19 at 22:26