You are on page 1of 17

<html><head>

<meta http-equiv="Content-type" content="text/html; charset=windows-1252">


<title>Vim documentation: filetype</title>
</head>
<body bgcolor="#ffffff">
<form method="GET" action="../search.php">
<input name="search" type="text">
<input value="Search tag (regex)" type="submit"><br>
<input name="docs" value="help" checked="checked" type="radio">Help
<input name="docs" value="faq" type="radio">FAQ
<input name="docs" value="both" type="radio">Both
</form>
<hr>
<h1>Vim documentation: filetype</h1>
<a name="top"></a>
<a href="http://vimdoc.sourceforge.net/htmldoc/help.html">main help file</a>
<hr>
<pre>
*<a name="filetype.txt"></a><b>filetype.txt</b>* For Vim version 7.3. Last cha
nge: 2008 Jul 15
VIM REFERENCE MANUAL
by <a href="http://vimdoc.sourceforge.
net/htmldoc/intro.html#Bram">Bram</a> <a href="http://vimdoc.sourceforge.net/htm
ldoc/intro.html#Moolenaar">Moolenaar</a>

Filetypes
*<a name="filetype"></a>
<b>filetype</b>* *<a name="file-type"></a><b>file-type</b>*
1. Filetypes
|<a href="#filetypes">filetypes<
/a>|
2. Filetype plugin
|<a href="#filetype-plugins">fil
etype-plugins</a>|
3. Docs for the default <a href="#filetype">filetype</a> plugins.
|<a href
="#ftplugin-docs">ftplugin-docs</a>|
Also see |<a href="http://vimdoc.sourceforge.net/htmldoc/autocmd.html">autocmd.t
xt</a>|.
{Vi does not have any of these commands}
==============================================================================
1. Filetypes
*<a name="filetypes"></a><b>file
types</b>* *<a name="file-types"></a><b>file-types</b>*
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.
*<a name=":filetype"></a
><b>:filetype</b>* *<a name=":filet"></a><b>:filet</b>*
To enable file type detection, use this command in your <a href="http://vimdoc.s
ourceforge.net/htmldoc/starting.html#vimrc">vimrc</a>:
<b>
:filetype on</b>
Each time a new or existing file is edited, Vim will try to recognize the type

of the file and set the <a href="http://vimdoc.sourceforge.net/htmldoc/options.h


tml#%27filetype%27">'filetype'</a> option. This will trigger the <a href="http:
//vimdoc.sourceforge.net/htmldoc/autocmd.html#FileType">FileType</a>
event, which can be used to set the <a href="http://vimdoc.sourceforge.net/htmld
oc/syntax.html#syntax">syntax</a> highlighting, set <a href="http://vimdoc.sourc
eforge.net/htmldoc/options.html#options">options</a>, etc.
NOTE: Filetypes and <a href="http://vimdoc.sourceforge.net/htmldoc/options.html#
%27compatible%27">'compatible'</a> don't work together well, since being <a href
="http://vimdoc.sourceforge.net/htmldoc/intro.html#Vi">Vi</a>
compatible means <a href="http://vimdoc.sourceforge.net/htmldoc/options.html#opt
ions">options</a> are global. Resetting <a href="http://vimdoc.sourceforge.net/
htmldoc/options.html#%27compatible%27">'compatible'</a> is recommended,
if you didn't <a href="http://vimdoc.sourceforge.net/htmldoc/diff.html#do">do</a
> that already.
Detail: The "<a href="#:filetype">:filetype</a> on" command will load one of the
se files:
<a href="http://vimdoc.sourceforge.net/htmldoc/os_amiga.html#Ami
ga">Amiga</a>
$VIMRUNTIME/filetype.vim
<a href="http://vimdoc.sourceforge.net/htmldoc/os_mac.html#Mac">
Mac</a>
$VIMRUNTIME:filetype.vim
<a href="http://vimdoc.sourceforge.net/htmldoc/os_msdos.html#MSDOS">MS-DOS</a>
$VIMRUNTIME\filetype.vim
RiscOS
Vim:Filetype
<a href="http://vimdoc.sourceforge.net/htmldoc/os_unix.html#Unix
">Unix</a>
$VIMRUNTIME/filetype.vim
<a href="http://vimdoc.sourceforge.net/htmldoc/os_vms.html#VMS">
VMS</a>
$VIMRUNTIME/filetype.vim
This file is a Vim <a href="http://vimdoc.sourceforge.net/htmldoc/usr_41
.html#script">script</a> that defines autocommands for the
<a href="http://vimdoc.sourceforge.net/htmldoc/autocmd.html#BufNewFile">
BufNewFile</a> and <a href="http://vimdoc.sourceforge.net/htmldoc/autocmd.html#B
ufRead">BufRead</a> events. 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 <a href="http://vimdoc.sourceforge.net/htmldoc/gui.html#GUI">GU
I</a> is running or will start soon, the <a href="http://vimdoc.sourceforge.net/
htmldoc/gui.html#menu.vim">menu.vim</a> <a href="http://vimdoc.sourceforge.net/h
tmldoc/usr_41.html#script">script</a> is
also sourced. See |<a href="http://vimdoc.sourceforge.net/htmldoc/optio
ns.html#%27go-M%27">'go-M'</a>| about avoiding that.
To add your own file types, see |<a href="#new-filetype">new-filetype</a>| below
. To search for help on a
<a href="#filetype">filetype</a> prepend "ft-" and optionally append "-syntax",
"-indent" or
"-plugin". For example:
<b>
:help ft-vim-indent</b>
<b>
:help ft-vim-syntax</b>
<b>
:help ft-man-plugin</b>
If the file type is not detected automatically, or it finds the wrong type,
you can either set the <a href="http://vimdoc.sourceforge.net/htmldoc/options.ht
ml#%27filetype%27">'filetype'</a> option manually, or add a <a href="http://vimd
oc.sourceforge.net/htmldoc/options.html#modeline">modeline</a> to your
file. Example, for an IDL file use the command:
<b>
:set filetype=idl</b>
or add this |<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#modelin

