问题
I've made own user snippet code for javascript
"inner backquote concat variable" : {
"prefix": "$",
"body": "\\${$1}",
"description": "concat variable with backquote sting"
}
I want that snippet to work inside backquote string or single quote string when I press '$' like this
but it does not work when inside a string.
How do make the snippet work inside a string?
回答1:
Add the following snippet in settings.json
"editor.quickSuggestions": {
"strings": true
},
It makes all snippets/emmets working on strings.
回答2:
Together with @Ridwan's suggestion your example still wouldn't work because you have no space between $
and the backtick
- so vscode does not see the $
as your prefix, it is just part of a larger string and so doesn't look like a unique trigger it is expecting.
You can see this with any snippet in or out of a string (using your snippet):
So the snippet prefix must "stand alone" so to speak so it can be recognized as a separate trigger. And that includes not being next to a "
or backtick
. They must have spaces around them.
来源:https://stackoverflow.com/questions/58008872/how-to-make-user-snippets-work-inside-strings-vscode