[RESOLVED] Special characters in snippets?


#1

I’m trying to get a for snippet working but it seems to break once I get to ${3:++} (as in, the snippet just quits and pressing tab will insert a literal tab after count).

for(int ${1:i} = 0; $1 < ${2:count}; $1${3:++})
{
	${4:/* code */}
}

It also seems to break if there’s a <. A very similar snippet is available on the language-c repo which also breaks. language-javascript does not experience this issue because it doesn’t allow ++ to be changed.

Is there any way to properly escape special characters in snippets?


#2

I was able to get this working by double escaping the plus signs:

for(int ${1:i} = 0; $1 < ${2:count}; $1${3:\\+\\+})
{
     ${4:/* code */}
}

I was having a similar issue with inserting regexp characters and got the answer from issue 127 in the repo. Hope this helps!


#3

This was actually fixed a few versions back and the original snippet now works ('twas actually a problem with using $1 more than once). Forgot to reply here though…