e">modeline</a>| to the file:


<b><font color="purple">

/* vim: set filetype=idl : */ </font></b>

*<a name=":filetype-plugin-on"><
/a><b>:filetype-plugin-on</b>*
You can enable loading the <a href="http://vimdoc.sourceforge.net/htmldoc/usr_05
.html#plugin">plugin</a> files for specific file types with:
<b>
:filetype plugin on</b>
If <a href="#filetype">filetype</a> detection was not switched on yet, it will b
e <a href="http://vimdoc.sourceforge.net/htmldoc/motion.html#as">as</a> well.
This actually loads the file "ftplugin.vim" in <a href="http://vimdoc.sourceforg
e.net/htmldoc/options.html#%27runtimepath%27">'runtimepath'</a>.
The result is that when a file is edited its <a href="http://vimdoc.sourceforge.
net/htmldoc/usr_05.html#plugin">plugin</a> file is loaded (if there
is one for the detected <a href="#filetype">filetype</a>filetype). |<a href="htt
p://vimdoc.sourceforge.net/htmldoc/usr_43.html#filetype-plugin">filetype-plugin<
/a>|
*<a name=":filetype-plugin-off">
</a><b>:filetype-plugin-off</b>*
You can disable it again with:
<b>
:filetype plugin off</b>
The <a href="#filetype">filetype</a> detection is not switched off then. But if
you <a href="http://vimdoc.sourceforge.net/htmldoc/diff.html#do">do</a> switch
off
<a href="#filetype">filetype</a> detection, the plugins will not be loaded eithe
r.
This actually loads the file "ftplugof.vim" in <a href="http://vimdoc.sourceforg
e.net/htmldoc/options.html#%27runtimepath%27">'runtimepath'</a>.
*<a name=":filetype-indent-on"><
/a><b>:filetype-indent-on</b>*
You can enable loading the indent file for specific file types with:
<b>
:filetype indent on</b>
If <a href="#filetype">filetype</a> detection was not switched on yet, it will b
e <a href="http://vimdoc.sourceforge.net/htmldoc/motion.html#as">as</a> well.
This actually loads the file "indent.vim" in <a href="http://vimdoc.sourceforge.
net/htmldoc/options.html#%27runtimepath%27">'runtimepath'</a>.
The result is that when a file is edited its indent file is loaded (if there
is one for the detected <a href="#filetype">filetype</a>). |<a href="http://vimd
oc.sourceforge.net/htmldoc/indent.html#indent-expression">indent-expression</a>|
*<a name=":filetype-indent-off">
</a><b>:filetype-indent-off</b>*
You can disable it again with:
<b>
:filetype indent off</b>
The <a href="#filetype">filetype</a> detection is not switched off then. But if
you <a href="http://vimdoc.sourceforge.net/htmldoc/diff.html#do">do</a> switch
off
<a href="#filetype">filetype</a> detection, the indent files will not be loaded
either.
This actually loads the file "indoff.vim" in <a href="http://vimdoc.sourceforge.
net/htmldoc/options.html#%27runtimepath%27">'runtimepath'</a>.
This disables auto-indenting for files you will open. It will keep working in
already opened files. Reset <a href="http://vimdoc.sourceforge.net/htmldoc/opti
ons.html#%27autoindent%27">'autoindent'</a>, <a href="http://vimdoc.sourceforge.

net/htmldoc/options.html#%27cindent%27">'cindent'</a>, <a href="http://vimdoc.so


urceforge.net/htmldoc/options.html#%27smartindent%27">'smartindent'</a> and/or
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27indentexpr%27">'i
ndentexpr'</a> to disable indenting in an opened file.
*<a name=":filetype-off"></a><b>
:filetype-off</b>*
To disable file type detection, use this command:
<b>
:filetype off</b>
This will keep the flags for "<a href="http://vimdoc.sourceforge.net/htmldoc/usr
_05.html#plugin">plugin</a>" and "indent", but since no file types
are being detected, they won't work until the next "<a href="#:filetype">:filety
pe</a> on".

Overview:
a><b>:filetype-overview</b>*

*<a name=":filetype-overview"></

<b><font color="purple">command
detection
plugin
indent </font></b>
<a href="#:filetype">:filetype</a> on
on
unchange
d
unchanged
<a href="#:filetype">:filetype</a> off
off
unchange
d
unchanged
<a href="#:filetype">:filetype</a> <a href="http://vimdoc.sourceforge.net/htmldo
c/usr_05.html#plugin">plugin</a> on
on
on
unchanged
<a href="#:filetype">:filetype</a> <a href="http://vimdoc.sourceforge.net/htmldo
c/usr_05.html#plugin">plugin</a> off
unchanged
off
unchanged
<a href="#:filetype">:filetype</a> indent on
on
unchange
d
on
<a href="#:filetype">:filetype</a> indent off
unchanged
unchange
d
off
<a href="#:filetype">:filetype</a> <a href="http://vimdoc.sourceforge.net/htmldo
c/usr_05.html#plugin">plugin</a> indent on
on
on
on
<a href="#:filetype">:filetype</a> <a href="http://vimdoc.sourceforge.net/htmldo
c/usr_05.html#plugin">plugin</a> indent off
unchanged
off
off
To see the current status, type:
<b>
:filetype</b>
The output looks something like this:
<b>
filetype detection:ON plugin:ON indent:OFF</b>
The file types are also used for <a href="http://vimdoc.sourceforge.net/htmldoc/
syntax.html#syntax">syntax</a> highlighting. If the "<a href="http://vimdoc.sou
rceforge.net/htmldoc/syntax.html#:syntax">:syntax</a> on"
command is used, the file type detection is installed too. There is no need
to <a href="http://vimdoc.sourceforge.net/htmldoc/diff.html#do">do</a> "<a href=
"#:filetype">:filetype</a> on" after "<a href="http://vimdoc.sourceforge.net/htm
ldoc/syntax.html#:syntax">:syntax</a> on".
To disable one of the file types, add a line in your <a href="#filetype">filetyp
e</a> file, see
|<a href="#remove-filetype">remove-filetype</a>|.

