What is the difference between filetype = and syntax = in Vim?
I noticed that in order for Vim to highlight the syntax of a particular file to highlight colors, you can 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=
?
source to share
'filetype'
is a superset 'syntax'
.
With 'filetype'
(if you've configured :filetype plugin on
), you also load the filetype plugins and their corresponding settings (e.g. indent config, compiler, mappings) from the config subdirectory ftplugin
in addition to setting the syntax for the filename.
This last part is done automatically by Vim as part of file type processing, in $VIMRUNTIME/syntax/syntax.vim
:
au! FileType * exe "set syntax=" . expand("<amatch>")
source to share