我有一个阿尔弗雷德片段,它为我输入了每周标记清单的大纲。下面是它看起来的样子:
## Week (4/25–4/29)
- [ ]
### Monday Apr 25, 2022
- [ ] Snippet
----我想把这个移到VS代码片段上。VS代码定义了环境变量,如$CURRENT_YEAR和$CURRENT_MONTH_NAME_SHORT,它们可以填充其中的一些内容。但是对于“周”(4/25-4/29),我真的很想知道下个星期五的日期(通常从今天起四天)。有什么方法可以用VS代码片段来完成吗?
为供参考,我的阿尔弗雷德是这样定义的:
## Week ({date:M/d}–{date +4d:M/d})
- [ ]
### Monday {date}
- [ ] Snippet
----发布于 2022-04-26 02:18:28
使用VSC代码段是不可能的。
使用扩展文件模板 (v1.10.0),您可以生成与now特定偏移的日期/时间。
您必须定义首选的dateTimeFormat设置。
定义以下设置(我们有一个命名日期格式:week-schedule)
可以是全局的,也可以是您的工作区
"templates.dateTimeFormat": {
"locale": "en-US",
"options": {
"year": "numeric",
"month": "2-digit",
"day": "2-digit",
"weekday": "long",
"hour12": false,
"hour": "2-digit",
"minute": "2-digit",
"second": "2-digit"
},
"template": "${month}/${day}"
"week-schedule": {
"options": {
"year": "numeric",
"month": "short",
"day": "2-digit",
"weekday": "long",
},
"template": "${weekday} ${month} ${day}, ${year}"
}
}定义以下模板(全局模板或工作区模板)
week-schedule.md
##@@## ${dateTimeFormat#template=${year}-${month}-${day}#offset=+1WD0 +1D#}_${dateTimeFormat#template=${month}-${day}#offset=+1WD0 +5D#}${input#Additional#find=^(.+)$#replace=-$1#}
## Week (${dateTimeFormat:offset=+1WD0 +1D:}–${dateTimeFormat:offset=+1WD0 +5D:})
- [ ]
### ${dateTimeFormat:week-schedule:offset=+1WD0 +1D:}
- [ ] Snippet
----
### ${dateTimeFormat:week-schedule:offset=+1WD0 +2D:}
- [ ] Snippet
----
### ${dateTimeFormat:week-schedule:offset=+1WD0 +3D:}
- [ ] Snippet
----
### ${dateTimeFormat:week-schedule:offset=+1WD0 +4D:}
- [ ] Snippet
----
### ${dateTimeFormat:week-schedule:offset=+1WD0 +5D:}
- [ ] Snippet
----它将创建一个带有日期和一些(可选)附加文本的文件名。
第一行需要那么长。整个文件名模板必须位于第1行。
模板可以包含VSC片段和输入字段以及其他一些变量。
编辑
在v1.11.0中有一个命令templates.pasteTemplate,您可以在其中插入带有键绑定的模板
{
"key": "ctrl+alt+w", // or any other combo
"command": "templates.pasteTemplate",
"args": {
"text": [
"## Week (${dateTimeFormat:week-schedule-head:offset=+1wd0 +1d:}–${dateTimeFormat:week-schedule-head:offset=+1wd0 +5d:})",
"- [ ]",
"",
"### ${dateTimeFormat:week-schedule:offset=+1wd0 +1d:}",
"- [ ] Snippet",
"",
"----"
]
}
}https://stackoverflow.com/questions/72001378
复制相似问题