Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a colorscheme for vim and want to give the ifand endif distinct colors.

I followed the tutorial on vimcasts and have the following file

"set 256 colors for gnome-terminal
if $COLORTERM == 'gnome-terminal'
    set t_Co=256
set background=dark
highlight clear
if exists("syntax_on")
    syntax reset
let g:colors_name = "my_color_scheme"

highlight guibg=#110117 ctermbg=233
highlight vimcommand guifg=#6792db ctermfg=68 guibg=NONE
highlight link number vimstring
highlight vimnotfunc guifg=#e6b13e ctermfg=179 guibg=NONE

The last lines changes the color of if but not of endif.

I used the snippet to find the name of the syntax

" Show syntax highlighting groups for word under cursor
nmap <C-S-P> :call <SID>SynStack()<CR>
function! <SID>SynStack()
  if !exists("*synstack")
  echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')

It shows ['vimIsCommand', 'vimCommand']. Setting an fg color for any of them does not seem to change the highlighting.

How can I find the right group name?

share|improve this question
up vote 0 down vote accepted

First, a colorscheme just provides a mapping of (mostly generic) highlight groups to certain colors and text attributes. A syntax script provides parsing rules to identify syntax elements. Those syntax groups (e.g. vimCommand) are then linked to the generic highlight groups (such as Statement).

Though a custom colorscheme could indeed provide a special color for, say, vimCommand, this is unusual. You can do that in your own colorscheme, but you can also perform the :hi link ... override in your ~/.vimrc.

In any case, you can only assign distinct colors to separate syntax groups.

The SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin is similar to the snippet in your question. With it, and by looking into the syntax definition in $VIMRUNTIME/syntax/vim.vim, I see that if belongs to the vimNotFunc group (together with elseif, return, and while), whereas endif is put together with all Vimscript commands into vimCommand. So, any color change would also affect many other commands, which may not be what you want.

To fix that, you'd need to tweak the syntax rules itself, by defining overriding :syntax commands, and putting them in ~/.vim/after/syntax/vim.vim. That's possible, but tedious (especially considering you might want to have the same for other languages, too). I'd rather reconsider whether you don't live with the predefined groupings.

share|improve this answer
Thank you so much for your thorough explanation. – Held May 16 '14 at 23:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.