当前位置: 首页 > 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"}
}

相关文章:

  • 【SSH】在VScode中配置SSH
  • 一次硬件恢复之后数据文件0kb的故障恢复---惜分飞
  • 本地生活是如何进行抽佣的
  • 19|Whisper+ChatGPT:请AI代你听播客
  • Flask 快速精通:从入门到实战的轻量级 Web 框架指南
  • git submodule 和git repo介绍
  • 告别微服务,迎接SCS(Self-Contained Systems)?新概念还是炒冷饭?
  • 算法 学习 排序 2025年6月16日10:25:37
  • MySQL 命令行的核心操作命令详解
  • 始理解NLP:我的第一章学习心得
  • SQL注入漏洞-下篇
  • Hive 3.x集成Apache Ranger:打造精细化数据权限管理体系
  • 【Unity笔记】Unity URP 渲染中的灯光数量设置— 场景、使用方法与渲染原理详解
  • Mac Mini M4 安装 jdk8 以及 隐藏 设置内的Java菜单
  • Mac 安装JD-GUI
  • Windows PPT/word怎么pdf不降低分辨率,插入可编辑
  • CSS 选择器、PxCook软件、盒子模型
  • UE5 自动寻路AI Move To节点学习笔记
  • 智能开发工具RubyMine v2025.1正式发布——增强AI功能部署
  • 随着数字资产的增长,香港推进稳定币监管
  • wordpress主题诗词/网站优化北京seo
  • 自己电脑做服务器搭网站/seo关键词排名优化
  • 做一个商城网站需要提交那些文件/深圳网站优化推广
  • 影响网站显示度的原因/百度网盘怎么找资源
  • 千岛湖建设集团网站/郑州疫情最新消息
  • 用dw做网站的视频/关键词优化是怎么做的