ThG
ThG

Reputation: 2401

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

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

Upvotes: 2

Views: 261

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172748

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$"

Upvotes: 2

evnu
evnu

Reputation: 6690

You could use :match for this: :match Error /^.*WIP$/. See :help match on how to define another hightlight group for different highlighting.

To run the matching automatically, consider using an autocommand:

:au BufRead,BufWrite * :match xWip /^.*WIP$/

Upvotes: 0

Related Questions