添加vscode插件C/C++ snippets,快速生成LVGL .c/.h文件模版

文章目录

    • 一、安装插件
    • 二、在安装目录下添加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

相关推荐
witton1 天前
MacOS中在目录或者文件右键菜单中添加“使用VSCode打开”
vscode·macos·文件·目录·服务·automator·右键菜单
wabil1 天前
[AI-Talk] codx制作xmind文件技巧
ide·ai编程·myeclipse·xmind
大衛說2 天前
02 · 环境搭建:uv 包管理与现代 IDE
ide·uv
cndes2 天前
安装Miniconda+Jupyter notebook
ide·python·jupyter
码上暴富2 天前
Cursor / VS Code 自定义文件颜色
前端·vscode
洛兮银儿2 天前
pycharm选中同一个词的标记颜色的修改
ide·python·pycharm
2601_962381582 天前
VSCode如何配置LlamaIndex RAG(检索增强生成)应用开发环境
vscode·开发环境·rag·llamaindex·检索增强生成
北漂燕郊杨哥2 天前
VS Code 安装微信小程序 MCP 介绍
vscode·微信小程序·小程序·mcp
Sherotree3 天前
Google Antigravity——Agent 被提到主界面
前端·ide·后端·edge浏览器
YZJenny3 天前
在服务器上安装使用code-server(Web 版 VS Code)
ide·vscode·编辑器