当前位置: 首页 > news >正文

vscode snippet 工程模板文件分享

2.3 自定义自己使用的代码片段
刷leetcode应该会很有用,比如引入一些链表node或者是图的定义等等。
比如写ROS的RVIZ输出的时候,能够有一个标准的代码片段的标准输出很有用。
比如写旋转矩阵或者类似的东西的时候在这里插入图片描述
这里可以创建两种snippets的配置文件,第一种是global的全局snippets配置文件,适合一些注释等所有语言都适用的情况?
我主要是使用了第二种,针对某一种语言创建snippets配置文件
在这里插入图片描述
这里我主要为C++程序和Python程序创建了Code Snippet文件,我将我的代码文件template分享:

首先是Python的template模板(python.json文件)

{// Place your snippets for python 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:// "Print to console": {// 	"prefix": "log",// 	"body": [// 		"console.log('$1');",// 		"$2"// 	],// 	"description": "Log output to console"// }"prefixs for leetcode": {"prefix": "prefix for leetcode","body": ["from typing import List","from queue import Queue",],"description": "prefix for leetcode"},"main for leetcode": {"prefix": "main for leetcode","body": ["if __name__ == \"__main__\":","    solution = Solution()","    grid = [['1','1','0','0','0'],","            ['1','1','0','0','0'],","            ['0','0','1','0','0'],","            ['0','0','0','1','1']]","    result = solution.numIslands(grid)","    print(f\"result = {result}\")"," ",],"description": "main for leetcode"},"bfs template": {"prefix": "bfs template","body": ["def bfs(_grid: List[List[str]], _visited: List[List[bool]], _i: int, _j: int):","    dirs = [[-1, 0], [1, 0], [0, -1], [0, 1]]","    que = Queue(0) # 0意味着初始化无线长度的queue","    que.put([_i, _j])","    _visited[_i][_j] = True","    while not que.empty():","        cur = que.get()","        curx = cur[0]","        cury = cur[1]","        for n in range(4):","            nextx = curx+dirs[n][0]","            nexty = cury+dirs[n][1]","            if(nextx < 0 or nextx >= len(_grid) or","                nexty < 0 or nexty >= len(_grid[0])):","                continue","            if(_visited[nextx][nexty] is False and _grid[nextx][nexty] == '1'):","                que.put([nextx, nexty])","                _visited[nextx][nexty] = True",],"description": "bfs template"}}

其次是C++的template模板(cpp.json文件)

{// Place your snippets for cpp 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:// "Print to console": {// 	"prefix": "log",// 	"body": [// 		"console.log('$1');",// 		"$2"// 	],// 	"description": "Log output to console"// }"sort algorithm with lambda": {"prefix": "sort_lambda","body": ["std::vector<int> v;","\/\/ 需要对v从大到小排列","sort(v.begin(), v.end(),[](int a, int b){return a>b;});"],"description": "Log output to console"},"prefixs for leetcode": {"prefix": "prefix for leetcode","body": ["#include <algorithm>","#include <iostream>","#include <unordered_set>","#include <vector>","#include <math.h>","#include <limits.h>","using namespace std;","struct TreeNode {","   int val;","   TreeNode *left;","   TreeNode *right;","   TreeNode() : val(0), left(nullptr), right(nullptr) {}","   TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}","   TreeNode(int x, TreeNode *left, TreeNode *right)","       : val(x), left(left), right(right) {}","};",],"description": "prefix for leetcode"},"main for leetcode": {"prefix": "main for leetcode","body": ["int main() {","   // 示例二叉树","   Solution solution;","   vector<int> nums = {7, 1, 5, 3, 6, 4};","   int result = solution.maxProfit(nums);","   std::cout << \"result: \" << result << std::endl;","}",],"description": "main for leetcode"}
}
http://www.lryc.cn/news/571071.html

相关文章:

  • CentOS 7 环境下 Visual Studio Code 安装与部署
  • 高防 IP 是如何帮助数藏行业防刷的
  • Objective-C与Swift混合编程
  • UDP访问DNS
  • Ubuntu 22.04离线安装Docker和NVIDIA Container Toolkit(使用gpu)
  • “智眸·家联“项目开发(一)
  • 【Java】抽象类与接口全解析
  • 【寻找Linux的奥秘】第十章:基础文件IO(上)
  • RGB解码:神经网络如何通过花瓣与叶片的数字基因解锁分类奥秘
  • 【云计算领域数学基础】组合数学优化
  • 基于nacos和gateway搭建微服务管理平台详细教程
  • elementui响应式数据类型变更情况
  • CVPR 2025最佳论文详解|VGGT:纯前馈Transformer架构,3D几何感知「大一统」模型来了!
  • FPGA基础 -- Verilog语言要素之值集合
  • Flutter - 原生交互 - 相机Camera - 曝光,缩放,录制视频
  • 【JSON-To-Video】AI智能体开发:为视频图片元素添加动效(滑入、旋转、滑出),附代码
  • 光谱相机的多模态成像技术详解
  • 数据仓库面试题合集⑥
  • 理解基本的RPC实现:从概念到实践
  • 2.涉及一个端到端的时间序列预测解决方案
  • 【Linux指南】文件内容查看与文本处理
  • 搜狗主动提交url并反馈快照更新软件(含源码)
  • 区间交集:区间选点
  • 231个web前端常用的javascript特效分享
  • 【C/C++开源库】适合嵌入式的定时器调度器
  • eXtremeComponents
  • Node.js Erlang比较
  • 第一次使用pycharm遇到的问题
  • 第二章 模型的评估与选择
  • java数据结构-栈、队列详解