user4035
user4035

Reputation: 23749

How to quote $1 in yasnippet

Suppose, I have the following yasnippet:

my $dir = __FILE__;
$dir =~ s/(.*)\/.*/$1/;

$1 here is the regular expression first match. Not yasnippet special symbol. How can I quote it, so it is inserted into the code as is?

Upvotes: 4

Views: 953

Answers (1)

Tyler
Tyler

Reputation: 10032

From the documentation:

Arbitrary text can be included as the content of a template. They are usually interpreted as plain text, except $ and `. You need to use \ to escape them: \$ and \`. The \ itself may also needed to be escaped as \\ sometimes.

So use \$ to get a literal '$' in your snippet.

Upvotes: 5

Related Questions