powershell - 如何在 VS Code 中为 Write-Debug 和 Write-Verbose 着色特定颜色?
问题描述
我在这里有一个简单的目标,但执行似乎相对复杂。我想要做的就是格式化Write-Debug
以及Write-Verbose
它们作为一行中的第一个文本出现的任何地方(有时缩进但前面没有字符)。
我想将它们格式化为与我的评论相同的颜色(或者只是手动将它们设置为相同的颜色就可以了)。可能我可能希望该行的其余部分使用相同的格式,但这是可选的。
我已经做了一个快速的谷歌,但答案的深度似乎让我对如此简单的事情有所了解,希望有人可以帮助简化它!
提前致谢。
解决方案
您可以使用Highlight 扩展来做到这一点。
在您的设置中:
"highlight.regexes": {
"((^\\s*Write-Debug)|(Write-Verbose))": { // A regex will be created from this string, don't forget to double escape it
"regexFlags": "gm", // Flags used when building this regex
"filterLanguageRegex": "powershell", // Apply only if current file's language matches this regex. Requires double escaping
"decorations": [ // Decoration options to apply to the capturing groups
{ "color": "red" }, // Decoration options to apply to the first capturing group, in this case "//TODO"
]
}
}
装饰选项中有更多样式选项。
要突出显示整行,请使用:
"((^\\s*Write-Debug.*)|(Write-Verbose.*))": {
文本必须在要修饰的捕获组中。如果你想以不同的方式装饰它,你可以把这条线的其余部分放到不同的捕获组中。
推荐阅读
- python - 根据间隔pyspark过滤数据框列中的值
- php - 如何将会话数据保存到数据库然后恢复它
- c# - 函数未在 C# 中执行
- javascript - java script game / 我想通过点击改变一个数字。我应该怎么办?
- python - 如何在 Pandas Python 中添加“子”数据帧或子行,每行和每个对象都有不同的操作?
- android - 努力使用 getByteArray 从 Bundle 中提取 ByteArray
- metadata - Google Optimize - 如何动态获取“测试描述”和其他测试元数据
- javascript - 使用 Storybook 渲染多个变体
- flutter - Dart:将文件的大小保持在一定大小而不截断
- python - Python datetime.fromisoformat() 拒绝 JavaScript 日期/时间字符串:ValueError: Invalid isoformat string