In Vim, how to display the text of a line with a specific color if it contains a specific word?

Issue

I have a simple Todo list :

141015 Call the office about something
141015 Buy a new tie
141016 Book 2 seats at theater

If an item is DONE, I simply delete it.
But if it is in progress – with WIP at the end of the line – I want to keep it in view, with the text just in DarkGray (which, against a black background, seems to be “blurred”).

141015 Call the office about something WIP (-> whole line in DarkGray)
141015 Buy a new tie
141016 Book 2 seats at theater

I came out with (in my syntax.vim) :

:syntax region xWip start='^' end='WIP$'
hi xWip ctermfg=DarkGray

but then, in my Todo list, everything was grayed

Where did I go wrong ?

Thanks for your help

Solution

The problem with your :syntax region is that Vim doesn’t check for an end match when starting the region, so every line (because it matches ^) got highlighted. You can switch to :syntax match if you want to stick with syntax highlighting instead of switching to :match (as in @evnu’s answer), as that command is window-local, unlike syntax highlighting.

:syntax match xWip "^.*WIP$"

Answered By – Ingo Karkat

Answer Checked By – Clifford M. (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.