Home Explore Blog CI



neovim

1st chunk of `runtime/doc/filetype.txt`
d468052fa103e45ffd60d78c995caa78322fba1b5d1c0f700000000100000fa4
*filetype.txt*  Nvim


		  VIM REFERENCE MANUAL    by Bram Moolenaar


Filetypes						*filetype* *file-type*

Also see |autocmd.txt|.

                                      Type |gO| to see the table of contents.

==============================================================================
1. Filetypes					*filetypes* *file-types*

Vim can detect the type of file that is edited.  This is done by checking the
file name and sometimes by inspecting the contents of the file for specific
text.

							*:filetype* *:filet*
To enable file type detection, use this command in your vimrc: >
	:filetype on
Each time a new or existing file is edited, Vim will try to recognize the type
of the file and set the 'filetype' option.  This will trigger the FileType
event, which can be used to set the syntax highlighting, set options, etc.

Detail: The ":filetype on" command will load these files:
		$VIMRUNTIME/filetype.lua
		$VIMRUNTIME/filetype.vim
	filetype.lua creates an autocommand that fires for all BufNewFile and
	BufRead events. It tries to detect the filetype based off of the
	file's extension or name.

	filetype.vim is a Vim script that defines autocommands for the
	BufNewFile and BufRead events. In contrast to filetype.lua, this
	file creates separate BufNewFile and BufRead events for each filetype
	pattern.

	If the file type is not found by the name, the file
	$VIMRUNTIME/scripts.vim is used to detect it from the contents of the
	file.
	When the GUI is running or will start soon, the |menu.vim| script is
	also sourced.

To add your own file types, see |new-filetype| below.  To search for help on a
filetype prepend "ft-" and optionally append "-syntax", "-indent" or
"-plugin".  For example: >
	:help ft-vim-indent
	:help ft-vim-syntax
	:help ft-man-plugin

If the file type is not detected automatically, or it finds the wrong type,
you can either set the 'filetype' option manually, or add a modeline to your
file.  Example, for an IDL file use the command: >
	:set filetype=idl

or add this |modeline| to the file: >
	/* vim: set filetype=idl : */
<
						*:filetype-plugin-on*
You can enable loading the plugin files for specific file types with: >
	:filetype plugin on
If filetype detection was not switched on yet, it will be as well.
This actually loads the file "ftplugin.vim" in 'runtimepath'.
The result is that when a file is edited its plugin file is loaded (if there
is one for the detected filetype). |filetype-plugin|

						*:filetype-plugin-off*
You can disable it again with: >
	:filetype plugin off
The filetype detection is not switched off then.  But if you do switch off
filetype detection, the plugins will not be loaded either.
This actually loads the file "ftplugof.vim" in 'runtimepath'.

						*:filetype-indent-on*
You can enable loading the indent file for specific file types with: >
	:filetype indent on
If filetype detection was not switched on yet, it will be as well.
This actually loads the file "indent.vim" in 'runtimepath'.
The result is that when a file is edited its indent file is loaded (if there
is one for the detected filetype). |indent-expression|

						*:filetype-indent-off*
You can disable it again with: >
	:filetype indent off
The filetype detection is not switched off then.  But if you do switch off
filetype detection, the indent files will not be loaded either.
This actually loads the file "indoff.vim" in 'runtimepath'.
This disables auto-indenting for files you will open.  It will keep working in
already opened files.  Reset 'autoindent', 'cindent', 'smartindent' and/or
'indentexpr' to disable indenting in an opened file.

						*:filetype-off*
To disable file type detection, use this command: >
	:filetype off
This will keep the flags for "plugin" and "indent", but since no file types
are being detected, they won't work until the next ":filetype on".


Overview:					*:filetype-overview*

command				detection	plugin		indent ~
:filetype on			on		unchanged	unchanged
:filetype off			off		unchanged	unchanged
:filetype

Title: Filetype Detection in Vim
Summary
Vim can detect file types by checking the file name and contents. The command ":filetype on" enables file type detection, triggering the FileType event to set syntax highlighting and options. Plugins and indent files can be enabled or disabled with ":filetype plugin on/off" and ":filetype indent on/off" respectively. To disable file type detection completely, use ":filetype off".