0

My vimrc has a function that extends the default-provided syntax for C:

function! Bx_c_syntax() "{{{
    "A faked version of the real thing
    let b:match_words=
                \ '\<BEGIN\>:\<END\?\>,' .
                \ ''
    syn keyword cStructure RECORD
endfunction #}}}

It also has this auto-group:

augroup Cc
    au!
    au FileType c call Bx_c_syntax()
    "...
augroup END

This gives me custom highlights/word-pairs as expected, however, when I resource my .vimrc (:source ~/.vimrc) I lose the new highlights/word-pairs until I reopen my C files.

What am I doing wrong?

4

What am I doing wrong?

Never ever touch FileType event. It's for ftdetect / ftplugin / indent / syntax, but not for you!

You must put your stuff into ~/.vim/after/syntax/c.vim instead, or whatever your &runtimepath is.

But what exactly goes wrong? Well, your vimrc should have syntax on or syntax enable line somewhere. And the first thing the command syntax on does is... it turns the syntax off, so no leftovers are hanging anywhere. After that all the good stuff is restored, but not yours, as it's still awaiting for FileType event to come... in vain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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