5

I would like to do create a snippet in which the ${1:} command is present in multiple locations, allowing me to editing in multiple locations at once.

In particular I would like this snippet to work as "expected".

cout << "${1:} = " << ${1:} << "\n";

usage:

1) type cout

2) expand the snippet

3) type the name of the variable you want to print

  • In what way does this snippet not work as expected? – Singulaere Entitaet Aug 29 '17 at 20:50
  • It works like if the first ${1:} were a ${2:} – Nisba Aug 29 '17 at 22:14
5

Try this snippet:

# -*- mode: snippet -*-
# name: cout variable
# key: cvar
# --
cout << "${1:var} = " << $1 << endl;$0

I believe the main problem is that yasnippet doesn't recognize the second ${1:} as a mirroring placeholder, and instead attempts to fix the snippet by changing ${1:} to ${2:}.

It may be an idea to open an issue on Github to at least issue an warning during snippet expansion for these kinds of errors, possibly when yas-verbosity is set to a sufficiently high value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.