{ // Place your snippets for c 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: "C header file": { "prefix": "#ifndef", "body": [ "#ifndef __$1_h__", "#define __$1_h__", "", "#ifdef __$1_h__GLOBAL", "\t#define __$1_h__EXTERN ", "#else", "\t#define __$1_h__EXTERN extern", "#endif", "", "$2", "#endif // __$1_h__", "", ], "description": "C header file define" } }
輸入#ifndef後按TABjavascript
再輸入 AUTO_GEN_SNIPPET , 再按TAB ,html
輸入 VOID hello(void) 就生成以下了:java
#ifndef __AUTO_GEN_SNIPPET_h__ #define __AUTO_GEN_SNIPPET_h__ #ifdef __AUTO_GEN_SNIPPET_h__GLOBAL #define __AUTO_GEN_SNIPPET_h__EXTERN #else #define __AUTO_GEN_SNIPPET_h__EXTERN extern #endif VOID HELLO(void); #endif // __AUTO_GEN_SNIPPET_h__
注意若是是頭文件在VSCode中(右下角)要選擇語言語言爲C,不能爲C++或其它,不然沒有自動完成提示功能。json
C.JSON修改保存後當即生效,不用從新啓動VSC.spa
自動提取.h頭文件名,並把文件名中的-或.改成_code
{ "C head common": { "prefix": "#ifndef", "body": [ "/***********************************************************************", " * @file $TM_FILENAME", " ${1:${TM_FILENAME_BASE/(.*)/${1:/upcase}/i}}", " * @brief $2 header file", " * @history", " * Date Version Author description", " * ========== ======= ========= =======================================", " * $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE V1.0 ${3|Wukong.SUN,Bajie.ZHU,Wuji.SA,Sanzhang.TANG,Baoyu.JIA|} Create", " *", " * @Copyright (C) $CURRENT_YEAR .cdWFVCEL. all right reserved", "***********************************************************************/", "#ifndef __${1/[.-]/_/g}_h__", "#define __${1/[.-]/_/g}_h__", "", "#ifdef __${1/[.-]/_/g}_h__GLOBAL", "\t#define __${1/[.-]/_/g}_h__EXTERN ", "#else", "\t#define __${1/[.-]/_/g}_h__EXTERN extern", "#endif", "", "$4", "#endif // __${1/[.-]/_/g}_h__", "", ], "description": "C header file common define" }, }
/*********************************************************************** * @file auto-gen.header.h AUTO-GEN.HEADER * @brief header file * @history * Date Version Author description * ========== ======= ========= ======================================= * 2018-08-05 V1.0 Wukong.SUN Create * * @Copyright (C) 2018 .cdWFVCEL. all right reserved ***********************************************************************/ #ifndef __AUTO_GEN_HEADER_h__ #define __AUTO_GEN_HEADER_h__ #ifdef __AUTO_GEN_HEADER_h__GLOBAL #define __AUTO_GEN_HEADER_h__EXTERN #else #define __AUTO_GEN_HEADER_h__EXTERN extern #endif #endif // __AUTO_GEN_HEADER_h__
https://www.cnblogs.com/a14907/p/6180244.html : [VS Code]跟我一塊兒在Visual Studio Code 添加自定義snippet(代碼段),附詳細配置htm