首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

VScode添加代码模板

  • 23-11-14 09:01
  • 3305
  • 11044
blog.csdn.net

VScode添加代码模板

文章目录

  • VScode添加代码模板
    • 1 简述
    • 2 设置模板
    • 3 Global Snippets file示例

1 简述

问:为什么要设置代码模板?
答:编程语言是有个性的,不同语言的演讲风格是不一样的。
旁白:我不懂?!

问:为什么要设置代码模板?
答:同种语言的演讲内容是不一样的,但是演讲稿的框架可以是一样的。
旁白:我懂了?!

问:为什么要设置代码模板?
答:好吧,我承认,每次复制粘贴的操作也是相当费键盘的,我需要快捷的方式在不同格式的语言文件中填充不同的框架内容。
旁白:VSCode说它可以。

2 设置模板

点击VSCode界面左下角的齿轮图标,在弹出界面中点击“User Snippets”选项,如下图所示:

在这里插入图片描述

此时会在界面顶部弹出选项,供用户选择需要为哪种语言添加模板,如下图所示:

在这里插入图片描述

选择你要添加的模板语言,然后就可以在模板文件中添加自定义的文件模板了,需要注意的是模板文件的格式为“json”格式。

也可以创建一个“Global Snippets file”模板文件,在这个文件中可以为各种语言添加文件模板。

3 Global Snippets file示例

下面的代码展示的是一个“Global Snippets file”示例:

{
	// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. 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:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
    "C function file template": {
        "prefix": "cfile",
        "body": [
            "/**",
            " * CONFIDENTIAL and PROPRIETARY",
            " *   Copyright (c) XXX Automotive System Co.,LTD. All rights reserved.",
            " *",
            " * FILE INFORMATION",
            " *   FILE NAME: ${TM_FILENAME}",
            " *   AUTHOR(S): XXX",
            " *",
            " * BRIEF INFORMATION",
            " *   function file.",
            " */",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Header Files",
            " *---------------------------------------------------------------------------*/",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Local Defines",
            " *---------------------------------------------------------------------------*/",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Local Variables",
            " *---------------------------------------------------------------------------*/",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Global Variables",
            " *---------------------------------------------------------------------------*/",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Local Functions",
            " *---------------------------------------------------------------------------*/",
            "/**",
            " * Abstract:",
            " *   Function.",
            " *",
            " * Parameter:",
            " *   argc: Parameter.",
            " *",
            " * Return:",
            " *   None.",
            " */",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Global Functions",
            " *---------------------------------------------------------------------------*/",
            "/**",
            " * Abstract:",
            " *   Function.",
            " *",
            " * Parameter:",
            " *   argc: Parameter.",
            " *",
            " * Return:",
            " *   None.",
            " */",
            "",
            ""
        ],
        "description": "C function file template."
    },
    "C header file template": {
        "prefix": "hfile",
        "body": [
            "/**",
            " * CONFIDENTIAL and PROPRIETARY",
            " *   Copyright (c) XXX Automotive System Co.,LTD. All rights reserved.",
            " *",
            " * FILE INFORMATION",
            " *   FILE NAME: ${TM_FILENAME}",
            " *   AUTHOR(S): XXX",
            " *",
            " * BRIEF INFORMATION",
            " *   header file.",
            " */",
            "",
            "#ifndef _${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H_INCLUDED_",
            "#define _${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H_INCLUDED_",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Header Files",
            " *---------------------------------------------------------------------------*/",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Defines",
            " *---------------------------------------------------------------------------*/",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Types",
            " *---------------------------------------------------------------------------*/",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Exported Functions",
            " *---------------------------------------------------------------------------*/",
            "",
            "",
            "#endif  /* End #ifndef _${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H_INCLUDED_ */",
            ""
        ],
        "description": "C header file template."
    },
    "GTest function file template": {
        "prefix": "gtest",
        "body": [
            "/**",
            " * CONFIDENTIAL and PROPRIETARY",
            " *   Copyright (c) XXX Automotive System Co.,LTD. All rights reserved.",
            " *",
            " * FILE INFORMATION",
            " *   FILE NAME: ${TM_FILENAME}",
            " *   AUTHOR(S): XXX",
            " *",
            " * BRIEF INFORMATION",
            " *   unit test file.",
            " */",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Header Files",
            " *---------------------------------------------------------------------------*/",
            "#include "
            "#include "
            "#include "
            "/* Include C-format header file. */"
            "extern "C" {"
            "    #include """
            "}",
            "",
            "using namespace std;",
            "/*---------------------------------------------------------------------------",
            " *         Defines",
            " *---------------------------------------------------------------------------*/",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Variables",
            " *---------------------------------------------------------------------------*/",
            "",
            "/*---------------------------------------------------------------------------",
            " *         Functions",
            " *---------------------------------------------------------------------------*/",
            "/**",
            " * Abstract:",
            " *   Function.",
            " *",
            " * Parameter:",
            " *   argc: Parameter.",
            " *",
            " * Return:",
            " *   None.",
            " */",
            ""
        ],
        "description": "GTest function file template."
    },
    "Python file template": {
        "prefix": "pyfile",
        "body": [
            "# CONFIDENTIAL and PROPRIETARY",
            "#   Copyright (c) XXX Automotive System Co.,LTD. All rights reserved.",
            "#",
            "# FILE INFORMATION",
            "#   FILE NAME: ${TM_FILENAME}",
            "#   AUTHOR(S): XXX",
            "#",
            "# BRIEF INFORMATION",
            "#   file information.",
            "",
            "# Import modules or packages.",
            "",
            ""
        ],
        "description": "Python file template."
    },
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193

在上述代码中供定义了四种文件模板:

cfile: C语言源码文件模板
hfile: C语言头文件模板
gtest: GTest源码文件模板
pyfile: Python文件模板
  • 1
  • 2
  • 3
  • 4

当为VSCode添加了上述“Global Snippets file”内容后,在空白文件中就可以通过输入提示词(cfile,hfile,gtest,pyfile)然后点击回车按键填充文件了。

《AUTOSAR谱系分解(ETAS工具链)》之总目录

注:本文转载自blog.csdn.net的PlutoZuo的文章"https://blog.csdn.net/PlutoZuo/article/details/133140923"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2024 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top