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

9

2

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?

TK.

Posted 2010-04-11T12:15:29.237

Reputation: 465

I found both answers here somewhat circular. TL;DR filetype is a super-set of the features of syntax. See also this

– phs – 2016-12-06T21:47:19.523

Answers

-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.

S.Hoekstra

Posted 2010-04-11T12:15:29.237

Reputation: 2 231

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

wisbucky

Posted 2010-04-11T12:15:29.237

Reputation: 1 522

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.

akira

Posted 2010-04-11T12:15:29.237

Reputation: 52 754