坚持写博客💪,分享自己的在学习、工作中的所得
- 给自己做备忘
- 对知识点记录、总结,加深理解
- 给有需要的人一些帮助,少踩一个坑,多走几步路
尽量以合适的方式排版,图文兼有
如果写的有误,或者有不理解的,均可在评论区留言
如果内容对你有帮助,欢迎点赞 👍 收藏 ⭐留言 📝。
虽然平台并不会有任何奖励,但是我会很开心,可以让我保持写博客的热情🙏🙏🙏
文章目录
🧁 vscode生成模板文件
在PyCharm中可以设置新建文件时生成模板文件,在VSCode中没有这个功能,但是VSCode中可以设置代码段,可以用来实现同样功能
File
> Preferences
> Configure User Snippets
输入python
后回车,会打开一个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"
// }
}
这是给出的例子。
{
// 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"
// }
"HEADER": {
"prefix": "desc",
"body": [
"#!/usr/bin/env python",
"# -*- encoding: utf-8 -*-",
"'''",
"@File : $TM_FILENAME",
"@Time : $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
"@Version : 1.0",
"@Desc : None",
"'''",
"",
"# import lib here",
"$0"
],
}
}
在其中添加"HEADER"
部分即可。
新建文件后输入desc
(也就是上面"prefix"
字段设置的值)再按TAB
键,就可以自动生成。光标默认在红色框位置,由"$0"
设置。
这里只提供一个最基本的通用版本,复制粘贴即可。需要更多信息,比如"Author"
、"Email"
等,自行添加在后面:
"'''",
"@File : $TM_FILENAME",
"@Time : $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
"@Version : 1.0",
"@Desc : None",
"@Author : xxx",
"@Email : xxx",
"'''",
需要用到更多的内部变量,比如"@Time : $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
,
可以根据参考链接选用
参考:https://code.visualstudio.com/docs/editor/userdefinedsnippets
如果内容对你有帮助,或者觉得写的不错
🏳️🌈欢迎点赞 👍 收藏 ⭐留言 📝
有问题,请在评论区留言