vscode自动添加linux头文件,VScode中自定义用户代码片段(C user snippet)自动生成C语言头文件排除重复包含...

环境

WINDOWS 2016

VSCode v1.25.1

C语言用户代码片段SNIPPET配置c.json内容

{

// 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后按TAB

再输入 AUTO_GEN_SNIPPET , 再按TAB ,

输入  VOID hello(void)  就生成如下了:

#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++或其它,否则没有自动完成提示功能。

C.JSON修改保存后立即生效,不用重新启动VSC.

自动生成一个更复杂的头

自动提取.h头文件名,并把文件名中的-或.改为_

snippet c.json

{

"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(代码段),附详细配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值