*<a name="filetype-detec
t"></a><b>filetype-detect</b>*
To detect the file type again:
<b>
:filetype detect</b>
Use this if you started with an empty file and typed text that makes it
possible to detect the file type. For example, when you entered this in a
shell <a href="http://vimdoc.sourceforge.net/htmldoc/usr_41.html#script">script<
/a>: "#!/bin/csh".
When <a href="#filetype">filetype</a> detection was off, it will be enabled f
irst, like the "on"
argument was used.
*<a name="filetype-overr
ule"></a><b>filetype-overrule</b>*
When the same extension is used for two <a href="#filetypes">filetypes</a>, Vim
tries to guess what
kind of file it is. This doesn't always work. A number of global <a href="http
://vimdoc.sourceforge.net/htmldoc/eval.html#variables">variables</a>
can be used to overrule the <a href="#filetype">filetype</a> used for certain ex
tensions:
<b><font color="purple">
file name
variable </font></b>
*.asa
g:filetype_asa |<a href="http://vimdoc.sourceforge.net/
htmldoc/syntax.html#ft-aspvbs-syntax">ft-aspvbs-syntax</a>| |<a href="http://vim
doc.sourceforge.net/htmldoc/syntax.html#ft-aspperl-syntax">ft-aspperl-syntax</a>
|
*.asp
g:filetype_asp |<a href="http://vimdoc.sourceforge.net/
htmldoc/syntax.html#ft-aspvbs-syntax">ft-aspvbs-syntax</a>| |<a href="http://vim
doc.sourceforge.net/htmldoc/syntax.html#ft-aspperl-syntax">ft-aspperl-syntax</a>
|
*.asm
g:asmsyntax
|<a href="http://vimdoc.sourceforge.net/
htmldoc/syntax.html#ft-asm-syntax">ft-asm-syntax</a>|
*.prg
g:filetype_prg
*.pl
g:filetype_pl
*.inc
g:filetype_inc
*.w
g:filetype_w
|<a href="http://vimdoc.sourceforge.net/
htmldoc/syntax.html#ft-cweb-syntax">ft-cweb-syntax</a>|
*.i
g:filetype_i
|<a href="http://vimdoc.sourceforge.net/
htmldoc/syntax.html#ft-progress-syntax">ft-progress-syntax</a>|
*.p
g:filetype_p
|<a href="http://vimdoc.sourceforge.net/
htmldoc/syntax.html#ft-pascal-syntax">ft-pascal-syntax</a>|
*.sh
g:bash_is_sh
|<a href="http://vimdoc.sourceforge.net/
htmldoc/syntax.html#ft-sh-syntax">ft-sh-syntax</a>|
*.tex
g:tex_flavor
|<a href="#ft-tex-plugin">ft-tex-plugin<
/a>|
*<a name="filetype-ignor
e"></a><b>filetype-ignore</b>*
To avoid that certain files are being inspected, the g:ft_ignore_pat variable
is used. The default value is set like this:
<b>
:let g:ft_ignore_pat = '\.\(Z\|gz\|bz2\|zip\|tgz\)$'</b>
This means that the contents of compressed files are not inspected.
*<a name="new-filetype">
</a><b>new-filetype</b>*
If a file type that you want to use is not detected yet, there are four ways

to add it. In any way, it's better not to modify the $VIMRUNTIME/filetype.vim
file. It will be overwritten when installing a new version of Vim.
A. If you want to overrule all default file type checks.
This works by <a href="http://vimdoc.sourceforge.net/htmldoc/editing.html#wri
ting">writing</a> one file for each <a href="#filetype">filetype</a>. The disad
vantage is that
means there can be many files. The advantage is that you can simply drop
this file in the right directory to make it work.
*<a name="ftdetect"></a>
<b>ftdetect</b>*
1. Create your user runtime directory. You would normally use the first
item of the <a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%2
7runtimepath%27">'runtimepath'</a> option. Then create the directory "<a href="
#ftdetect">ftdetect</a>"
inside it. Example for <a href="http://vimdoc.sourceforge.net/htmldoc/os_
unix.html#Unix">Unix</a>:
<b>
:!mkdir ~/.vim</b>
<b>
:!mkdir ~/.vim/ftdetect</b>
2. Create a file that contains an <a href="http://vimdoc.sourceforge.net/html
doc/autocmd.html#autocommand">autocommand</a> to detect the file type.
Example:
<b>
au BufRead,BufNewFile *.mine
set filetype=mine</b>
Note that there is no "augroup" command, this has already been done
when sourcing your file. You could also use the <a href="http://vimdoc.so
urceforge.net/htmldoc/pattern.html#pattern">pattern</a> "*" and then
check the contents of the file to recognize it.
Write this file <a href="http://vimdoc.sourceforge.net/htmldoc/motion.html
#as">as</a> "mine.vim" in the "<a href="#ftdetect">ftdetect</a>" directory in yo
ur user
runtime directory. For example, for <a href="http://vimdoc.sourceforge.ne
t/htmldoc/os_unix.html#Unix">Unix</a>:
<b>
:w ~/.vim/ftdetect/mine.vim</b>
3. To use the new <a href="#filetype">filetype</a> detection you must restart
Vim.
The files in the "<a href="#ftdetect">ftdetect</a>" directory are used after
all the default
checks, thus they can overrule a previously detected file type. But you
can also use |<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#:se
tfiletype">:setfiletype</a>| to keep a previously detected filetype.
<a href="http://vimdoc.sourceforge.net/htmldoc/motion.html#B">B</a>. If you want
to detect your file after the default file type checks.
This works like A above, but instead of setting <a href="http://vimdoc.source
forge.net/htmldoc/options.html#%27filetype%27">'filetype'</a> unconditionally
use "<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#:setfiletype
">:setfiletype</a>". This will only set <a href="http://vimdoc.sourceforge.net/
htmldoc/options.html#%27filetype%27">'filetype'</a> if no file type was
detected yet. Example:
<b>
au BufRead,BufNewFile *.txt
setfiletype text</b>
You can also use the already detected file type in your command. For
example, to use the file type "mypascal" when "pascal" has been detected:
<b>
au BufRead,BufNewFile *
if &amp;ft == 'pascal' | set ft=mypascal
</b>

