代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>filetype - Vim Documentation</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim8.0">
<meta name="syntax" content="help">
<meta name="settings" content="no_pre,use_css,expand_tabs">
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="jquery.min.js" type="text/javascript"></script>
<script src="mark-current-page.js" type="text/javascript"></script>
</head>
<body>
<header>
<div class="header">
<a href="http://vim-jp.org/">vim-jp</a>
/ <a href="http://vim-jp.org/vimdoc-en/">vimdoc-en</a>
/ filetype<br />
<a name="top"></a><h1>filetype - Vim Documentation</h1>
<a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
</div>
</header>
<nav>
<dl>
<dt>BASIC</dt>
<dd><ul>
<li><a href="quickref.html">quickref</a></li>
<li><a href="sponsor.html">sponsor</a></li>
</ul></dd>
<dt>USER MANUAL</dt>
<dd><ul>
<li><a href="usr_toc.html">usr_toc</a></li>
</ul></dd>
<dt>Getting Started</dt>
<dd><ul>
<li><a href="usr_01.html">usr_01</a></li>
<li><a href="usr_02.html">usr_02</a></li>
<li><a href="usr_03.html">usr_03</a></li>
<li><a href="usr_04.html">usr_04</a></li>
<li><a href="usr_05.html">usr_05</a></li>
<li><a href="usr_06.html">usr_06</a></li>
<li><a href="usr_07.html">usr_07</a></li>
<li><a href="usr_08.html">usr_08</a></li>
<li><a href="usr_09.html">usr_09</a></li>
<li><a href="usr_10.html">usr_10</a></li>
<li><a href="usr_11.html">usr_11</a></li>
<li><a href="usr_12.html">usr_12</a></li>
</ul></dd>
<dt>Editing Effectively</dt>
<dd><ul>
<li><a href="usr_20.html">usr_20</a></li>
<li><a href="usr_21.html">usr_21</a></li>
<li><a href="usr_22.html">usr_22</a></li>
<li><a href="usr_23.html">usr_23</a></li>
<li><a href="usr_24.html">usr_24</a></li>
<li><a href="usr_25.html">usr_25</a></li>
<li><a href="usr_26.html">usr_26</a></li>
<li><a href="usr_27.html">usr_27</a></li>
<li><a href="usr_28.html">usr_28</a></li>
<li><a href="usr_29.html">usr_29</a></li>
<li><a href="usr_30.html">usr_30</a></li>
<li><a href="usr_31.html">usr_31</a></li>
<li><a href="usr_32.html">usr_32</a></li>
</ul></dd>
<dt>Tuning Vim</dt>
<dd><ul>
<li><a href="usr_40.html">usr_40</a></li>
<li><a href="usr_41.html">usr_41</a></li>
<li><a href="usr_42.html">usr_42</a></li>
<li><a href="usr_43.html">usr_43</a></li>
<li><a href="usr_44.html">usr_44</a></li>
<li><a href="usr_45.html">usr_45</a></li>
</ul></dd>
<dt>Making Vim Run</dt>
<dd><ul>
<li><a href="usr_90.html">usr_90</a></li>
</ul></dd>
<dt>General subjects</dt>
<dd><ul>
<li><a href="intro.html">intro</a></li>
<li><a href="index.html">help</a></li>
<li><a href="helphelp.html">helphelp</a></li>
<li><a href="vimindex.html">index</a></li>
<li><a href="tags.html">tags</a></li>
<li><a href="howto.html">howto</a></li>
<li><a href="tips.html">tips</a></li>
<li><a href="message.html">message</a></li>
<li><a href="quotes.html">quotes</a></li>
<li><a href="todo.html">todo</a></li>
<li><a href="debug.html">debug</a></li>
<li><a href="develop.html">develop</a></li>
<li><a href="uganda.html">uganda</a></li>
</ul></dd>
<dt>Basic editing</dt>
<dd><ul>
<li><a href="starting.html">starting</a></li>
<li><a href="editing.html">editing</a></li>
<li><a href="motion.html">motion</a></li>
<li><a href="scroll.html">scroll</a></li>
<li><a href="insert.html">insert</a></li>
<li><a href="change.html">change</a></li>
<li><a href="indent.html">indent</a></li>
<li><a href="undo.html">undo</a></li>
<li><a href="repeat.html">repeat</a></li>
<li><a href="visual.html">visual</a></li>
<li><a href="various.html">various</a></li>
<li><a href="recover.html">recover</a></li>
</ul></dd>
<dt>Advanced editing</dt>
<dd><ul>
<li><a href="cmdline.html">cmdline</a></li>
<li><a href="options.html">options</a></li>
<li><a href="pattern.html">pattern</a></li>
<li><a href="map.html">map</a></li>
<li><a href="tagsrch.html">tagsrch</a></li>
<li><a href="quickfix.html">quickfix</a></li>
<li><a href="windows.html">windows</a></li>
<li><a href="tabpage.html">tabpage</a></li>
<li><a href="syntax.html">syntax</a></li>
<li><a href="spell.html">spell</a></li>
<li><a href="diff.html">diff</a></li>
<li><a href="autocmd.html">autocmd</a></li>
<li><a href="filetype.html">filetype</a></li>
<li><a href="eval.html">eval</a></li>
<li><a href="channel.html">channel</a></li>
<li><a href="fold.html">fold</a></li>
</ul></dd>
<dt>Special issues</dt>
<dd><ul>
<li><a href="print.html">print</a></li>
<li><a href="remote.html">remote</a></li>
<li><a href="term.html">term</a></li>
<li><a href="digraph.html">digraph</a></li>
<li><a href="mbyte.html">mbyte</a></li>
<li><a href="mlang.html">mlang</a></li>
<li><a href="arabic.html">arabic</a></li>
<li><a href="farsi.html">farsi</a></li>
<li><a href="hebrew.html">hebrew</a></li>
<li><a href="russian.html">russian</a></li>
<li><a href="ft_ada.html">ft_ada</a></li>
<li><a href="ft_sql.html">ft_sql</a></li>
<li><a href="hangulin.html">hangulin</a></li>
<li><a href="rileft.html">rileft</a></li>
</ul></dd>
<dt>GUI</dt>
<dd><ul>
<li><a href="gui.html">gui</a></li>
<li><a href="gui_w32.html">gui_w32</a></li>
<li><a href="gui_x11.html">gui_x11</a></li>
</ul></dd>
<dt>Interfaces</dt>
<dd><ul>
<li><a href="if_cscop.html">if_cscop</a></li>
<li><a href="if_lua.html">if_lua</a></li>
<li><a href="if_mzsch.html">if_mzsch</a></li>
<li><a href="if_perl.html">if_perl</a></li>
<li><a href="if_pyth.html">if_pyth</a></li>
<li><a href="if_tcl.html">if_tcl</a></li>
<li><a href="if_ole.html">if_ole</a></li>
<li><a href="if_ruby.html">if_ruby</a></li>
<li><a href="debugger.html">debugger</a></li>
<li><a href="workshop.html">workshop</a></li>
<li><a href="netbeans.html">netbeans</a></li>
<li><a href="sign.html">sign</a></li>
</ul></dd>
<dt>Versions</dt>
<dd><ul>
<li><a href="vi_diff.html">vi_diff</a></li>
<li><a href="version4.html">version4</a></li>
<li><a href="version5.html">version5</a></li>
<li><a href="version6.html">version6</a></li>
<li><a href="version7.html">version7</a></li>
<li><a href="version8.html">version8</a></li>
</ul></dd>
<dt>Remarks about specific systems</dt>
<dd><ul>
<li><a href="os_390.html">os_390</a></li>
<li><a href="os_amiga.html">os_amiga</a></li>
<li><a href="os_beos.html">os_beos</a></li>
<li><a href="os_dos.html">os_dos</a></li>
<li><a href="os_mac.html">os_mac</a></li>
<li><a href="os_mint.html">os_mint</a></li>
<li><a href="os_msdos.html">os_msdos</a></li>
<li><a href="os_os2.html">os_os2</a></li>
<li><a href="os_qnx.html">os_qnx</a></li>
<li><a href="os_risc.html">os_risc</a></li>
<li><a href="os_unix.html">os_unix</a></li>
<li><a href="os_vms.html">os_vms</a></li>
<li><a href="os_win32.html">os_win32</a></li>
</ul></dd>
<dt>Standard plugins</dt>
<dd><ul>
<li><a href="pi_getscript.html">pi_getscript</a></li>
<li><a href="pi_gzip.html">pi_gzip</a></li>
<li><a href="pi_logipat.html">pi_logipat</a></li>
<li><a href="pi_netrw.html">pi_netrw</a></li>
<li><a href="pi_paren.html">pi_paren</a></li>
<li><a href="pi_tar.html">pi_tar</a></li>
<li><a href="pi_vimball.html">pi_vimball</a></li>
<li><a href="pi_zip.html">pi_zip</a></li>
</ul></dd>
<dt>Filetype plugins</dt>
<dd><ul>
<li><a href="pi_spec.html">pi_spec</a></li>
</ul></dd>
<dt>Others</dt>
<dd><ul>
<li><a href="vim_faq.html">vim_faq</a></li>
</ul></dd>
</dl>
</nav>
<article class="Vimdoc VimdocJa">
<div id='vimCodeElement'>
<a class="Constant" href="filetype.html" name="filetype.txt">filetype.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2017 Mar 28<br>
<br>
<br>
<span class="Identifier">VIM REFERENCE MANUAL by Bram Moolenaar</span><br>
<br>
<br>
Filetypes <a class="Constant" href="filetype.html#filetype" name="filetype">filetype</a> <a class="Constant" href="filetype.html#file-type" name="file-type">file-type</a><br>
<br>
1. Filetypes <a class="Identifier" href="filetype.html#filetypes">filetypes</a><br>
2. Filetype plugin <a class="Identifier" href="filetype.html#filetype-plugins">filetype-plugins</a><br>
3. Docs for the default filetype plugins. <a class="Identifier" href="filetype.html#ftplugin-docs">ftplugin-docs</a><br>
<br>
Also see <a class="Identifier" href="autocmd.html">autocmd.txt</a>.<br>
<br>
<span class="Special">{Vi does not have any of these commands}</span><br>
<br>
<span class="PreProc">==============================================================================</span><br>
1. Filetypes <a class="Constant" href="filetype.html#filetypes" name="filetypes">filetypes</a> <a class="Constant" href="filetype.html#file-types" name="file-types">file-types</a><br>
<br>
Vim can detect the type of file that is edited. This is done by checking the<br>
file name and sometimes by inspecting the contents of the file for specific<br>
text.<br>
<br>
<a class="Constant" href="filetype.html#:filetype" name=":filetype">:filetype</a> <a class="Constant" href="filetype.html#:filet" name=":filet">:filet</a><br>
To enable file type detection, use this command in your vimrc:<br>
<div class="helpExample"> :filetype on</div>
Each time a new or existing file is edited, Vim will try to recognize the type<br>
of the file and set the <a class="Type" href="options.html#'filetype'">'filetype'</a> option. This will trigger the FileType<br>
event, which can be used to set the syntax highlighting, set options, etc.<br>
<br>
<span class="Todo">NOTE</span>: Filetypes and <a class="Type" href="options.html#'compatible'">'compatible'</a> don't work together well, since being Vi<br>
compatible means options are global. Resetting <a class="Type" href="options.html#'compatible'">'compatible'</a> is recommended,<br>
if you didn't do that already.<br>
<br>
Detail: The ":filetype on" command will load one of these files:<br>
Amiga $VIMRUNTIME/filetype.vim<br>
Mac $VIMRUNTIME:filetype.vim<br>
MS-DOS $VIMRUNTIME\filetype.vim<br>
RiscOS Vim:Filetype<br>
Unix $VIMRUNTIME/filetype.vim<br>
VMS $VIMRUNTIME/filetype.vim<br>
This file is a Vim script that defines autocommands for the<br>
BufNewFile and BufRead events. If the file type is not found by the<br>
name, the file $VIMRUNTIME/scripts.vim is used to detect it from the<br>
contents of the file.<br>
When the GUI is running or will start soon, the menu.vim script is<br>
also sourced. See <a class="Identifier" href="options.html#'go-M'">'go-M'</a> about avoiding that.<br>
<br>
To add your own file types, see <a class="Identifier" href="filetype.html#new-filetype">new-filetype</a> below. To search for help on a<br>
filetype prepend "ft-" and optionally append "-syntax", "-indent" or<br>
"-plugin". For example:<br>
<div class="helpExample"> :help ft-vim-indent<br>
:help ft-vim-syntax<br>
:help ft-man-plugin</div>
<br>
If the file type is not detected automatically, or it finds the wrong type,<br>
you can either set the <a class="Type" href="options.html#'filetype'">'filetype'</a> option manually, or add a modeline to your<br>
file. Example, for an IDL file use the command:<br>
<div class="helpExample"> :set filetype=idl</div>
<br>
or add this <a class="Identifier" href="options.html#modeline">modeline</a> to the file:<br>
<span class="PreProc">/* vim: set filetype=idl : */</span><br>
<br>
<a class="Constant" href="filetype.html#:filetype-plugin-on" name=":filetype-plugin-on">:filetype-plugin-on</a><br>
You can enable loading the plugin files for specific file types with:<br>
<div class="helpExample"> :filetype plugin on</div>
If filetype detection was not switched on yet, it will be as well.<br>
This actually loads the file "ftplugin.vim" in <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>.<br>
The result is that when a file is edited its plugin file is loaded (if there<br>
is one for the detected filetype). <a class="Identifier" href="usr_43.html#filetype-plugin">filetype-plugin</a><br>
<br>
<a class="Constant" href="filetype.html#:filetype-plugin-off" name=":filetype-plugin-off">:filetype-plugin-off</a><br>
You can disable it again with:<br>
<div class="helpExample"> :filetype plugin off</div>
The filetype detection is not switched off then. But if you do switch off<br>
filetype detection, the plugins will not be loaded either.<br>
This actually loads the file "ftplugof.vim" in <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>.<br>
<br>
<a class="Constant" href="filetype.html#:filetype-indent-on" name=":filetype-indent-on">:filetype-indent-on</a><br>
You can enable loading the indent file for specific file types with:<br>
<div class="helpExample"> :filetype indent on</div>
If filetype detection was not switched on yet, it will be as well.<br>
This actually loads the file "indent.vim" in <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>.<br>
The result is that when a file is edited its indent file is loaded (if there<br>
is one for the detected filetype). <a class="Identifier" href="indent.html#indent-expression">indent-expression</a><br>
<br>
<a class="Constant" href="filetype.html#:filetype-indent-off" name=":filetype-indent-off">:filetype-indent-off</a><br>
You can disable it again with:<br>
<div class="helpExample"> :filetype indent off</div>
The filetype detection is not switched off then. But if you do switch off<br>
filetype detection, the indent files will not be loaded either.<br>
This actually loads the file "indoff.vim" in <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>.<br>
This disables auto-indenting for files you will open. It will keep working in<br>
already opened files. Reset <a class="Type" href="options.html#'autoindent'">'autoindent'</a>, <a class="Type" href="options.html#'cindent'">'cindent'</a>, <a class="Type" href="options.html#'smartindent'">'smartindent'</a> and/or<br>
<a class="Type" href="options.html#'indentexpr'">'indentexpr'</a> to disable indenting in an opened file.<br>
<br>
<a class="Constant" href="filetype.html#:filetype-off" name=":filetype-off">:filetype-off</a><br>
To disable file type detection, use this command:<br>
<div class="helpExample"> :filetype off</div>
This will keep the flags for "plugin" and "indent", but since no file types<br>
are being detected, they won't work until the next ":filetype on".<br>
<br>
<br>
Overview: <a class="Constant" href="filetype.html#:filetype-overview" name=":filetype-overview">:filetype-overview</a><br>
<br>
<span class="PreProc">command detection plugin indent</span><br>
:filetype on on unchanged unchanged<br>
:filetype off off unchanged unchanged<br>
:filetype plugin on on on unchanged<br>
:filetype plugin off unchanged off unchanged<br>
:filetype indent on on unchanged on<br>
:filetype indent off unchanged unchanged off<br>
:filetype plugin indent on on on on<br>
:filetype plugin indent off unchanged off off<br>
<br>
To see the current status, type:<br>
<div class="helpExample"> :filetype</div>
The output looks something like this:<br>
<div class="helpExample"> filetype detection:ON plugin:ON indent:OFF</div>
<br>
The file types are also used for syntax highlighting. If the ":syntax on"<br>
command is used, the file type detection is installed too. There is no need<br>
to do ":filetype on" after ":syntax on".<br>
<br>
To disable one of the file types, add a line in your filetype file, see<br>
<a class="Identifier" href="filetype.html#remove-filetype">remove-filetype</a>.<br>
<br>
<a class="Constant" href="filetype.html#filetype-detect" name="filetype-detect">filetype-detect</a><br>
To detect the file type again:<br>
<div class="helpExample"> :filetype detect</div>
Use this if you started with an empty file and typed text that makes it<br>
possible to detect the file type. For example, when you entered this in a<br>
shell script: "#!/bin/csh".<br>
When filetype detection was off, it will be enabled first, like the "on"<br>
argument was used.<br>
<br>
<a class="Constant" href="filetype.html#filetype-overrule" name="filetype-overrule">filetype-overrule</a><br>
When the same extension is used for two filetypes, Vim tries to guess what<br>
kind of file it is. This doesn't always work. A number of global variables<br>
can be used to overrule the filetype used for certain extensions:<br>
<br>
<span class="PreProc">file name variable</span><br>
*.asa g:filetype_asa <a class="Identifier" href="syntax.html#ft-aspvbs-syntax">ft-aspvbs-syntax</a> <a class="Identifier" href="syntax.html#ft-aspperl-syntax">ft-aspperl-syntax</a><br>
*.asp g:filetype_asp <a class="Identifier" href="syntax.html#ft-aspvbs-syntax">ft-aspvbs-syntax</a> <a class="Identifier" href="syntax.html#ft-aspperl-syntax">ft-aspperl-syntax</a><br>
*.asm g:asmsyntax <a class="Identifier" href="syntax.html#ft-asm-syntax">ft-asm-syntax</a><br>
*.prg g:filetype_prg<br>
*.pl g:filetype_pl<br>
*.inc g:filetype_inc<br>
*.w g:filetype_w <a class="Identifier" href="syntax.html#ft-cweb-syntax">ft-cweb-syntax</a><br>
*.i g:filetype_i <a class="Identifier" href="syntax.html#ft-progress-syntax">ft-progress-syntax</a><br>
*.p g:filetype_p <a class="Identifier" href="syntax.html#ft-pascal-syntax">ft-pascal-syntax</a><br>
*.sh g:bash_is_sh <a class="Identifier" href="syntax.html#ft-sh-syntax">ft-sh-syntax</a><br>
*.tex g:tex_flavor <a class="Identifier" href="filetype.html#ft-tex-plugin">ft-tex-plugin</a><br>
<br>
<a class="Constant" href="filetype.html#filetype-ignore" name="filetype-ignore">filetype-ignore</a><br>
To avoid that certain files are being inspected, the g:ft_ignore_pat variable<br>
is used. The default value is set like this:<br>
<div class="helpExample"> :let g:ft_ignore_pat = '\.\(Z\|gz\|bz2\|zip\|tgz\)$'</div>
This means that the contents of compressed files are not inspected.<br>
<br>
<a class="Constant" href="filetype.html#new-filetype" name="new-filetype">new-filetype</a><br>
If a file type that you want to use is not detected yet, there are four ways<br>
to add it. In any way, it's better not to modify the $VIMRUNTIME/filetype.vim<br>
file. It will be overwritten when installing a new version of Vim.<br>
<br>
A. If you want to overrule all default file type checks.<br>
This works by writing one file for each filetype. The disadvantage is that<br>
means there can be many files. The advantage is that you can simply drop<br>
this file in the right directory to make it work.<br>
<a class="Constant" href="filetype.html#ftdetect" name="ftdetect">ftdetect</a><br>
1. Create your user runtime directory. You would normally use the first<br>
item of the <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> option. Then create the directory "ftdetect"<br>
inside it. Example for Unix:<br>
<div class="helpExample"> :!mkdir ~/.vim<br>
:!mkdir ~/.vim/ftdetect</div>
<br>
2. Create a file that contains an autocommand to detect the file type.<br>
Example:<br>
<div class="helpExample"> au BufRead,BufNewFile *.mine set filetype=mine</div>
<span class="Todo">Note</span> that there is no "augroup" command, this has already been done<br>
when sourcing your file. You could also use the pattern "*" and then<br>
check the contents of the file to recognize it.<br>
Write this file as "mine.vim" in the "ftdetect" directory in your user<br>
runtime directory. For example, for Unix:<br>
<div class="helpExample"> :w ~/.vim/ftdetect/mine.vim</div>
<br>
3. To use the new filetype detection you must restart Vim.<br>
<br>
The files in the "ftdetect" directory are used after all the default<br>
checks, thus they can overrule a previously detected file type. But you<br>
can also use <a class="Identifier" href="options.html#:setfiletype">:setfiletype</a> to keep a previously detected filetype.<br>
<br>
B. If you want to detect your file after the default file type checks.<br>
<br>
This works like A above, but instead of setting <a class="Type" href="options.html#'filetype'">'filetype'</a> unconditionally<br>
use ":setfiletype". This will only set <a class="Type" href="options.html#'filetype'">'filetype'</a> if no file type was<br>
detected yet. Example:<br>
<div class="helpExample"> au BufRead,BufNewFile *.txt setfiletype text</div>
<br>
You can also use the already detected file type in your command. For<br>
example, to use the file type "mypascal" when "pascal" has been detected:<br>
<div class="helpExample"> au BufRead,BufNewFile * if &ft == 'pascal' | set ft=mypascal<br>
| endif</div>
<br>
C. If your file type can be detected by the file name.<br>
1. Create your user runtime directory. You would normally use the first<br>
item of the <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> option. Example for Unix:<br>
<div class="helpExample"> :!mkdir ~/.vim</div>
<br>
2. Create a file that contains autocommands to detect the file type.<br>
Example:<br>
<div class="helpExample"> " my filetype file<br>
if exists("did_load_filetypes")<br>
finish<br>
endif<br>
augroup filetypedetect<br>
au! BufRead,BufNewFile *.mine setfiletype mine<br>
au! BufRead,BufNewFile *.xyz setfiletype drawing<br>
augroup END</div>
Write this file as "filetype.vim" in your user runtime directory. For<br>
example, for Unix:<br>
<div class="helpExample"> :w ~/.vim/filetype.vim</div>
<br>
3. To use the new filetype detection you must restart Vim.<br>
<br>
Your filetype.vim will be sourced before the default FileType autocommands<br>
have been installed. Your autocommands will match first, and the<br>
":setfiletype" command will make sure that no other autocommands will set<br>
<a class="Type" href="options.html#'filetype'">'filetype'</a> after this.<br>
<a class="Constant" href="filetype.html#new-filetype-scripts" name="new-filetype-scripts">new-filetype-scripts</a><br>
D. If your filetype can only be detected by inspecting the contents of the<br>
file.<br>
<br>
1. Create your user runtime directory. You would normally use the first<br>
item of the <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> option. Example for Unix:<br>
<div class="helpExample"> :!mkdir ~/.vim</div>
<br>
2. Create a vim script file for doing this. Example:<br>
<div class="helpExample"> if did_filetype() " filetype already set..<br>
finish " ..don't do these checks<br>
endif<br>
if getline(1) =~ '^#!.*\<mine\>'<br>
setfiletype mine<br>
elseif getline(1) =~? '\<drawing\>'<br>
setfiletype drawing<br>
endif</div>
See $VIMRUNTIME/scripts.vim for more examples.<br>
Write this file as "scripts.vim" in your user runtime directory. For<br>
example, for Unix:<br>
<div class="helpExample"> :w ~/.vim/scripts.vim</div>
<br>
3. The detection will work right away, no need to restart Vim.<br>
<br>
Your scripts.vim is loaded before the default checks for file types, which<br>
means that your rules override the default rules in<br>
$VIMRUNTIME/scripts.vim.<br>
<br>
<a class="Constant" href="filetype.html#remove-filetype" name="remove-filetype">remove-filetype</a><br>
If a file type is detected that is wrong for you, install a filetype.vim or<br>
scripts.vim to catch it (see above). You can set <a class="Type" href="options.html#'filetype'">'filetype'</a> to a non-existing<br>
name to avoid that it will be set later anyway:<br>
<div class="helpExample"> :set filetype=ignored</div>
<br>
If you are setting up a system with many users, and you don't want each user<br>
to add/remove the same filetypes, consider writing the filetype.vim and<br>
scripts.vim files in a runtime directory that is used for everybody. Check<br>
the <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> for a directory to use. If there isn't one, set<br>
<a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> in the <a class="Identifier" href="starting.html#system-vimrc">system-vimrc</a>. Be careful to keep the default<br>
directories!<br>
<br>
<br>
<a class="Constant" href="filetype.html#autocmd-osfiletypes" name="autocmd-osfiletypes">autocmd-osfiletypes</a><br>
<span class="Todo">NOTE</span>: this code is currently disabled, as the RISC OS implementation was<br>
removed. In the future this will use the <a class="Type" href="options.html#'filetype'">'filetype'</a> option.<br>
<br>
On operating systems which support storing a file type with the file, you can<br>
specify that an autocommand should only be executed if the file is of a<br>
certain type.<br>
<br>
The actual type checking depends on which platform you are running Vim<br>
on; see your system's documentation for details.<br>
<br>
To use osfiletype checking in an autocommand you should put a list of types to<br>
match in angle brackets in place of a pattern, like this:<br>
<br>
<div class="helpExample"> :au BufRead *.html,<&faf;HTML> runtime! syntax/html.vim</div>
<br>
This will match:<br>
<br>
- Any file whose name ends in ".html"<br>
- Any file whose type is "&faf" or "HTML", where the meaning of these types<br>
depends on which version of Vim you are using.<br>
Unknown types are considered NOT to match.<br>
<br>
You can also specify a type and a pattern at the same time (in which case they<br>
must both match):<br>
<br>
<div class="helpExample"> :au BufRead <&fff>diff*</div>
<br>
This will match files of type "&fff" whose names start with "diff".<br>
<br>
<br>
<a class="Constant" href="filetype.html#plugin-details" name="plugin-details">plugin-details</a><br>
The "plugin" directory can be in any of the directories in the <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a><br>
option. All of these directories will be searched for plugins and they are<br>
all loaded. For example, if this command:<br>
<br>
<div class="helpExample"> set runtimepath</div>
<br>
produces this output:<br>
<br>
<span class="PreProc">runtimepath=/etc/vim,~/.vim,/usr/local/share/vim/vim60</span><br>
<br>
then Vim will load all plugins in these directories and below:<br>
<br>
<span class="PreProc">/etc/vim/plugin/ </span><br>
<span class="PreProc">~/.vim/plugin/ </span><br>
<span class="PreProc">/usr/local/share/vim/vim60/plugin/ </span><br>
<br>
<span class="Todo">Note</span> that the last one is the value of $VIMRUNTIME which has been expanded.<br>
<br>
What if it looks like your plugin is not being loaded? You can find out what<br>
happens when Vim starts up by using the <a class="Identifier" href="starting.html#-V">-V</a> argument:<br>
<br>
<div class="helpExample"> vim -V2</div>
<br>
You will see a lot of messages, in between them is a remark about loading the<br>
plugins. It starts with:<br>
<br>
<span class="PreProc">Searching for "plugin/**/*.vim" in</span><br>
<br>
There you can see where Vim looks for your plugin scripts.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
2. Filetype plugin <a class="Constant" href="filetype.html#filetype-plugins" name="filetype-plugins">filetype-plugins</a><br>
<br>
When loading filetype plugins has been enabled <a class="Identifier" href="filetype.html#:filetype-plugin-on">:filetype-plugin-on</a>, options<br>
will be set and mappings defined. These are all local to the buffer, they<br>
will not be used for other files.<br>
<br>
Defining mappings for a filetype may get in the way of the mappings you<br>
define yourself. There are a few ways to avoid this:<br>
1. Set the "maplocalleader" variable to the key sequence you want the mappings<br>
to start with. Example:<br>
<div class="helpExample"> :let maplocalleader = ","</div>
All mappings will then start with a comma instead of the default, which<br>
is a backslash. Also see <a class="Identifier" href="map.html#<LocalLeader>"><LocalLeader></a>.<br>
<br>
2. Define your own mapping. Example:<br>
<div class="helpExample"> :map ,p <Plug>MailQuote</div>
You need to check the description of the plugin file below for the<br>
functionality it offers and the string to map to.<br>
You need to define your own mapping before the plugin is loaded (before<br>
editing a file of that type). The plugin will then skip installing the<br>
default mapping.<br>
<a class="Constant" href="filetype.html#no_mail_maps" name="no_mail_maps">no_mail_maps</a><br>
3. Disable defining mappings for a specific filetype by setting a variable,<br>
which contains the name of the filetype. For the "mail" filetype this<br>
would be:<br>
<div class="helpExample"> :let no_mail_maps = 1</div>
<a class="Constant" href="filetype.html#no_plugin_maps" name="no_plugin_maps">no_plugin_maps</a><br>
4. Disable defining mappings for all filetypes by setting a variable:<br>
<div class="helpExample"> :let no_plugin_maps = 1</div>
<br>
<br>
<a class="Constant" href="filetype.html#ftplugin-overrule" name="ftplugin-overrule">ftplugin-overrule</a><br>
If a global filetype plugin does not do exactly what you want, there are three<br>
ways to change this:<br>
<br>
1. Add a few settings.<br>
You must create a new filetype plugin in a directory early in<br>
<a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>. For Unix, for example you could use this file:<br>
<div class="helpExample"> vim ~/.vim/ftplugin/fortran.vim</div>
You can set those settings and mappings that you would like to add. <span class="Todo">Note</span><br>
that the global plugin will be loaded after this, it may overrule the<br>
settings that you do here. If this is the case, you need to use one of the<br>
following two methods.<br>
<br>
2. Make a copy of the plugin and change it.<br>
You must put the copy in a directory early in <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>. For Unix, for<br>
example, you could do this:<br>
<div class="helpExample"> cp $VIMRUNTIME/ftplugin/fortran.vim ~/.vim/ftplugin/fortran.vim</div>
Then you can edit the copied file to your liking. Since the b:did_ftplugin<br>
variable will be set, the global plugin will not be loaded.<br>
A disadvantage of this method is that when the distributed plugin gets<br>
improved, you will have to copy and modify it again.<br>
<br>
3. Overrule the settings after loading the global plugin.<br>
You must create a new filetype plugin in a directory from the end of<br>
<a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>. For Unix, for example, you could use this file:<br>
<div class="helpExample"> vim ~/.vim/after/ftplugin/fortran.vim</div>
In this file you can change just those settings that you want to change.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
3. Docs for the default filetype plugins. <a class="Constant" href="filetype.html#ftplugin-docs" name="ftplugin-docs">ftplugin-docs</a><br>
<br>
<br>
<span class="Statement">CHANGELOG </span><a class="Constant" href="filetype.html#ft-changelog-plugin" name="ft-changelog-plugin">ft-changelog-plugin</a><br>
<br>
Allows for easy entrance of Changelog entries in Changelog files. There are<br>
some commands, mappings, and variables worth exploring:<br>
<br>
Options:<br>
<a class="Type" href="options.html#'comments'">'comments'</a> is made empty to not mess up formatting.<br>
<a class="Type" href="options.html#'textwidth'">'textwidth'</a> is set to 78, which is standard.<br>
<a class="Type" href="options.html#'formatoptions'">'formatoptions'</a> the 't' flag is added to wrap when inserting text.<br>
<br>
Commands:<br>
NewChangelogEntry Adds a new Changelog entry in an intelligent fashion<br>
(see below).<br>
<br>
Local mappings:<br>
<span class="Special"><Leader></span>o Starts a new Changelog entry in an equally intelligent<br>
fashion (see below).<br>
<br>
Global mappings:<br>
<span class="Todo">NOTE</span>: The global mappings are accessed by sourcing the<br>
ftplugin/changelog.vim file first, e.g. with<br>
<div class="helpExample"> runtime ftplugin/changelog.vim</div>
in your <a class="Identifier" href="starting.html#.vimrc">.vimrc</a>.<br>
<span class="Special"><Leader></span>o Switches to the ChangeLog buffer opened for the<br>
current directory, or opens it in a new buffer if it<br>
exists in the current directory. Then it does the<br>
same as the local <span class="Special"><Leader></span>o described above.<br>
<br>
Variables:<br>
g:changelog_timeformat Deprecated; use g:changelog_dateformat instead.<br>
g:changelog_dateformat The date (and time) format used in ChangeLog entries.<br>
The format accepted is the same as for the<br>
<a class="Identifier" href="eval.html#strftime()">strftime()</a> function.<br>
The default is "%Y-%m-%d" which is the standard format<br>
for many ChangeLog layouts.<br>
g:changelog_username The name and email address of the user.<br>
The default is deduced from environment variables and<br>
system files. It searches /etc/passwd for the comment<br>
part of the current user, which informally contains<br>
the real name of the user up to the first separating<br>
comma. then it checks the $NAME environment variable<br>
and finally runs <span class="Comment">whoami</span> and <span class="Comment">hostname</span> to build an<br>
email address. The final form is<br>
<div class="helpExample"> Full Name <user@host></div>
<br>
g:changelog_new_date_format<br>
The format to use when creating a new date-entry.<br>
The following table describes special tokens in the<br>
string:<br>
%% insert a single '%' character<br>
%d insert the date from above<br>
%u insert the user from above<br>
%p insert result of b:changelog_entry_prefix<br>
%c where to position cursor when done<br>
The default is "%d %u\n\n\t* %p%c\n\n", which produces<br>
something like (| is where cursor will be, unless at<br>
the start of the line where it denotes the beginning<br>
of the line)<br>
<div class="helpExample"> |2003-01-14 Full Name <user@host><br>
|<br>
| * prefix|</div>
<br>
g:changelog_new_entry_format<br>
The format used when creating a new entry.<br>
The following table describes special tokens in the<br>
string:<br>
%p insert result of b:changelog_entry_prefix<br>
%c where to position cursor when done<br>
The default is "\t*%c", which produces something<br>
similar to<br>
<div class="helpExample"> | * prefix|</div>
<br>
g:changelog_date_entry_search<br>
The search pattern to use when searching for a<br>
date-entry.<br>
The same tokens that can be used for<br>
g:changelog_new_date_format can be used here as well.<br>
The default is '^\s*%d\_s*%u' which finds lines<br>
matching the form<br>
<div class="helpExample"> |2003-01-14 Full Name <user@host></div>
and some similar formats.<br>
<br>
g:changelog_date_end_entry_search<br>
The search pattern to use when searching for the end<br>
of a date-entry.<br>
The same tokens that can be used for<br>
g:changelog_new_date_format can be used here as well.<br>
The default is '^\s*$' which finds lines that contain<br>
only whitespace or are completely empty.<br>
<br>
b:changelog_name <a class="Constant" href="filetype.html#b:changelog_name" name="b:changelog_name">b:changelog_name</a><br>
Name of the ChangeLog file to look for.<br>
The default is 'ChangeLog'.<br>
<br>
b:changelog_path<br>
Path of the ChangeLog to use for the current buffer.<br>
The default is empty, thus looking for a file named<br>
<a class="Identifier" href="filetype.html#b:changelog_name">b:changelog_name</a> in the same directory as the<br>
current buffer. If not found, the parent directory of<br>
the current buffer is searched. This continues<br>
recursively until a file is found or there are no more<br>
parent directories to search.<br>
<br>
b:changelog_entry_prefix<br>
Name of a function to call to generate a prefix to a<br>
new entry. This function takes no arguments and<br>
should return a string containing the prefix.<br>
Returning an empty prefix is fine.<br>
The default generates the shortest path between the<br>
ChangeLog's pathname and the current buffers pathname.<br>
In the future, it will also be possible to use other<br>
variable contexts for this variable, for example, g:.<br>
<br>
The Changelog entries are inserted where they add the least amount of text.<br>
After figuring out the current date and user, the file is searched for an<br>
entry beginning with the current date and user and if found adds another item<br>
under it. If not found, a new entry and item is prepended to the beginning of<br>
the Changelog.<br>
<br>
<br>
<span class="Statement">FORTRAN </span><a class="Constant" href="filetype.html#ft-fortran-plugin" name="ft-fortran-plugin">ft-fortran-plugin</a><br>
<br>
Options:<br>
<a class="Type" href="options.html#'expandtab'">'expandtab'</a> is switched on to avoid tabs as required by the Fortran<br>
standards unless the user has set fortran_have_tabs in .vimrc.<br>
<a class="Type" href="options.html#'textwidth'">'textwidth'</a> is set to 72 for fixed source format as required by the<br>
Fortran standards and to 80 for free source format.<br>
<a class="Type" href="options.html#'formatoptions'">'formatoptions'</a> is set to break code and comment lines and to preserve long<br>
lines. You can format comments with <a class="Identifier" href="change.html#gq">gq</a>.<br>
For further discussion of fortran_have_tabs and the method used for the<br>
detection of source format see <a class="Identifier" href="syntax.html#ft-fortran-syntax">ft-fortran-syntax</a>.<br>
<br>
<br>
<span class="Statement">GIT COMMIT </span><a class="Constant" href="filetype.html#ft-gitcommit-plugin" name="ft-gitcommit-plugin">ft-gitcommit-plugin</a><br>
<br>
One command, :DiffGitCached, is provided to show a diff of the current commit<br>
in the preview window. It is equivalent to calling "git diff --cached" plus<br>
any arguments given to the command.<br>
<br>
<br>
<span class="Statement">MAIL </span><a class="Constant" href="filetype.html#ft-mail-plugin" name="ft-mail-plugin">ft-mail-plugin</a><br>
<br>
Options:<br>
<a class="Type" href="options.html#'modeline'">'modeline'</a> is switched off to avoid the danger of trojan horses, and to<br>
avoid that a Subject line with "Vim:" in it will cause an<br>
error message.<br>
<a class="Type" href="options.html#'textwidth'">'textwidth'</a> is set to 72. This is often recommended for e-mail.<br>
<a class="Type" href="options.html#'formatoptions'">'formatoptions'</a> is set to break text lines and to repeat the comment leader<br>
in new lines, so that a leading ">" for quotes is repeated.<br>
You can also format quoted text with <a class="Identifier" href="change.html#gq">gq</a>.<br>
<br>
Local mappings:<br>
<span class="Special"><LocalLeader></span>q or \\MailQuote<br>
Quotes the text selected in Visual mode, or from the cursor position<br>
to the end of the file in Normal mode. This means "> " is inserted in<br>
each line.<br>
<br>
<span class="Statement">MAN </span><a class="Constant" href="filetype.html#ft-man-plugin" name="ft-man-plugin">ft-man-plugin</a> <a class="Constant" href="filetype.html#:Man" name=":Man">:Man</a> <a class="Constant" href="filetype.html#man.vim" name="man.vim">man.vim</a><br>
<br>
Displays a manual page in a nice way. Also see the user manual<br>
<a class="Identifier" href="usr_12.html#find-manpage">find-manpage</a>.<br>
<br>
To start using the ":Man" command before any manual page was loaded, source<br>
this script from your startup vimrc file:<br>
<br>
<div class="helpExample"> runtime ftplugin/man.vim</div>
<br>
Options:<br>
<a class="Type" href="options.html#'iskeyword'">'iskeyword'</a> the '.' character is added to be able to use <span class="Special">CTRL-]</span> on the<br>
manual page name.<br>
<br>
Commands:<br>
Man <span class="Special">{name}</span> Display the manual page for <span class="Special">{name}</span> in a window.<br>
Man <span class="Special">{number}</span> <span class="Special">{name}</span><br>
Display the manual page for <span class="Special">{name}</span> in a section <span class="Special">{number}</span>.<br>
<br>
Global mapping:<br>
<span class="Special"><Leader></span>K Displays the manual page for the word under the cursor.<br>
<span class="Special"><Plug></span>ManPreGetPage idem, allows for using a mapping:<br>
<div class="helpExample"> nmap <F1> <Plug>ManPreGetPage<CR></div>
<br>
Local mappings:<br>
<span class="Special">CTRL-]</span> Jump to the manual page for the word under the cursor.<br>
<span class="Special">CTRL-T</span> Jump back to the previous manual page.<br>
q Same as ":quit"<br>
<br>
To use a vertical split instead of horizontal:<br>
<div class="helpExample"> let g:ft_man_open_mode = 'vert'</div>
To use a new tab:<br>
<div class="helpExample"> let g:ft_man_open_mode = 'tab'</div>
<br>
To enable folding use this:<br>
<div class="helpExample"> let g:ft_man_folding_enable = 1</div>
If you do not like the default folding, use an autocommand to add your desired<br>
folding style instead. For example:<br>
<div class="helpExample"> autocmd FileType man setlocal foldmethod=indent foldenable</div>
<br>
You may also want to set <a class="Type" href="options.html#'keywordprg'">'keywordprg'</a> to make the <a class="Identifier" href="various.html#K">K</a> command open a manual<br>
page in a Vim window:<br>
<div class="helpExample"> set keywordprg=:Man</div>
<br>
<br>
<span class="Statement">MANPAGER </span><a class="Constant" href="filetype.html#manpager.vim" name="manpager.vim">manpager.vim</a><br>
<br>
The :Man command allows you to turn Vim into a manpager (that syntax highlights<br>
manpages and follows linked manpages on hitting <span class="Special">CTRL-]</span>).<br>
<br>
Works on:<br>
<br>
- Linux<br>
- Mac OS<br>
- FreeBSD<br>
- Cygwin<br>
- Win 10 under Bash<br>
<br>
Untested:<br>
<br>
- Amiga OS<br>
- BeOS<br>
- OS/2<br>
<br>
For bash,zsh,ksh or dash by adding to the config file (.bashrc,.zshrc, ...)<br>
<br>
export MANPAGER="env MAN_PN=1 vim -M +MANPAGER -"<br>
<br>
For (t)csh by adding to the config file<br>
<br>
setenv MANPAGER "env MAN_PN=1 vim -M +MANPAGER -"<br>
<br>
For fish by adding to the config file<br>
<br>
set -x MANPAGER "env MAN_PN=1 vim -M +MANPAGER -"<br>
<br>
If man sets the $MAN_PN environment variable, like man-db, the most common<br>
implementation on Linux and Mac OS, then the "env MAN_PN=1 " part above is<br>
superfluous.<br>
<br>
<span class="Statement">PDF </span><a class="Constant" href="filetype.html#ft-pdf-plugin" name="ft-pdf-plugin">ft-pdf-plugin</a><br>
<br>
Two maps, <span class="Special"><C-]></span> and <span class="Special"><C-T></span>, are provided to simulate a tag stack for navigating<br>
the PDF. The following are treated as tags:<br>
<br>
- The byte offset after "startxref" to the xref table<br>
- The byte offset after the /Prev key in the trailer to an earlier xref table<br>
- A line of the form "0123456789 00000 n" in the xref table<br>
- An object reference like "1 0 R" anywhere in the PDF<br>
<br>
These maps can be disabled with<br>
<div class="helpExample"> :let g:no_pdf_maps = 1</div>
<br>
<br>
<span class="Statement">PYTHON </span><a class="Constant" href="filetype.html#ft-python-plugin" name="ft-python-plugin">ft-python-plugin</a> <a class="Constant" href="filetype.html#PEP8" name="PEP8">PEP8</a><br>
<br>
By default the following options are set, in accordance with PEP8:<br>
<br>
<div class="helpExample"> setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8</div>
<br>
To disable this behaviour, set the following variable in your vimrc:<br>
<div class="helpExample"> <br>
let g:python_recommended_style = 0</div>
<br>
<br>
<span class="Statement">RPM SPEC </span><a class="Constant" href="filetype.html#ft-spec-plugin" name="ft-spec-plugin">ft-spec-plugin</a><br>
<br>
Since the text for this plugin is rather long it has been put in a separate<br>
file: <a class="Identifier" href="pi_spec.html">pi_spec.txt</a>.<br>
<br>
<br>
<span class="Statement">RUST </span><a class="Constant" href="filetype.html#ft-rust" name="ft-rust">ft-rust</a><br>
<br>
Since the text for this plugin is rather long it has been put in a separate<br>
file: <a class="Identifier" href="ft_rust.html">ft_rust.txt</a>.<br>
<br>
<br>
<span class="Statement">SQL </span><a class="Constant" href="filetype.html#ft-sql" name="ft-sql">ft-sql</a><br>
<br>
Since the text for this plugin is rather long it has been put in a separate<br>
file: <a class="Identifier" href="ft_sql.html">ft_sql.txt</a>.<br>
<br>
<br>
<span class="Statement">TEX </span><a class="Constant" href="filetype.html#ft-tex-plugin" name="ft-tex-plugin">ft-tex-plugin</a> <a class="Constant" href="filetype.html#g:tex_flavor" name="g:tex_flavor">g:tex_flavor</a><br>
<br>
If the first line of a *.tex file has the form<br>
<div class="helpExample"> %&<format></div>
then this determined the file type: plaintex (for plain TeX), context (for<br>
ConTeXt), or tex (for LaTeX). Otherwise, the file is searched for keywords to<br>
choose context or tex. If no keywords are found, it defaults to plaintex.<br>
You can change the default by defining the variable g:tex_flavor to the format<br>
(not the file type) you use most. Use one of these:<br>
<div class="helpExample"> let g:tex_flavor = "plain"<br>
let g:tex_flavor = "context"<br>
let g:tex_flavor = "latex"</div>
Currently no other formats are recognized.<br>
<br>
<br>
vim:tw=78:ts=8:ft=help:norl:<br>
</div>
</article>
<footer>
<a href="#top">Return to the top</a> - <a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
<br />
<div style="text-align:right;">
Hosted by <a href="https://github.com/vim-jp/vimdoc-en">vimdoc-en project</a><br />
If you met any problem, please report it to <a href="https://github.com/vim-jp/vimdoc-en/issues">issue</a>.<br />
</div>
</footer>
<!--<script src="js/check-referrer.js" type="text/javascript"></script>-->
</body>
</html>
<!-- vim:set ts=8 sts=2 sw=2 tw=0 et: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。