List known filetypes?

5,575 views
Skip to first unread message

Benct Philip Jonsson

unread,
May 26, 2010, 5:53:50 AM5/26/10
to vim...@googlegroups.com
How can I get a list of known file types?
Preferably with info which criteria they are recognized by
(file suffix, interpreter directive...)

(I suspect this is a faq, but none of help helpgrep or
Google returns anything useful, or I can't come up with
the right search term. :-? )

TIA,

/BP

Steve Hall

unread,
May 26, 2010, 7:59:07 AM5/26/10
to vim...@googlegroups.com
From: Benct Philip Jonsson, Wed, May 26, 2010 5:53 am

>
> How can I get a list of known file types?

:echo glob($VIMRUNTIME . '/ftplugin/*.vim')

or

:echo glob($VIMRUNTIME . '/syntax/*.vim')

(I find the latter a better exhaustive list, the former are often
shared by multiple languages.)


> Preferably with info which criteria they are recognized by
> (file suffix, interpreter directive...)

Much tougher, each syntax/filetype is detected in a different way.
Often by extension, but sometimes by internal file structure or
format.


--
Steve Hall [ digitect dancingpaper com ]

Tim Chase

unread,
May 26, 2010, 5:33:24 PM5/26/10
to vim...@googlegroups.com, Benct Philip Jonsson
On 05/26/2010 04:53 AM, Benct Philip Jonsson wrote:
> How can I get a list of known file types?
> Preferably with info which criteria they are recognized by
> (file suffix, interpreter directive...)

While you got an answer to the first half, the second part takes
digging into multiple files. You want to look at the stock
filetypes in $VIMRUNTIME/filetype.vim first. If you've added any
plugins or scripts, they may have dropped in their own file-type
detection. To find them, you'd want to peek in all the files in
the "ftdetect" subdirectories of the paths listed in your
'runtimepath' setting (yes, it a bunch of places).

You can read more details in the help at

:help :filetype " for details on the global
:help new-filetype " for details on custom/local versions

Hope this helps,

-tim


Tony Mechelynck

unread,
May 26, 2010, 10:14:39 AM5/26/10
to vim...@googlegroups.com, Benct Philip Jonsson

The relevant help tags are
:help 'runtimepath'
:help filetype.txt
:help new-filetype
:help new-filetype-scripts

For the criteria, you can:

a) list the autocommands which identify them

:au filetypedetect

These autocommands are set by $VIMRUNTIME/filetype.vim; one of them runs
$VIMRUNTIME/scripts.vim to try to identify files from their contents
when the name, path, etc. are not enough.

b) check which filetypes have scripts to handle them

(gvim) Syntax => Show filetypes in menu

which, however, lists only preinstalled filetypes, and not with the name
under which the 'filetype' or 'syntax' option knows them;

or else, for each of the directories listed in the 'runtimepath' option,
list (using ls on Unix or dir, possibly dir /w to save space, on Windows):

<directory>/ftplugin/*.vim
<directory>/indent/*.vim
<directory>/syntax/*.vim

Note that 'filetype' (as used by ftplugin and indent scripts) and
'syntax' (as used by syntax scripts) are separate options, which have
usually the same value but could be different.

In a "vanilla" install of Vim with no third-party scripts installed, the
only value of <directory> above pointing to an existing, nonempty
directory is your $VIMRUNTIME directory.


Best regards,
Tony.

Reply all
Reply to author
Forward
0 new messages