简体   繁体   English

语法在VIM中突出显示以匹配行的第一个/最后一个字母

[英]Syntax Highlighting in VIM to match first/last letter of line

I'm trying to to setup syntax highlighting in VIM to match the whole line only if the first non-whitespace character is "-" or if the last non-whitespace character of the line is ":". 我试图在VIM中设置语法高亮,以便仅当第一个非空白字符为“ - ”或者该行的最后一个非空白字符为“:”时才匹配整行。 A typical line has many tabs in front of text. 典型的行在文本前面有许多选项卡。

For instance I have lines like this (with tabs in front of the text): 例如,我有这样的行(在文本前面有标签):

- Go Home today - 今天回家

Eat vegetables: 吃蔬菜:

I don't however want to match these (not end or beginning of line). 但是我不想匹配这些(不是结束或开头)。

Go - Home today Go - 今天回家

Eat : vegetables 吃蔬菜

I have tried various iterations but can't get it right. 我尝试了各种迭代,但无法做到正确。 For instance the following only highlights dashes, including every dash in file. 例如,以下仅突出显示破折号,包括文件中的每个破折号。 I want it to highlight the whole line if the last or beginning characters match. 如果最后一个或开头的字符匹配,我希望它突出显示整行。

syn region dash start=/\v-/ end=// oneline
highlight link dash String

I know I just need to get my start/end searches right, but am having no luck. 我知道我只需要开始/结束搜索,但没有运气。 How can I do this? 我怎样才能做到这一点?

Try something like this: 尝试这样的事情:

syn region dash start=/^\s*\zs-/ end=/$/ oneline
syn region dash start=/^/ end=/:\ze\s*$/ oneline
highlight link dash String

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM