您可以使用类似的扩展名来对具有不同缩进的线条进行不同的着色强调 https://marketplace.visualstudio.com/items?itemName=fabiospampinato.vscode-highlight。例如我可以得到这个:
在 settings.json 中使用以下代码:
"highlight.regexes": {
"((?<!.))(\\w.*)": [
{},
{
"color": "green",
"fontWeight": "bold",
// "outline": "1px solid #fff",
"letterSpacing": "1px"
}
],
"((?<!.))( )(\\w.*)": [
{},
{},
{
"color": "yellow",
}
],
"((?<!.))( )(\\w.*)": [
{},
{},
{
"color": "red",
}
]
}
我的设置为每个选项卡插入 2 个空格 - 我发现您需要在正则表达式中使用空格,而不是像这样更方便的东西(\\t\\t)
or ( ){4}
但必须使用( )
- 这 4 个空格对我来说代表两个选项卡 - 正则表达式在扩展中工作。
有关更多样式选项,请参阅https://code.visualstudio.com/api/references/vscode-api#DecorationRenderOptions https://code.visualstudio.com/api/references/vscode-api#DecorationRenderOptions
扩展链接显示了如何将其限制为您想要的任何文件类型。我将其合并到下面的第二批代码中。
如果您只想要项目符号标题,例如a-z
or 1-9
要着色,而不是该行上的其余文本,这也可以在正则表达式中实现:
"highlight.regexes": {
"((?<!.))(\\w.*)": {
"regexFlags": "gi",
// "filterLanguageRegex": "markdown",
"filterFileRegex": "Notes.*\\.txt",
"decorations": [
{},
{
"color": "green",
"fontWeight": "bold",
"letterSpacing": "1px",
"textDecoration": "underline"
},
]
},
"((?<!.))( )([a-z1-9][:\\.])(.*)": {
"regexFlags": "gi",
// "filterLanguageRegex": "markdown",
"filterFileRegex": "Notes.*\\.txt",
"decorations": [
{},
{},
{
"color": "yellow",
},
{}
]
},
"((?<!.))( )([a-z1-9][:\\.])(.*)": {
"regexFlags": "gi",
// "filterLanguageRegex": "markdown",
"filterFileRegex": "Notes.*\\.txt",
"decorations": [
{},
{},
{
"color": "red",
},
{}
]
}
[仅限于以下形式的文件Notes1.txt
, Notes blsdfs .txt
和类似的。]
显然,您可以根据需要使用更多级别的缩进,并使用遵循相同模式的更多正则表达式条目。