9

What's the difference between syntax and filetype in Vim?

I learned that I can set syntax and filetype, but I can't understand the difference fully.

Is syntax used only for syntax highlighting?

  • I found both answers here somewhat circular. TL;DR filetype is a super-set of the features of syntax. See also this – phs Dec 6 '16 at 21:47
-1

It will expect certain filetypes to have a specific syntax. For example when you open a file.php it will expect a PHP syntax and colour it accordingly.

But some people use unusual filetypes but still want to use the correect syntax in the editor, for example file.txt or file.bla with PHP content inside.

Syntax is the "language" inside the file, where filetype is the actual type of the file.

6

filetype affects more things than syntax (for example: syntax highlighting, indenting rules, and other plugins). So generally, you should use filetype unless you only want to change the syntax highlighting.

http://vim.wikia.com/wiki/Filetype.vim

0

a c-file is a c-file (filetype), no matter how you color the different elements of the file (syntax). some decisions (for example, how to color some words, where to put brackets etc) are maded based upon the filetype.

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.