VScode User Snippets Template
设置方法
File -> Preferences -> User Snippets -> cpp.json
Template
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "cpp",
"body": [
"#include <iostream>",
"#include <cstdio>",
"#include <cstring>",
"#include <string>",
"#include <algorithm>",
"#include <vector>",
"#include <map>",
"#include <set>",
"#include <queue>",
"#include <stack>",
"#include <cstdlib>",
"#include <cmath>",
"#define LL long long",
"#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);",
"#define MP pair<int,int>",
"",
"/*** ",
" Author : @JokerNoCry",
" Time : $CURRENT_YEAR:$CURRENT_MONTH:$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
" ***/",
"using namespace std;",
"const int maxn=1e5+10;",
"const int mod=1e9+7;",
"",
"",
"",
"int main()",
"{",
" IO;",
" $0",
" return 0;",
"}",
],
"description": "cpp template"
}
}
说明
prefix 中的代码是用来调用的。
例如: 代码 “prefix” : “cpp” 时:
新建 -> test.cpp -> 输入 -> cpp -> 回车 ; 然后就直接出现了模板中的代码
description 中的内容是对该模板的解释
例如 : 代码 “description” : “cpp template”
新建 -> test.cpp -> 输入 -> cpp ; 按回车之前 选项框选中cpp 后面有备注 内容就是 " cpp template"
body的内容就是模板的主题内容:
每行都需要一个引号,空行也需要引号,引号后面需要逗号。
VScode中的参数:
$0 //创建模板后输入指针的位置。(你输入第一个字符的位置)
$CURRENT_YEAR //时间中的年
$CURRENT_MONTH //时间中的月
$CURRENT_DATE //时间中的日
$CURRENT_HOUR //时间中的小时
$CURRENT_MINUTE //时间中的分钟
$CURRENT_SECOND //时间中的秒数