How to add dollar signs in Code Snippets of Visual Studio Code? - visual-studio-code

$ (dollar signs) are removed from Snippets in Visual Studio Code
How to disable placeholders?
My vue-html.json file snippet
"body": ["<ActivityIndicator v-if=\"$apollo.loading\" />"]
does not add $ and produces
<ActivityIndicator v-if="apollo.loading" />
but instead it should produce
<ActivityIndicator v-if="$apollo.loading" />

"description": {
"prefix": "trigger",
"body": [
"<ActivityIndicator v-if=\"\\$apollo.loading\" />"
],
"description": "description"
}
In JSON the backslash itself needs to be encoded with \, which is why you need \\

"body": ["<ActivityIndicator v-if=\"\\$apollo.loading\" />"]
You need to escape the $ symbol individually too

Related

How to select multiple values from VS Code choice-type snippet?

I use VS Code and Markdown to journal and track things. The following markdown snippet is an example of using choice-type variables in a snippet.
How would I select multiple TOOLS from the choice below?
As soon as I choose 1 option, I'm taken to $0.
"Context": {
"prefix": "scontext",
"body": [
"- **TYPE:** ${1|COMMS,SUPPORT,RESEARCH,MEETING,DEVELOPMENT,TESTING,VALIDATION,PROJECT MGMT,CONSULTING,DOCUMENTATION,ADMINISTRATION,TRAINING,BREAK|}",
"- **PROJECT:** ${2|Project1,Project2,Project3|}",
"- **TOOLS:** ${3|Python,Azure Storage,Azure Function,Azure Key Vault,Etc.|}",
"- **START:** ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}-08:00",
"- **END:** ",
"- **DURATION:** ",
"- **NOTES:**",
" - $0",
"---"
],
"description": "New context"
},

Capture text between two different char. Between the first{ and the last }

Capture text between two different char using PowerShell. Between the first{ and the last } . Basically there is text with Json in it and I want to capture the json from it. I have looked for examples but so far no luck.
PROJECT Description: Azure Test Project Description
PROJECT ADMINISTRATORS: jjohnson
CONTRIBUTORS: jdoe
BOARD PROCESS: Agile
SPECIAL INSTRUCTIONS:
{
"organization": "https://dev.azure.com/cloudops",
"projectName": "Test Project",
"projectDescription": "Azure Test Project Description",
"projectProcessType": "Agile",
"specialInstructions": "",
"adminMembers": [
{
"userSamAccountName": "jjohnson",
"userEmailAddress": "jjohnson#test.com",
"userPrincipalName": "jjohnson#test.com",
"projectGroupType": "projectAdministrator"
}
],
"contribMembers": [
{
"userSamAccountName": "jdoe",
"userEmailAddress": "jdoe#test.com",
"userPrincipalName": "jdoe#test.com",
"projectGroupType": "projectContributor"
}
]
}
Is this what you were looking for?
[Regex]::Match((Get-Content "sampleinputfile.txt" -Raw),
'^{.+}',
[Text.RegularExpressions.RegexOptions]::Multiline -bor
[Text.RegularExpressions.RegexOptions]::Singleline).Value
Basically this converts the input file to a single (newline-delimited) string (Get-Content -Raw), and then uses the .NET Framework's Match method to do a regular expression match for the lines of text between the { and } characters (inclusive).

How can I disable spellchecking of latex math fragments in markdown in visual studio code?

Is there way to configure any of the spell check plugins in visual studio to ignore math fragments between $$ delimiters in markdown?
$$
Δx = \frac{1}{2} (v_i + v_f) Δt ignore any mi∑takes here
$$
configure to notice this mi∑take
$$
Δx = \frac{1}{2} (v_i + v_f) Δt
$$
Spellright plug-in with these settings:
"spellright.ignoreRegExpsByClass": {
"markdown": [
"/\\\\\\\\\\([^]*?\\\\\\\\\\)/gm" ,
"/\\\\\\\\\\[[^]*?\\\\\\\\\\]/gm" ,
"/\\$\\$[^]*?\\$\\$/gm" ],
]
}
How I got there:
I moved from git pages to git lab pages so I was using this syntax
\( <mathjax> \)
because I'm using jekyll to produced pages from markdown, I had to escape those back slashes
\\( <mathjax> \\)
Then I used spellright plug-ins regex ignore setting.
To ignore anything between the delimiters I had to escape the backslashes in the regex, and because the regex is entered as a string, I had to escape the backslashes in the string so I end up with:
"spellright.ignoreRegExpsByClass": {
"markdown": [
"/\\\\\\\\\\(.*\\\\\\\\\\)/gm" ,
"/\\\\\\\\\\[.*\\\\\\\\\\]/gm" ]
}
but the . wasn't matching new line characters, so I changed this to:
"spellright.ignoreRegExpsByClass": {
"markdown": [
"/\\\\\\\\\\([^]*?\\\\\\\\\\)/gm" ,
"/\\\\\\\\\\[[^]*?\\\\\\\\\\]/gm" ,
]
}
And added in a pattern to match by original $$...$$ problem
"spellright.ignoreRegExpsByClass": {
"markdown": [
"/\\\\\\\\\\([^]*?\\\\\\\\\\)/gm" ,
"/\\\\\\\\\\[[^]*?\\\\\\\\\\]/gm" ,
"/\\$\\$[^]*?\\$\\$/gm" ],
]
}

How to escape $ in Visual Studio Code snippet creation

It seems when using PHP variables like $_SERVER the code snippet ignores the $. For example
{
// Example:
"IP Address Test": {
"scope": "php",
"prefix": "iptest",
"body": [
"// Debugging",
"if($_SERVER[\"REMOTE_ADDR\"]=='${1:ipaddress}'){",
"\t//run only my ip",
"\t$0",
"}"
],
"description": "Test only from IP address"
}
}
outputs :
// Debugging
if(_SERVER["REMOTE_ADDR"]=='xxx.xxx.xxx.xxx'){
//run only my ip
}
You can't use \ you have to use double $ ..
eg.
// Debugging
if($$_SERVER["REMOTE_ADDR"]=='xxx.xxx.xxx.xxx'){
//run only my ip
}

Escape $ in snippet

I'm trying to escape the $ character in my snippets but I cannot seem to get it correct.
If I use \$ as it looks like I should be from the documentation, I get the error:
file: path/to/snippets/php.json'
severity: 'Error'
message: 'Invalid escape character in string'
And no $ appear in my snippet.
If I use $$ found from this answer, I get a $ to show up but it thinks that the text immediately following is a tabstop.
If I use $\ it works but I have to have a character that is part of an escape sequence immediately following. So if I wanted $factory, I would need to do $\ffactory. \f seems to be the best as it does not effect the layout of my snippet.
I'm pretty sure that I am missing what needs to be done here.
My snippet for reference:
"factory" :{
"prefix": "factory",
"body": [
"\$factory->define($1, function (Faker\\Generator \$faker){",
"\treturn [",
"\t\t$2,",
"\t];",
"}"
],
"description": "Creates Model factory"
},
After much trial and error, I found that using \\$ will give me the desired results. So if I wanted $test in my snippet output, with test not being a tabstop, I would need \\$test snippet definition body:
"factory" :{
"prefix": "factory",
"body": [
"\\$factory->define($1, function (Faker\\Generator \\$faker){",
"\treturn [",
"\t\t$2,",
"\t];",
"});"
],
"description": "Creates Model factory"
},