I have the following minimal .vimrc file:

" syntax enable
syntax case match
syntax keyword MyTodo TODO PENDING 
syntax keyword MyTodoIP IN PROGRESS 
syntax keyword MyTodoClosed CLOSED COMPLETE DONE
hi MyTodo        ctermfg=yellow
hi MyTodoIP      ctermfg=darkgreen
hi MyTodoClosed  ctermfg=darkgray

As is, this works fine (TODO, etc are correctly highlighted). However, When I uncomment syntax enable, my syntax keywords are not highlighted as I have specified.

I looked at :help syn-enable and it says the following:

The :syntax enable command will keep your current color settings. This allows using :highlight commands to set your preferred colors before or after using this command.

I also tried using

syntax match MyTodoMatch "TODO"

with hi MyTodoWatch with the same result.

There is a similar question on stackoverflow from 2011 that seems to be having the same problem, but no solution so I'm posting here.

What am I missing here? How can I use syntax enable with custom keywords?

Additionally, with syntax enable 'enabled', I can source ~/.vimrc after opening vim and the desired syntax is applied correctly.

  • can't reproduce. can you provide more information about how you're running vim? what version etc?
    – Mass
    Commented Mar 10, 2019 at 20:14
  • From vim --version: VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 19 2019 12:07:03) macOS version Included patches: 1-950 Compiled by Homebrew Huge version with MacVim GUI. Features included (+) or not (-): ... ... The relevant feature seems to be included: +syntax. There's a lot more
    – John
    Commented Mar 10, 2019 at 20:46
  • Are you using syntax enable somewhere else in your set up (somewhere below $HOME/.vim)? If so, this would reset all syntax items, if syntax is already enabled (but not the highlighting).
    – Ralf
    Commented Mar 10, 2019 at 23:04

1 Answer 1


The only explanation I have, is that there is another syntax enable (or syntax on) somewhere.

Background: If syntax enable is executed and syntax was enabled before, all syntax items are cleared. See $VIMRUNTIME/syntax/syntax.vim line 12. The documentation only talks about :highlight, not :syntax.

If you have the directory $HOME/.vim with other setup files, rename it to $HOME/.vim.off and test again.

If that doesn't help, you could run:

vim -V15verbose.out ...

Replace ... with whatever you use to reproduce the problem. After Vim is started, check that the problem can be reproduced and exit Vim.

This command will write a trace of all commands to the file verbose.out. You can then grep that file for syntax enable or syntax on to check if there is another invocation.

Note that Vim appends to that file, so you might want to delete it between tries.

Update: You should also check verbose.log for sy clear, syn clear or syntax clear.

  • I tried your suggestion (move .vim to .vim.off) and I still have the same problem. I checked the verbose output as you suggested, and the only instances of syntax on|enable that I find (other than the one in my example .vimrc) are in comment blocks in syntax files in MacVim. I'm going to try removing MacVim.
    – John
    Commented Mar 11, 2019 at 10:41
  • @John Than I'm out of ideas.
    – Ralf
    Commented Mar 11, 2019 at 11:03
  • @John Minor update (last line)
    – Ralf
    Commented Mar 11, 2019 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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