问题
I am writing some JavaScript snippets for VS Code, and when I add the one for an event listener, there are a number of pre-defined prefix allocations relating to other pieces of code. I would like to use "ael" as the prefix prompt for this snippet, but that defaults to an alert command (this is particularly frustrating because the first 3 letters of alert are actually "ale"), anyway, is there a way of over-riding the default behaviour?
In the code below if I change the prefix
to "ttt", and subsequently type "ttt", the snippet works, when I use "ael" it doesn't.
How do I over-ride this?
SNIPPET
"ael": {
"prefix": "ael",
"body": [
"addEventListener(\"\t$1\", function(){",
"\t$2",
"}, false);"
],
"description": "Add an Event Listener",
}
回答1:
It's a part of the latest update: 1.19 release notes
When you accept a suggestion it remembers and jumps to the thing that you previously accepted. Here is the issue about controlling this feature: #41060
Since vscode 1.20 there is an option to disable or modify this behavior:
"editor.suggestSelection"
"first"
- as it was before (no rememering, no preselecting)
"recentlyUsed"
- select the previously used item
"recentlyUsedByPrefix"
- select items based on prefixes you have used
来源:https://stackoverflow.com/questions/48304160/over-ride-default-snippet-prefix-in-vs-code