I am trying to create a snippet in VSCode that will generate a template when I type inc
.
The template should be either:
#include "header-file"
, or #include <header-file>
based on the selected brackets.
Additionally, the cursor should be placed inside the brackets.
For example, if I select angle brackets, the generated template should be #include <cursor>
.
This is what I have tried so far:
{
"Include Header": {
"scope": "c,cpp",
"prefix": "inc",
"body": "#include ${1|"$0",<$0>|}",
}
}
However, the result is not what I expected. VSCode is treating $0 as a string literal, and the output is either #include <$0>
or #include "$0"
2
Answers
Try this instead:
try this snippet
If you have typed the header file (
$2
) and press TAB you are at the end of the line.