Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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=?

like image 558
Francesco C Avatar asked Nov 27 '14 12:11

Francesco C


Video Answer


1 Answers

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>")
like image 103
Ingo Karkat Avatar answered Dec 01 '22 16:12

Ingo Karkat