Johnny Utahh
Johnny Utahh

Reputation: 2478

vim: change line's font color based upon first character in the line?

In vim, I'd like to change a font color for just one line depending on if said line starts (with any preceding tab/space/whitespace) a dash, period, slash, or 'x'. How can I program/configure existing vim to do this?

Upvotes: 1

Views: 1325

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172530

In Vim, a colorscheme just provides a mapping of highlighting groups (usually generic ones such as Comment, String, though particular syntaxes also define things like vimLineComment) to foreground / background colors and text attributes such as bold or italic. What you want is a custom syntax definition.

:help usr_44.txt introduces writing a syntax file; you can also look to the existing ones in $VIMRUNTIME/syntax/ for inspiration. To highlight lines starting with x:

:syntax match mysyntaxXLine /^x.*$/
:highlight link mysyntaxXLine Error

Upvotes: 4

Related Questions