How do I tell what syntax file is being used?

52

14

Vim is syntax highlighting my file in a funny way, and I want to know what syntax file is responsible for this behaviour. How do I find out what syntax files vim has loaded?

Edward Z. Yang

Posted 2013-12-10T05:34:05.973

Reputation: 755

Answers

40

To find out which files Vim has actually loaded, execute

:scriptnames

garyjohn

Posted 2013-12-10T05:34:05.973

Reputation: 29 085

1On Mac OS X I modified the /usr/share/vim/vim73/filetype.vim. After using the above command I realized it was using MacVim's version at ~/Applications/MacVim.app/Contents/Resources/vim/runtime/filetype.vim. If you have MacVim installed, make sure you modify the correct file. – echamber – 2015-01-18T19:26:00.833

2You may have two syntax files loaded that have the same name. For example, vim ships with syntax highlighting for ColdFusion, (/usr/share/vim/vim81/syntax/cf.vim for me). I installed a custom cf.vim because the standard one is dated. :scriptnames shows both files. The default is lower on the script list; however, the former is being used. If you look at /usr/share/vim/vim81/syntax/cf.vim, there's a guard if exists("b:current_syntax") finish endif. So, in my case, the scriptnames was helpful, but I had to dig a bit deeper. – avejidah – 2018-06-05T16:38:14.777

That's useful. Now, here is something I'm not sure about: if a syntax file shows up in this list, is it guaranteed that the syntax file is "active"? I can see quite a few syntax files here. – Edward Z. Yang – 2013-12-10T10:04:34.540

7Generally, only the last one listed is "active", and even it may not be if you've turned syntax highlighting off. To see the syntax currently in effect, execute :echo b:current_syntax. To see the syntax items currently in effect, do as Ingo suggested and execute :syntax list. The latter may help if syntax items from more than one syntax file are in effect, as Ingo noted. – garyjohn – 2013-12-10T15:07:56.067

33

The syntax for the current buffer can be queried via

:setlocal syntax?

It usually (but not necessarily) corresponds to the buffer's filetype (:setlocal filetype?).

For a deeper look,

:syntax list

shows all syntax definitions (some syntaxes (can) include other language's syntaxes, e.g. java has html for the JavaDoc comment markup).

Ingo Karkat

Posted 2013-12-10T05:34:05.973

Reputation: 19 513

2This is what I came looking for based on the title of OP's question. OP of course clarifies in the description he's looking for the actual syntax file, but I appreciate you leaving this here since it's one of the first answers in search engines. – verboze – 2019-05-06T15:44:12.650

4

You can view what filetype(s) are currently used and by

:verbose set ft ?

The plugin handling the filetype is most likely located at

:e $VIMRUNTIME\ftplugin

Lieven Keersmaekers

Posted 2013-12-10T05:34:05.973

Reputation: 1 088