views:

17

answers:

1

Hi,

For a filetype plug-in, I would like to define and use a default custom highlight name, e.g.:

hi CsvColumn guifg=black guibg=NavajoWhite ctermfg=black ctermbg=yellow

However, I would like to allow users to define their own in preference to the default, so to do something like:

if <somehow or other check if 'CsvColumn' has NOT been defined>
    hi CsvColumn guifg=black guibg=NavajoWhite ctermfg=black ctermbg=yellow
fi

Is there a way to do this?

Since this is in a filetype plugin, it gets executed once everytime a buffer is loaded or read, so presumably there is a good chance it will be sourced after the user's '.vimrc' has been sourced, so any definition the user provides there or in a colorscheme will be overridden if I do not do the check.

+1  A: 

There is a function to do that, called hlexists({name}):

The result is a Number, which is non-zero if a highlight group called {name} exists. This is when the group has been defined in some way. Not necessarily when highlighting has been defined for it, it may also have been used for a syntax item.

So your code would be:

if hlexists('CsvColumn')
    hi ...
fi
UncleZeiv
That does it! Thanks!
Jeet