Search code examples
emacsyasnippet

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?


Solution

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