# Highlighting specific words automatically with different background

I am using Vim 8.0.

I often pepper my Haskell code with undefined stub functions to be filled in later. Note that undefined is a valid keyword in Haskell

add :: Int -> Int -> Int
add a b = undefined


What I'd like to do, while in Haskell mode, is to make the word undefined word look like an eye-sore to remind me that implementations are still not complete.

In particular, I would like the background of undefined to be pink and the foreground color of the text to be, say, black

How do I go about doing this?

You can use matchadd() function like this. First define your custom highlighting color:

:hi CustomPink ctermbg=205 guibg=hotpink guifg=black ctermfg=black


Then you can color your words like this:

:call matchadd('CustomPink', '\<undefined\>')


The advantage of using the match functionality is, that this does not depend on the priorities of the defined syntax definitions and is usually more flexible.

Of course, one could create a simple plugin, that defines the colors, highlightes customs words and does some error checking (as well as remembering the id for each match, so it can easily be reverted). But that is out of the scope for my answer for now :)

• Wow! Thanks. This works nicely. How do I enable this only for files with extension '.hs' though? Otherwise the word "undefined" will appear in pink for all other file-types too. – smilingbuddha Jul 27 '17 at 2:55
• What filetype is '.hs'? – Christian Brabandt Jul 27 '17 at 20:10
• Haskell source code files. – smilingbuddha Jul 29 '17 at 15:12
• au FileType haskell :call matchadd('CustomPink' '\<undefined\>') should do it. – Christian Brabandt Jul 29 '17 at 16:43