Take markdown file as an example. I often found that some downloaded files suffixed with
.md (rather than
.markdown) can be recognized as markdown file, and syntax-highlighted as such. However, it won't work if I plainly create a file suffixed with
.md and open it. I have to
:set syntax=markdown so that Vim can highlight the file properly.
Also, I noticed that the syntax in some system files with strange suffix such as
.list can be magically highlighted. For example, on my Ubuntu system there is a file
/etc/apt/sources.list. Upon opening it, Vim can correctly recognize the syntax in the file is
debsources. But it won't be so if I copy the file to
~/Desktop and open again.
Another example, in the same directory
/etc/apt/apt.conf.d, there are files with no extension at all, and they can all be recognized having
So how does Vim determine which syntax to use for highlighting when encountering strange extensions or no extension at all?