50

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?

39

To find out which files Vim has actually loaded, execute

:scriptnames
  • 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 Dec 10 '13 at 10:04
  • 6
    Generally, 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 Dec 10 '13 at 15:07
  • 1
    On 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 Jan 18 '15 at 19:26
  • 1
    You 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 Jun 5 '18 at 16:38
31

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

  • This 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 May 6 at 15:44
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

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.