<b>
b>

| endif</

C. If your file type can be detected by the file name.


1. Create your user runtime directory. You would normally use the first
item of the <a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%2
7runtimepath%27">'runtimepath'</a> option. Example for <a href="http://vimdoc.s
ourceforge.net/htmldoc/os_unix.html#Unix">Unix</a>:
<b>
:!mkdir ~/.vim</b>
2. Create a file that contains autocommands to detect the file type.
Example:
<b>
" my filetype file</b>
<b>
if exists("did_load_filetypes")</b>
<b>
finish</b>
<b>
endif</b>
<b>
augroup filetypedetect</b>
<b>
au! BufRead,BufNewFile *.mine
setfiletype mine</b>
<b>
au! BufRead,BufNewFile *.xyz
setfiletype drawing</b>
<b>
augroup END</b>
Write this file <a href="http://vimdoc.sourceforge.net/htmldoc/motion.html
#as">as</a> "filetype.vim" in your user runtime directory. For
example, for <a href="http://vimdoc.sourceforge.net/htmldoc/os_unix.html#U
nix">Unix</a>:
<b>
:w ~/.vim/filetype.vim</b>
3. To use the new <a href="#filetype">filetype</a> detection you must restart
Vim.
Your filetype.vim will be sourced before the default <a href="http://vimdoc.s
ourceforge.net/htmldoc/autocmd.html#FileType">FileType</a> autocommands
have been installed. Your autocommands will match first, and the
"<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#:setfiletype">:s
etfiletype</a>" command will make sure that no other autocommands will set
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27filetype%27">'
filetype'</a> after this.
*<a name="new-filetype-s
cripts"></a><b>new-filetype-scripts</b>*
<a href="http://vimdoc.sourceforge.net/htmldoc/change.html#D">D</a>. If your <a
href="#filetype">filetype</a> can only be detected by inspecting the contents of
the
file.
1. Create your user runtime directory. You would normally use the first
item of the <a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%2
7runtimepath%27">'runtimepath'</a> option. Example for <a href="http://vimdoc.s
ourceforge.net/htmldoc/os_unix.html#Unix">Unix</a>:
<b>
:!mkdir ~/.vim</b>
2. Create a vim <a href="http://vimdoc.sourceforge.net/htmldoc/usr_41.html#sc
ript">script</a> file for doing this. Example:
<b>
if did_filetype()
" filetype already set..</b>
<b>
finish
" ..don't do these checks</b>
<b>
endif</b>
<b>
if getline(1) =~ '^#!.*\&lt;mine\&gt;'</b>
<b>
setfiletype mine</b>
<b>
elseif getline(1) =~? '\&lt;drawing\&gt;'</b>
<b>
setfiletype drawing</b>
<b>
endif</b>

See $VIMRUNTIME/scripts.vim for more examples.


Write this file <a href="http://vimdoc.sourceforge.net/htmldoc/motion.html
#as">as</a> "scripts.vim" in your user runtime directory. For
example, for <a href="http://vimdoc.sourceforge.net/htmldoc/os_unix.html#U
nix">Unix</a>:
<b>
:w ~/.vim/scripts.vim</b>
3. The detection will work right away, no need to restart Vim.
Your scripts.vim is loaded before the default checks for file types, which
means that your rules override the default rules in
$VIMRUNTIME/scripts.vim.
*<a name="remove-filetype"></a><
b>remove-filetype</b>*
If a file type is detected that is wrong for you, <a href="http://vimdoc.sourcef
orge.net/htmldoc/usr_90.html#install">install</a> a filetype.vim or
scripts.vim to catch it (see above). You can set <a href="http://vimdoc.sourcef
orge.net/htmldoc/options.html#%27filetype%27">'filetype'</a> to a non-existing
name to avoid that it will be set later anyway:
<b>
:set filetype=ignored</b>
If you are setting up a system with many users, and you don't want each user
to add/remove the same <a href="#filetypes">filetypes</a>, consider <a href="htt
p://vimdoc.sourceforge.net/htmldoc/editing.html#writing">writing</a> the filetyp
e.vim and
scripts.vim files in a runtime directory that is used for everybody. Check
the <a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27runtimepath%2
7">'runtimepath'</a> for a directory to use. If there isn't one, set
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27runtimepath%27">'
runtimepath'</a> in the |<a href="http://vimdoc.sourceforge.net/htmldoc/starting
.html#system-vimrc">system-vimrc</a>|. Be careful to keep the default
directories!

