简体   繁体   中英

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 ":". 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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