VSCode学习笔记一:添加代码模板

一目了然

  • 1 简述
  • 2 设置模板
  • 3 Global Snippets file示例

1 简述

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

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

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

2 设置模板

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

Manage -> User Snippets

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

Language 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 <stdio.h>""#include <stdlib.h>""#include <gtest/gtest.h>""/* Include C-format header file. */""extern \"C\" {""    #include \"\"""}","","/*---------------------------------------------------------------------------"," *         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."},
}

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

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

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/72291.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

qt作业day4

//clock_exercise.cpp#include "clock_timer.h" #include "ui_clock_timer.h"//时间事件处理函数 void Clock_Timer::timerEvent(QTimerEvent *event) {if(event->timerId() time_id){sys_tm QDateTime :: currentDateTime(); // int year sy…

【c++】如何有效地利用命名空间?

​ &#x1f331;博客主页&#xff1a;青竹雾色间 &#x1f618;博客制作不易欢迎各位&#x1f44d;点赞⭐收藏➕关注 ​✨人生如寄&#xff0c;多忧何为 ✨ 目录 前言什么是命名空间&#xff1f;命名空间的语法命名空间的使用避免命名冲突命名空间的嵌套总结 前言 当谈到C编…

直播APP源码搭建:核心的服务器系统

在现代科技的推动下&#xff0c;网络衍生出了各种各样的技术&#xff0c;每个技术都被应用到需要的APP上&#xff0c;直播APP源码搭建出来的APP就是其中的一个&#xff0c;然而&#xff0c;这些技术能够成功的在直播APP源码搭建的APP中稳定的为用户们提供功能与服务&#xff0c…

芯科蓝牙BG27开发笔记-新建示例工程

此笔记的必要性 芯科的官方资料很丰富&#xff0c;并且ssv5中能方便索引到所需文档&#xff0c;不过大而全的问题就是找不到合适的切入点&#xff0c;更不会有本地化比较好的中文的系统的教程了。往往看到一个starting guide&#xff0c;会延伸其他starting guide&#xff0c;…

Docker从认识到实践再到底层原理(四-2)|Docker镜像仓库实战案例

前言 那么这里博主先安利一些干货满满的专栏了&#xff01; 首先是博主的高质量博客的汇总&#xff0c;这个专栏里面的博客&#xff0c;都是博主最最用心写的一部分&#xff0c;干货满满&#xff0c;希望对大家有帮助。 高质量博客汇总 然后就是博主最近最花时间的一个专栏…

污水处理厂3D数字孪生三维可视系统降低设备风险隐患

当相对传统与保守的水务行业&#xff0c;与激进与开放的互联网发生碰撞之后&#xff0c;产生了最好的一个名词是&#xff1a;“智慧水务”&#xff0c;谈及智慧水务&#xff0c;自然免不了当下最具热度的技术“元宇宙”&#xff0c;水资源再生是我国追求高质量发展的新策略&…

软件测试/测试开发丨Selenium Web自动化多浏览器处理

点此获取更多相关资料 本文为霍格沃兹测试开发学社学员学习笔记分享 原文链接&#xff1a;https://ceshiren.com/t/topic/27185 一、多浏览器测试介绍 1.1、多浏览器测试背景 用户使用的浏览器(firefox,chrome,IE 等)web 应用应该能在任何浏览器上正常的工作&#xff0c;这样…

springboot整合elasticsearch使用案例

引入依赖 <dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId> </dependency> 添加注入 import org.apache.http.HttpHost; import org.elasticsearch.client.Res…

2594. 修车的最少时间

文章目录 Tag题目来源题目解读解题思路方法一&#xff1a;二分枚举答案 写在最后 Tag 【二分枚举答案】【数组】 题目来源 2594. 修车的最少时间 题目解读 给你一个表示机械工能力的数组 ranks&#xff0c;ranks[i] 表示第 i 位机械工可以在 r a n k s [ i ] ∗ n 2 ranks[…

[docker]笔记-存储管理

