This question already has an answer here:

I have a number of files with a syntax almost identical to C, though the files have suffixes such as .t, .sc

I would like to have the same syntax highlighting that I have for standard C files ending with the suffix .c.

For any one file I know I can execute:

:set filetype=c

but it is cumbersome to have to execute that command every time.

Is there something I can add to my .vimrc file so that some files with specific suffixes can have "C" syntax highlighting?

marked as duplicate by muru Jan 27 '17 at 0:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Yes, you can add the following:

augroup filetypedetect
    au! BufRead,BufNewFile *.t, *.sc setfiletype c
augroup END

However, to help keep your .vimrc tidy, you could also put that in a separate file called filetypes.vim in your .vim directory.


You can put this in your ~/.vimrc, or in a file in ~/.vim/ftdetect:

au BufNewFile,BufRead *.t,*.sc set filetype=c

Also see:

:help new-filetype

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