自学内容网 自学内容网

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


这个 snippets 常用于 LVGL 。

一、安装插件

在这里插入图片描述

二、在安装目录下添加c.json和cpp.json文件

①在 C:/Users/yourname/AppData/Roaming/Code/User/snippets/ 目录下创建 c.json 并填入如下内容:

{
    "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/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


原文地址:https://blog.csdn.net/weixin_62897522/article/details/142615570

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!