1、docker数据存储分为非永久性存储和永久性存储。 非永久性存储&#xff1a;容器创建会默认创建非永久性存储&#xff0c;该存储从属于容器&#xff0c;生命周期与容器相同&#xff0c;会随着容器的关闭而消失&#xff08;可理解为内存中数据&#xff0c;会随关机而消失&…

PHP表单token验证防CSRF攻击

在PHP中&#xff0c;表单token是一种安全机制&#xff0c;用于防止跨站请求伪造&#xff08;CSRF&#xff09;攻击。 CSRF攻击是一种利用用户身份在未经授权的情况下执行非法操作的攻击方式。 表单token的原理是在表单中生成一个随机的token&#xff0c;并将其存储在服务器端…

12. 自动化项目实战

目录 1. 登录测试 2. 测试首页的帖子列表数不为0 3. 帖子详情页校验 4. 发布帖子 5. 退出登录 自动化项目实施的基本流程如下图所示&#xff1a; 手工测试用例、自动化测试用例。 1. 登录测试 校验登录后主页显示的用户名称和登录时输入的用户名是否相等。 public class…

自动化运维工具Ansible教程(二)【进阶篇】

文章目录 前言Ansible 入门到精通自动化运维工具Ansible教程(一)【入门篇】自动化运维工具Ansible教程(二)【进阶篇】精通篇 进阶篇1. Ansible 的高级主题&#xff08;例如&#xff1a;角色、动态清单、变量管理等&#xff09;**1. 角色&#xff08;Roles&#xff09;**&#x…

WangEditor在Vue前端的应用

1、在Vue项目中安装WangEditor 对于Vue2&#xff1a; npm install wangeditor/editor-for-vue --save 或者 yarn add wangeditor/editor-for-vue 对于Vue3&#xff1a; npm install wangeditor/editor-for-vuenext --save 或者 yarn add wangeditor/editor-for-vuenext 2、将Wa…

Mac brew -v 报错 fatal: detected dubious ownership in repository

Mac 电脑查询 brew版本时报错&#xff0c;如下错误&#xff1a; Last login: Fri Sep 8 14:56:21 on ttys021 sunshiyusunshiyudeMacBook-Pro-2 ~ % brew -v Homebrew 4.0.3-30-g7ac31f7 fatal: detected dubious ownership in repository at /usr/local/Homebrew/Library/Ta…

l8-d9 UDP通信实现

一、函数接口扩展与UDP通信实现流程 1.write/read到send/recv 函数原型&#xff1a; ssize_t send(int sockfd, const void *buf, size_t len, int flags); ssize_t recv(int sockfd, void *buf, size_t len, int flags); 前三个参数同read/write一样&#xff1b; ssize_t rea…

Java-HashMap中put()方法是如何实现的,内含详细流程图

文章目录 Java中的HashMap什么是HashMap&#xff1f;对比其他Map中put()方法HashMap中put()方法使用示例 HashMap中put()源码解析手绘流程图实现原理源码探究&#xff08;JDK 1.8&#xff09; 设计put()的意义总结 Java中的HashMap 什么是HashMap&#xff1f; HashMap是Java中…

羊城杯2023 部分wp

目录 D0nt pl4y g4m3!!!(php7.4.21源码泄露&pop链构造) Serpent(pickle反序列化&python提权) ArkNights(环境变量泄露) Ez_misc(win10sinpping_tools恢复) D0nt pl4y g4m3!!!(php7.4.21源码泄露&pop链构造) 访问/p0p.php 跳转到了游戏界面 应该是存在302跳转…

1783_CMD启动MATLAB同时执行一个脚本

全部学习汇总&#xff1a; GitHub - GreyZhang/g_matlab: MATLAB once used to be my daily tool. After many years when I go back and read my old learning notes I felt maybe I still need it in the future. So, start this repo to keep some of my old learning notes…

ELK框架Logstash配合Filebeats和kafka使用

ELK框架Logstash配合Filebeats和kafka使用 本文目录 ELK框架Logstash配合Filebeats和kafka使用配置文件结构input为标准输入&#xff0c;output为标准输出input为log文件output为标准输出output为es input为tcpspringboot配置logstash配置 input为filebeatsfilebeats配置logsta…