****2022-11-10 22:38:27 星期四

目的

重新写一套新的代码,一些基本框架都比较类似,如加载模块、构建函数、参数读取、创建日志甚至是一些好用的自建装饰器,不想每次创建新脚本时都重新写一遍,或者找其他文件复制粘贴再删除不需要的代码块时,那么自建所需的代码块(snippet)就很好的解决这个问题。

方法

步骤一

打开设置,找到用户自定义代码块设置
image

步骤二

从弹窗中选择需要创建代码块的编程语言
image

步骤三

创建所需的代码块,以 python 为例:

点击查看代码
{
	// 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"
	// }
	"python 模板(新脚本)": {
		"prefix": "pyformat",
		"body": [
			"\"\"\"",
			"$CURRENT_YEAR.$CURRENT_MONTH.$CURRENT_DATE Liukb",
			"    ",
			"\"\"\"",
			"",
			"import re",
			"import os",
			"import sys",
			"import time",
			"import logging",
			"import argparse",
			"import pandas as pd",
			"from glob import glob",
			"import subprocess as sp",
			"from collections import defaultdict",
			"",
			"logging.basicConfig(",
			"    level = logging.DEBUG,",
			"    filename = \"${1:./log}\",",
			"    filemode = \"a\",",
			"    format = \"[%(asctime)s - %(levelname)-4s - %(module)s : line %(lineno)s] %(message)s\",",
			"    datefmt = \"%Y-%m-%d %H:%M:%S\"",
			")",
			"",
			"class ${2:Core}:",
			"    def __init__(self):",
			"        self.name = 'posion'",
			"",
			"",
			"if __name__ == '__main__':",
			"    parse = argparse.ArgumentParser()",
			"    parse.add_argument('-b', '--batchs', default='')",
			"    opts = parse.parse_args()",
		],
		"description": "python 模板"
	},
}

使用实例

新建一个 python 格式的文件,输入配置中 prefix 定义的字段,不用完全输入完就会有提示。(vscode 不卡,或者模块安装正常,提示非常迅速)
image

原文地址:http://www.cnblogs.com/magower/p/16876786.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性