*<a name="autocmd-osfiletypes"><
/a><b>autocmd-osfiletypes</b>*
On operating systems which support storing a file type with the file, you can
specify that an <a href="http://vimdoc.sourceforge.net/htmldoc/autocmd.html#auto
command">autocommand</a> should only be executed if the file is of a
certain type.
The actual type checking depends on which platform you are running Vim
on; see your system's documentation for details.
To use osfiletype checking in an <a href="http://vimdoc.sourceforge.net/htmldoc/
autocmd.html#autocommand">autocommand</a> you should put a list of types to
match in angle brackets in place of a <a href="http://vimdoc.sourceforge.net/htm
ldoc/pattern.html#pattern">pattern</a>, like this:
<b>

:au BufRead *.html,&lt;&amp;faf;HTML&gt; runtime! syntax/html.vim</b>

This will match:


- Any file whose name ends in ".html"
- Any file whose type is "&amp;faf" or "HTML", where the meaning of these types
depends on which version of Vim you are using.
Unknown types are considered NOT to match.

You can also specify a type and a <a href="http://vimdoc.sourceforge.net/htmldoc


/pattern.html#pattern">pattern</a> at the same time (in which <a href="http://vi
mdoc.sourceforge.net/htmldoc/change.html#case">case</a> they
must both match):
<b>

:au BufRead &lt;&amp;fff&gt;diff*</b>

This will match files of type "&amp;fff" whose names start with "<a href="http:/
/vimdoc.sourceforge.net/htmldoc/diff.html#diff">diff</a>".
Note that osfiletype checking is skipped if Vim is compiled without the
|<a href="http://vimdoc.sourceforge.net/htmldoc/various.html#+osfiletype">+osfil
etype</a>| feature.
*<a name="plugin-details
"></a><b>plugin-details</b>*
The "<a href="http://vimdoc.sourceforge.net/htmldoc/usr_05.html#plugin">plugin</
a>" directory can be in any of the directories in the <a href="http://vimdoc.sou
rceforge.net/htmldoc/options.html#%27runtimepath%27">'runtimepath'</a>
option. All of these directories will be searched for plugins and they are
all loaded. For example, if this command:
<b>

set runtimepath</b>

produces this output:


<b><font color="purple">
/vim60 </font></b>

runtimepath=/etc/vim,~/.vim,/usr/local/share/vim

then Vim will load all plugins in these directories and below:
<b><font color="purple">
<b><font color="purple">
<b><font color="purple">

/etc/vim/plugin/ </font></b>
~/.vim/plugin/ </font></b>
/usr/local/share/vim/vim60/plugin/ </font></b>

Note that the last one is the value of <a href="http://vimdoc.sourceforge.net/ht


mldoc/starting.html#$VIMRUNTIME">$VIMRUNTIME</a> which has been expanded.
What if it looks like your <a href="http://vimdoc.sourceforge.net/htmldoc/usr_05
.html#plugin">plugin</a> is not being loaded? You can find out what
happens when Vim starts up by using the |<a href="http://vimdoc.sourceforge.net/
htmldoc/starting.html#-V">-V</a>| argument:
<b>

vim -V2</b>

You will see a lot of <a href="http://vimdoc.sourceforge.net/htmldoc/message.htm


l#messages">messages</a>, in between them is a remark about loading the
plugins. It starts with:
<b><font color="purple">

Searching for "plugin/**/*.vim" in </font></b>

There you can see where Vim looks for your <a href="http://vimdoc.sourceforge.ne
t/htmldoc/usr_05.html#plugin">plugin</a> scripts.
==============================================================================
2. Filetype <a href="http://vimdoc.sourceforge.net/htmldoc/usr_05.html#plugin">p
lugin</a>
*<a name="filetype-plugins"></a>

<b>filetype-plugins</b>*
When loading filetype plugins has been enabled |<a href="#:filetype-plugin-on">:
filetype-plugin-on</a>|, <a href="http://vimdoc.sourceforge.net/htmldoc/options.
html#options">options</a>
will be set and mappings defined. These are all local to the buffer, they
will not be used for other files.
Defining mappings for a <a href="#filetype">filetype</a> may get in the way of t
he mappings you
define yourself. There are a few ways to avoid this:
1. Set the "<a href="http://vimdoc.sourceforge.net/htmldoc/map.html#maplocallead
er">maplocalleader</a>" variable to the key sequence you want the mappings
to start with. Example:
<b>
:let maplocalleader = ","</b>
All mappings will then start with a comma instead of the default, which
is a <a href="http://vimdoc.sourceforge.net/htmldoc/intro.html#backslash">bac
kslash</a>. Also see |<a href="http://vimdoc.sourceforge.net/htmldoc/map.html#%
3CLocalLeader%3E">&lt;LocalLeader&gt;</a>|.
2. Define your own <a href="http://vimdoc.sourceforge.net/htmldoc/map.html#mappi
ng">mapping</a>. Example:
<b>
:map ,p &lt;Plug&gt;MailQuote</b>
You need to check the description of the <a href="http://vimdoc.sourceforge.n
et/htmldoc/usr_05.html#plugin">plugin</a> file below for the
functionality it offers and the string to map to.
You need to define your own <a href="http://vimdoc.sourceforge.net/htmldoc/ma
p.html#mapping">mapping</a> before the <a href="http://vimdoc.sourceforge.net/ht
mldoc/usr_05.html#plugin">plugin</a> is loaded (before
editing a file of that type). The <a href="http://vimdoc.sourceforge.net/htm
ldoc/usr_05.html#plugin">plugin</a> will then skip installing the
default <a href="http://vimdoc.sourceforge.net/htmldoc/map.html#mapping">mapp
ing</a>.
3. Disable defining mappings for a specific <a href="#filetype">filetype</a> by
setting a variable,
which contains the name of the <a href="#filetype">filetype</a>. For the "ma
il" <a href="#filetype">filetype</a> this
would be:
<b>
:let no_mail_maps = 1</b>
4. Disable defining mappings for all <a href="#filetypes">filetypes</a> by setti
ng a variable:
<b>
:let no_plugin_maps = 1</b>

