VS Code 用户代码片段模板
可以快捷创建默认代码片段,提高开发效率
- 在菜单中选择用户代码片段
- 创建配置文件
可以创建全局配置或者当前文件夹配置,或修改已有的配置
- 模板参考及效果
{
"Print to conaole": {
"prefix": "cpp",
"body": [
"#include <iostream>",
"#include <windows.h>",
"",
"using namespace std;",
"",
"int main(){",
" ",
" ",
" system(\"pause\");",
" return 0;",
"}",
""
],
"description": "Max"
},
"C C++ Header": {
"scope": "c, cpp",
"prefix": "header",
"description": "Add #ifndef, #define and #endif",
"body": [
"#ifndef _${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H_",
"#define _${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H_",
"",
"#ifdef __cplusplus",
"extern \"C\" {",
"#endif",
"",
"$10",
"#ifdef __cplusplus",
"}",
"#endif",
"",
"#endif // _${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H_"
]
},
"C C++ Description": {
"scope": "c, cpp",
"prefix": "description",
"description": "Add function description",
"body": [
"/**",
" * @brief ${0}",
" * @param ${1}",
" * @param ${2}",
" * @return ${3}",
"**/"
]
}
}
输入 prefix 弹出快捷菜单
cpp效果:
#include <iostream>
#include <windows.h>
using namespace std;
int main(){
system("pause");
return 0;
}
header 效果
#ifndef _CLASS_H_
#define _CLASS_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif // _CLASS_H_
description 效果
/**
* @brief
* @param
* @param
* @return
**/