What is the difference between filetype= and syntax= in Vim?

828 views Asked by At

I noticed that in order for Vim to color highlight the syntax of a specific file, one can both set the following in the _vimrc file:

au BufNewFile,BufRead *.file_extension set filetype=program_highlighting

au BufNewFile,BufRead *.file_extension set syntax=program_highlighting

What is the difference between using filetype= or syntax=?

1

There are 1 answers

0
Ingo Karkat On

The 'filetype' is a superset of 'syntax'.

With 'filetype' (assuming you have :filetype plugin on configured), you also load filetype plugins and their corresponding settings (e.g. indent config, compiler, mappings) from the ftplugin configuration subdir, in addition to setting the syntax to the filetype name.

That last part is done automatically by Vim as part of the filetype processing, in $VIMRUNTIME/syntax/syntax.vim:

au! FileType *  exe "set syntax=" . expand("<amatch>")