*<a name="ftplugin-overr
ule"></a><b>ftplugin-overrule</b>*
If a global <a href="#filetype">filetype</a> <a href="http://vimdoc.sourceforge.
net/htmldoc/usr_05.html#plugin">plugin</a> does not <a href="http://vimdoc.sourc
eforge.net/htmldoc/diff.html#do">do</a> exactly what you want, there are three
ways to change this:
1. Add a few settings.
You must create a new <a href="#filetype">filetype</a> <a href="http://vimdoc
.sourceforge.net/htmldoc/usr_05.html#plugin">plugin</a> in a directory early in
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27runtimepath%27
">'runtimepath'</a>. For <a href="http://vimdoc.sourceforge.net/htmldoc/os_unix
.html#Unix">Unix</a>, for example you could use this file:

<b>

vim ~/.vim/ftplugin/fortran.vim</b>
You can set those settings and mappings that you would like to add. Note
that the global <a href="http://vimdoc.sourceforge.net/htmldoc/usr_05.html#pl
ugin">plugin</a> will be loaded after this, it may overrule the
settings that you <a href="http://vimdoc.sourceforge.net/htmldoc/diff.html#do
">do</a> here. If this is the <a href="http://vimdoc.sourceforge.net/htmldoc/ch
ange.html#case">case</a>, you need to use one of the
following two methods.
2. Make a copy of the <a href="http://vimdoc.sourceforge.net/htmldoc/usr_05.html
#plugin">plugin</a> and change it.
You must put the copy in a directory early in <a href="http://vimdoc.sourcefo
rge.net/htmldoc/options.html#%27runtimepath%27">'runtimepath'</a>. For <a href=
"http://vimdoc.sourceforge.net/htmldoc/os_unix.html#Unix">Unix</a>, for
example, you could <a href="http://vimdoc.sourceforge.net/htmldoc/diff.html#d
o">do</a> this:
<b>
cp $VIMRUNTIME/ftplugin/fortran.vim ~/.vim/ftplugin/fortran.vim</b>
Then you can edit the copied file to your liking. Since the b:did_ftplugin
variable will be set, the global <a href="http://vimdoc.sourceforge.net/htmld
oc/usr_05.html#plugin">plugin</a> will not be loaded.
A disadvantage of this method is that when the distributed <a href="http://vi
mdoc.sourceforge.net/htmldoc/usr_05.html#plugin">plugin</a> gets
improved, you will have to copy and modify it again.
3. Overrule the settings after loading the global <a href="http://vimdoc.sourcef
orge.net/htmldoc/usr_05.html#plugin">plugin</a>.
You must create a new <a href="#filetype">filetype</a> <a href="http://vimdoc
.sourceforge.net/htmldoc/usr_05.html#plugin">plugin</a> in a directory from the
end of
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27runtimepath%27
">'runtimepath'</a>. For <a href="http://vimdoc.sourceforge.net/htmldoc/os_unix
.html#Unix">Unix</a>, for example, you could use this file:
<b>
vim ~/.vim/after/ftplugin/fortran.vim</b>
In this file you can change just those settings that you want to change.
==============================================================================
3. Docs for the default <a href="#filetype">filetype</a> plugins.
*<a name="ftplugin-docs"></a><b>ftplugin-docs</b>*

CHANGELOG
lugin"></a><b>ft-changelog-plugin</b>*

*<a name="ft-changelog-p

Allows for <a href="http://vimdoc.sourceforge.net/htmldoc/starting.html#easy">ea


sy</a> entrance of Changelog entries in Changelog files. There are
some commands, mappings, and <a href="http://vimdoc.sourceforge.net/htmldoc/eval
.html#variables">variables</a> worth exploring:
Options:
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27comments%27">'com
ments'</a>
is made empty to not mess up <a href="http://vimdoc.sour
ceforge.net/htmldoc/change.html#formatting">formatting</a>.
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27textwidth%27">'te
xtwidth'</a>
is set to 78, which is standard.
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27formatoptions%27"
>'formatoptions'</a>
the '<a href="http://vimdoc.sourceforge.net/html
doc/motion.html#t">t</a>' flag is added to wrap when <a href="http://vimdoc.sour
ceforge.net/htmldoc/insert.html#inserting">inserting</a> text.

Commands:
NewChangelogEntry
Local mappings:
&lt;Leader&gt;o

Adds a new Changelog entry in an intelligent fashion


(see below).
Starts a new Changelog entry in an equally intelligent
fashion (see below).

Global mappings:
NOTE: The global mappings are accessed by sourcing the
ftplugin/changelog.vim file first, e.g. with
<b>
runtime ftplugin/changelog.vim</b>
in your |<a href="http://vimdoc.sourceforge.net/htmldoc/
starting.html#.vimrc">.vimrc</a>|.
&lt;Leader&gt;o
Switches to the ChangeLog buffer opened for the
current directory, or opens it in a new buffer if it
exists in the current directory. Then it does the
same <a href="http://vimdoc.sourceforge.net/htmldoc/moti
on.html#as">as</a> the local &lt;Leader&gt;o described above.
Variables:
g:changelog_timeformat Deprecated; use g:changelog_dateformat instead.
g:changelog_dateformat The date (and time) format used in ChangeLog entries.
The format accepted is the same <a href="http://vimdoc.s
ourceforge.net/htmldoc/motion.html#as">as</a> for the
|<a href="http://vimdoc.sourceforge.net/htmldoc/eval.htm
l#strftime%28%29">strftime()</a>| function.
The default is "%Y-%m-%d" which is the standard format
for many ChangeLog layouts.
g:changelog_username
The name and email address of the user.
The default is deduced from environment <a href="http://
vimdoc.sourceforge.net/htmldoc/eval.html#variables">variables</a> and
system files. It searches /etc/passwd for the comment
part of the current user, which informally contains
the real name of the user up to the first separating
comma. then it checks the $NAME environment variable
and finally runs `whoami` and `hostname` to build an
email address. The final form is
<b>
Full Name &lt;user@host&gt;</b>
g:changelog_new_date_format
The format to use when creating a new date-entry.
The following table describes special tokens in the
string:
%%
insert a single '<a href="http://vimdoc.
sourceforge.net/htmldoc/motion.html#%">%</a>' character
%d
insert the date from above
%u
insert the user from above
%c
where to position cursor when done
The default is "%d %u\n\n\t* %c\n\n", which produces
something like (| is where cursor will be, unless at
the start of the line where it denotes the beginning
of the line)
<b>
|2003-01-14 Full Name &lt;user@host&gt;</b>
<b>
|</b>
<b>
|
* |</b>
g:changelog_new_entry_format
The format used when creating a new entry.

