文章目录
-
- 一、安装插件
- 二、在安装目录下添加c.json和cpp.json文件
-
- [①在 C:/Users/yourname/AppData/Roaming/Code/User/snippets/ 目录下创建 c.json 并填入如下内容:](#①在 C:/Users/yourname/AppData/Roaming/Code/User/snippets/ 目录下创建 c.json 并填入如下内容:)
- [②在 C:/Users/yourname/AppData/Roaming/Code/User/snippets/ 目录下创建 cpp.json 并填入如下内容:](#②在 C:/Users/yourname/AppData/Roaming/Code/User/snippets/ 目录下创建 cpp.json 并填入如下内容:)
- 三、使用
这个 snippets 常用于 LVGL 。
一、安装插件
二、在安装目录下添加c.json和cpp.json文件
①在 C:/Users/yourname/AppData/Roaming/Code/User/snippets/ 目录下创建 c.json 并填入如下内容:
C
{
"C Source File Template": {
"prefix": "csource",
"body": [
"/**",
" * @file ${TM_FILENAME_BASE}.c",
" *",
" */",
"",
"/*********************",
" * INCLUDES",
" *********************/",
"#include \"${TM_FILENAME_BASE}.h\"",
"",
"/**********************",
" * DEFINES",
" **********************/",
"",
"/**********************",
" * TYPEDEFS",
" **********************/",
"",
"/**********************",
" * STATIC PROTOTYPES",
" **********************/",
"",
"/**********************",
" * STATIC VARIABLES",
" **********************/",
"",
"/**********************",
" * MACROS",
" **********************/",
"",
"/**********************",
" * GLOBAL FUNCTIONS",
" **********************/",
"",
"/**********************",
" * STATIC FUNCTIONS",
" **********************/"
],
"description": "Template for a C source file",
},
}
②在 C:/Users/yourname/AppData/Roaming/Code/User/snippets/ 目录下创建 cpp.json 并填入如下内容:
C
{
"C/CPP Header File Template": {
"prefix": "cheader",
"body": [
"/**",
" * @file ${TM_FILENAME_BASE}.h",
" *",
" */",
"#ifndef ${TM_FILENAME_BASE/(.*)/${1:/upcase}_H/}",
"#define ${TM_FILENAME_BASE/(.*)/${1:/upcase}_H/}",
"",
"#ifdef __cplusplus",
"extern \"C\" {",
"#endif",
"",
"/*********************",
" * INCLUDES",
" *********************/",
"",
"/**********************",
" * DEFINES",
" **********************/",
"",
"/**********************",
" * TYPEDEFS",
" **********************/",
"",
"/**********************",
" * GLOBAL PROTOTYPES",
" **********************/",
"",
"/**********************",
" * MACROS",
" **********************/",
"",
"#ifdef __cplusplus",
"} /* extern \"C\" */",
"#endif",
"",
"#endif /* ${TM_FILENAME_BASE/(.*)/${1:/upcase}_H/} */"
],
"description": "Template for a C/CPP header file",
},
}
三、使用
在创建xx.c 和xx.h 文件后,输入 csource 或 cheader 的前几个字符,就会出现 csource 或 cheader 的提示,上下键选中它们并回车,就能自动插入
类似的,也可以为其他的代码框架添加模板。
参考:https://blog.csdn.net/angry_rooster/article/details/118560317