7

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

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

1 Answer 1

8

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 and acknowledge you have read our privacy policy.

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