<b>

The following table describes special tokens in the


string:
%c
where to position cursor when done
The default is "\t*%c", which produces something
similar to
|
* |</b>

g:changelog_date_entry_search
The search <a href="http://vimdoc.sourceforge.net/htmldo
c/pattern.html#pattern">pattern</a> to use when searching for a
date-entry.
The same tokens that can be used for
g:changelog_new_date_format can be used here <a href="ht
tp://vimdoc.sourceforge.net/htmldoc/motion.html#as">as</a> well.
The default is '^\s*%d\_s*%u' which finds lines
matching the form
<b>
|2003-01-14 Full Name &lt;user@host&gt;</b>
and some similar formats.
g:changelog_date_end_entry_search
The search <a href="http://vimdoc.sourceforge.net/htmldo
c/pattern.html#pattern">pattern</a> to use when searching for the end
of a date-entry.
The same tokens that can be used for
g:changelog_new_date_format can be used here <a href="ht
tp://vimdoc.sourceforge.net/htmldoc/motion.html#as">as</a> well.
The default is '^\s*$' which finds lines that contain
only <a href="http://vimdoc.sourceforge.net/htmldoc/patt
ern.html#whitespace">whitespace</a> or are completely empty.
<a href="#b:changelog_name">b:changelog_name</a>
*<a name="b:changelog_name"></a><b>b:changelog_name</b>*
Name of the ChangeLog file to look for.
The default is 'ChangeLog'.
b:changelog_path
Path of the ChangeLog to use for the current buffer.
The default is empty, thus looking for a file named
|<a href="#b:changelog_name">b:changelog_name</a>| in th
e same directory <a href="http://vimdoc.sourceforge.net/htmldoc/motion.html#as">
as</a> the
current buffer. If not found, the parent directory of
the current buffer is searched. This continues
recursively until a file is found or there are no more
parent directories to search.
b:changelog_entry_prefix
Name of a function to call to generate a prefix to a
new entry. This function takes no arguments and
should return a string containing the prefix.
Returning an empty prefix is fine.
The default generates the shortest path between the
ChangeLog's pathname and the current <a href="http://vim
doc.sourceforge.net/htmldoc/windows.html#buffers">buffers</a> pathname.
In the future, it will also be possible to use other
variable contexts for this variable, for example, g:.
The Changelog entries are inserted where they add the least amount of text.
After figuring out the current date and user, the file is searched for an

entry beginning with the current date and user and if found adds another item
under it. If not found, a new entry and item is prepended to the beginning of
the Changelog.

FORTRAN
gin"></a><b>ft-fortran-plugin</b>*

*<a name="ft-fortran-plu

Options:
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27expandtab%27">'ex
pandtab'</a>
is switched on to avoid tabs <a href="http://vimdoc.sourceforge.
net/htmldoc/motion.html#as">as</a> required by the Fortran
standards unless the user has set fortran_have_tabs in <a href="
http://vimdoc.sourceforge.net/htmldoc/starting.html#.vimrc">.vimrc</a>.
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27textwidth%27">'te
xtwidth'</a>
is set to 72 for fixed source format <a href="http://vimdoc.sour
ceforge.net/htmldoc/motion.html#as">as</a> required by the
Fortran standards and to 80 for free source format.
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27formatoptions%27"
>'formatoptions'</a> is set to break code and comment lines and to preserve long
lines. You can format comments with |<a href="http://vimdoc.sou
rceforge.net/htmldoc/change.html#gq">gq</a>|.
For further discussion of fortran_have_tabs and the method used for the
detection of source format see |<a href="http://vimdoc.sourceforge.net/htmldoc/s
yntax.html#ft-fortran-syntax">ft-fortran-syntax</a>|.

GIT COMMIT
lugin"></a><b>ft-gitcommit-plugin</b>*

*<a name="ft-gitcommit-p

One command, :DiffGitCached, is provided to show a <a href="http://vimdoc.source


forge.net/htmldoc/diff.html#diff">diff</a> of the current commit
in the preview <a href="http://vimdoc.sourceforge.net/htmldoc/windows.html#windo
w">window</a>. It is equivalent to calling "git <a href="http://vimdoc.sourcefo
rge.net/htmldoc/diff.html#diff">diff</a> --cached" plus
any arguments given to the command.

MAIL
"></a><b>ft-mail-plugin</b>*

*<a name="ft-mail-plugin

Options:
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27modeline%27">'mod
eline'</a>
is switched off to avoid the danger of trojan horses, and to
avoid that a Subject line with "Vim:" in it will cause an
error message.
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27textwidth%27">'te
xtwidth'</a>
is set to 72. This is often recommended for e-mail.
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27formatoptions%27"
>'formatoptions'</a> is set to break text lines and to repeat the comment leade
r
in new lines, so that a leading "<a href="http://vimdoc.sourcefo
rge.net/htmldoc/change.html#%3E">&gt;</a>" for <a href="http://vimdoc.sourceforg
e.net/htmldoc/quotes.html#quotes">quotes</a> is repeated.
You can also format quoted text with |<a href="http://vimdoc.sou
rceforge.net/htmldoc/change.html#gq">gq</a>|.

