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.hqwc.cn/news/103231.html

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

相关文章

idea2021.1.3版本双击启动,没反应

今天打开电脑&#xff0c;点开idea&#xff0c;界面悬在这里&#xff0c;几秒然后就是没了。然后就一直打不开idea了。 然后又是卸载重装&#xff0c;又是删除缓存文件。我把电脑关于idea的文件全都删除了 。重新安装后&#xff08;首次运行倒是可以打开&#xff0c;但是关掉id…

搭建自己的OCR服务,第三步:PPOCRLabel标注工具安装

一、安装说明 安装好了PaddleOCR后&#xff0c;还需要安装PPOCRLabel这个标注工具&#xff0c;想要自己训练模型的话&#xff0c;有个标注工具会起很大作用。 尤其是PPOCRLabel就是跟PaddleOCR配套的标注工具&#xff0c;同样是开源的。 在下载 PaddleOCR 整个源码中&#x…

冠达管理:“旺季”来临,煤炭板块走高,云煤能源、陕西黑猫涨停

煤炭板块1日盘中发力走高&#xff0c;截至发稿&#xff0c;云煤动力、陕西黑猫涨停&#xff0c;兖矿动力涨超7%&#xff0c;晋控煤业、华阳股份涨超6%&#xff0c;山西焦煤、平煤股份涨超5%。 组织表明&#xff0c;动力大通胀背景下&#xff0c;未来3-5年煤炭供需偏紧的格局仍…

创邻科技图数据库课程走进一流高校

《图数据库原理和实践》 正式开课&#xff01; 最近&#xff0c;浙江大学计算机学院新开了一门名为 《图数据库原理和实践》 的新课程&#xff0c;该课程由创邻科技和浙江大学联合推出&#xff0c;吸引了许多学生踊跃参与&#xff01; 曾为浙大学子的创邻科技CTO周研博士作为…

VBA技术资料MF54:VBA_EXCEL实时获取鼠标位置

【分享成果&#xff0c;随喜正能量】若人散乱心&#xff0c;乃至以一花&#xff0c;供养于画像&#xff0c;渐见无数佛。所以发一幅释迦牟尼佛像&#xff0c;与同修善友一起每日在微博上供养&#xff0c;只要有供养之心&#xff0c;便可积累功德。以此回向&#xff0c;愿求者如…

YOLOV7改进-添加基于注意力机制的目标检测头(DYHEAD)

DYHEAD 复制到这&#xff1a; 1、models下新建文件 2、yolo.py中import一下 3、改IDetect这里 4、论文中说6的效果最好&#xff0c;但参数量不少&#xff0c;做一下工作量 5、在进入IDetect之前&#xff0c;会对RepConv做卷积 5、因为DYHEAD需要三个层输入的特征层一致&am…

【Python】迭代器__iter__、__next__

这里主要纠正迭代器的用法&#xff0c;因为一些教程传播错误示例让我很无语。 最大的错误就是&#xff0c;把__iter__和__next写在同个类里&#xff0c;每每看见都感到诧异。不是说这方法不行&#xff0c;主要是&#xff0c;一旦出现预期之外的运行结果往往很难查到原因(因为它…

【云原生】Kubeadmin安装k8s集群

目录 前言&#xff1a; 一 环境部署 1.1 服务器部署功能 1.2 环境准备&#xff08;所有节点&#xff09; 二 安装docker&#xff08;所有节点&#xff09; 三 所有节点安装kubeadm&#xff0c;kubelet和kubectl 3.1 定义kubernetes源 3.2 开机自启kubelet 四 部署K8S集…

“数智+绿色”驱动,宏工科技助力线缆线材稳定高品质生产

9月4日-7日&#xff0c;WIRE CHINA 2023中国国际线缆及线材展览会在上海新国际博览中心举办。宏工科技现场展出线缆线材自动化生产一站式解决方案&#xff0c;与现场观众共商“数字化、智能化、绿色化”发展机遇。 线缆是制造业中最大或产品使用范围最广的基础性配套产业之一&a…

1.4 空间中的曲线和曲面

空间中的曲线与曲面 知识点1 曲面方程定义 定义1 如果曲面 S 与方程F (x,y,z ) 0 有下述关系&#xff1a; &#xff08;1&#xff09; 曲面 S 上的任意点的坐标都满足此方程 &#xff08;2&#xff09;不在曲面S上的点的坐标不满足此方程 则F&#xff08;x,y,z&#xff0…

Elasticsearch实现词云效果Demo

文章目录 前言前期准备springbootElasticsearch依赖 思路准备数据查询数据处理文本样式处理 具体实施数据准备创建索引数据存储进行查询 踩坑记录聚合查询不生效问题 demo地址总结 前言 最近项目中使用Elasticsearch在做快速查询的功能&#xff0c;然后就想到了之前的一个项目…

2023-9-8 求组合数(二)

题目链接&#xff1a;求组合数 II #include <iostream> #include <algorithm>using namespace std;typedef long long LL; const int mod 1e9 7; const int N 100010;// 阶乘&#xff0c;阶乘的逆 int fact[N], infact[N];LL qmi(int a, int k, int p) {int res…