Answer the question
In order to leave comments, you need to log in
Is it possible to insert conditional snippets in VSCode like in Sublime Text?
Good time!
Is it possible in VSCode to insert a snippet from a keybinding only if there is no specific character before the insertion point?
I want typing "{" in CSS/SCSS files to automatically generate the correct structure.
That is, I write:
.block{
I get:
.block {
| <- курсор
}
Answer the question
In order to leave comments, you need to log in
In the course of further research, it was determined that this can only be implemented by writing your own extension and calling not editor.action.insertSnippet, but a method of your extension, which will check the previous character and insert the snippet if everything is OK.
In my opinion, writing such small extensions is bad manners, I solved my problem by adding a new snippet, which, when pressed on "ctrl+#", will insert #{$var}, and "shift+3" (#) remains behind the usual octothorpe.
Keybindings, if anyone needs:
{
"key": "shift+[",
"when": "editorTextFocus && resourceExtname == .scss || resourceExtname == .css",
"command": "editor.action.insertSnippet",
"args": {
"snippet": " {\n\t${0}\n}"
}
},
{
"key": "ctrl+3",
"when": "editorTextFocus && resourceExtname == .scss || resourceExtname == .css",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "#{\\$${1:var}}"
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question