Local mappings:
&lt;LocalLeader&gt;q or \\MailQuote
Quotes the text selected in <a href="http://vimdoc.sourceforge.net/htmld
oc/visual.html#Visual">Visual</a> mode, or from the cursor position
to the end of the file in <a href="http://vimdoc.sourceforge.net/htmldoc
/intro.html#Normal">Normal</a> mode. This means "<a href="http://vimdoc.sourcef
orge.net/htmldoc/change.html#%3E">&gt;</a> " is inserted in
each line.
MAN
*<a name="ft-man-plugin"
></a><b>ft-man-plugin</b>* *<a name=":Man"></a><b>:Man</b>*
Displays a manual page in a <a href="http://vimdoc.sourceforge.net/htmldoc/todo.
html#nice">nice</a> way. Also see the user manual
|<a href="http://vimdoc.sourceforge.net/htmldoc/usr_12.html#find-manpage">find-m
anpage</a>|.
To start using the "<a href="#:Man">:Man</a>" command before any manual page was
loaded, source
this <a href="http://vimdoc.sourceforge.net/htmldoc/usr_41.html#script">script</
a> from your <a href="http://vimdoc.sourceforge.net/htmldoc/starting.html#startu
p">startup</a> <a href="http://vimdoc.sourceforge.net/htmldoc/starting.html#vimr
c">vimrc</a> file:
<b>

runtime ftplugin/man.vim</b>

Options:
<a href="http://vimdoc.sourceforge.net/htmldoc/options.html#%27iskeyword%27">'is
keyword'</a>
the '<a href="http://vimdoc.sourceforge.net/htmldoc/repeat.html#
.">.</a>' character is added to be able to use <a href="http://vimdoc.sourceforg
e.net/htmldoc/tagsrch.html#CTRL-]">CTRL-]</a> on the
manual page name.
Commands:
Man {name}
Display the manual page for {name} in a <a href="http://vimdoc.s
ourceforge.net/htmldoc/windows.html#window">window</a>.
Man {number} {name}
Display the manual page for {name} in a section {number}.
Global <a href="http://vimdoc.sourceforge.net/htmldoc/map.html#mapping">mapping<
/a>:
&lt;Leader&gt;K Displays the manual page for the <a href="http://vimdoc.sourcefo
rge.net/htmldoc/motion.html#word">word</a> under the cursor.
Local mappings:
<a href="http://vimdoc.sourceforge.net/htmldoc/tagsrch.html#CTRL-]">CTRL-]</a>
Jump to the manual page for the <a href="http://vimdoc.sourceforge.net/htmldoc/m
otion.html#word">word</a> under the cursor.
<a href="http://vimdoc.sourceforge.net/htmldoc/tagsrch.html#CTRL-T">CTRL-T</a>
Jump back to the previous manual page.

PDF
></a><b>ft-pdf-plugin</b>*

*<a name="ft-pdf-plugin"

Two maps, &lt;C-]&gt; and &lt;C-T&gt;, are provided to simulate a <a href="http:
//vimdoc.sourceforge.net/htmldoc/tagsrch.html#tag">tag</a> stack for navigating
the PDF. The following are treated <a href="http://vimdoc.sourceforge.net/htmld

oc/motion.html#as">as</a> <a href="http://vimdoc.sourceforge.net/htmldoc/tagsrch


.html#tags">tags</a>:
-

The byte offset after "startxref" to the xref table


The byte offset after the /Prev key in the trailer to an earlier xref table
A line of the form "0123456789 00000 n" in the xref table
An object reference like "1 0 R" anywhere in the PDF

These maps can be disabled with


<b>
:let g:no_pdf_maps = 1</b>

RPM SPEC
"></a><b>ft-spec-plugin</b>*

*<a name="ft-spec-plugin

Since the text for this <a href="http://vimdoc.sourceforge.net/htmldoc/usr_05.ht


ml#plugin">plugin</a> is rather long it has been put in a separate
file: |<a href="http://vimdoc.sourceforge.net/htmldoc/pi_spec.html">pi_spec.txt<
/a>|.

SQL
>ft-sql</b>*

*<a name="ft-sql"></a><b

Since the text for this <a href="http://vimdoc.sourceforge.net/htmldoc/usr_05.ht


ml#plugin">plugin</a> is rather long it has been put in a separate
file: |<a href="http://vimdoc.sourceforge.net/htmldoc/ft_sql.html">ft_sql.txt</a
>|.

TEX
></a><b>ft-tex-plugin</b>*

*<a name="ft-tex-plugin"

If the first line of a *.tex file has the form


<b>
%&amp;&lt;format&gt;</b>
then this determined the file type: plaintex (for plain TeX), context (for
ConTeXt), or tex (for LaTeX). Otherwise, the file is searched for keywords to
choose context or tex. If no keywords are found, it defaults to plaintex.
You can change the default by defining the variable g:tex_flavor to the format
(not the file type) you use most. Use one of these:
<b>
let g:tex_flavor = "plain"</b>
<b>
let g:tex_flavor = "context"</b>
<b>
let g:tex_flavor = "latex"</b>
Currently no other formats are recognized.
<a href="#top">top</a> - <a href="http://vimdoc.sourceforge.net/htmldoc/help.htm
l">main help file</a>
</pre>
<hr>
<form method="GET" action="../search.php">
<input name="search" type="text">
<input value="Search tag (regex)" type="submit"><br>
<input name="docs" value="help" checked="checked" type="radio">Help
<input name="docs" value="faq" type="radio">FAQ
<input name="docs" value="both" type="radio">Both

</form>

</body></html>

You might also like