snippet-generator icon indicating copy to clipboard operation
snippet-generator copied to clipboard

Escape (PowerShell, PHP) $Variables in VSCode

Open maelcum opened this issue 6 years ago • 3 comments
trafficstars

Hello.

$Variablenames in VSCode snippets need to be escaped with a double backslash, like: \\$Variablename to look like $Variablename in the inserted code.

It gets tricky when $Variablenames follow a path delimiter, in Windows the backslash... A Windows backslash is escaped with a single backslash, like: \\some\\path Adding the escaped $Variablename directly behind it will not work, ie: \\\\$Variablename. The $Variablename will loose it's '$' and look like: \Variablename What does work is escaping the double escape by double escaping :) as in: \\\\\\$Variablename

tl;dr: it takes six backslashes to escape the combination '\some\path\$Variablename', to look like '\\some\\path\\\\\\$Variablename' This is only necessary if a $Variablename follows a path delimiter. Otherwise a double backslash '\\' would be enough.

phew

This might be related (or cover) Issue #13

maelcum avatar Nov 02 '19 15:11 maelcum

Hi.

Thanks for reporting. This issue applies only to languages that use $ as a variable prefix — like PHP. Am I correct on this one?

I may look into it at some point. Thanks for reporting again and have a nice day 🥑

pawelgrzybek avatar Nov 04 '19 08:11 pawelgrzybek

Yes, correct. I am sorry, this should have been mentioned somewhere. I've just changed the title to reflect that. And a very nice day to you too.

maelcum avatar Nov 04 '19 10:11 maelcum

👋 Ran into this today as well with a Vue.js snippet. Vue uses a lot of $ for properties that bind to the vue instance for example this.$route.query.search to get the query parameters.

Admittedly it took me 2 seconds to go and add the \\ to fix it but just wanted to add another example. Love the site, saves me loads of time 🙏

Watersdr avatar Dec 06 '19 21:12 Watersdr