代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>autocmd - 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>
/ autocmd<br />
<a name="top"></a><h1>autocmd - 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="autocmd.html" name="autocmd.txt">autocmd.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2017 Jul 14<br>
<br>
<br>
<span class="Identifier">VIM REFERENCE MANUAL by Bram Moolenaar</span><br>
<br>
<br>
Automatic commands <a class="Constant" href="autocmd.html#autocommand" name="autocommand">autocommand</a><br>
<br>
For a basic explanation, see section <a class="Identifier" href="usr_40.html#40.3">40.3</a> in the user manual.<br>
<br>
1. Introduction <a class="Identifier" href="autocmd.html#autocmd-intro">autocmd-intro</a><br>
2. Defining autocommands <a class="Identifier" href="autocmd.html#autocmd-define">autocmd-define</a><br>
3. Removing autocommands <a class="Identifier" href="autocmd.html#autocmd-remove">autocmd-remove</a><br>
4. Listing autocommands <a class="Identifier" href="autocmd.html#autocmd-list">autocmd-list</a><br>
5. Events <a class="Identifier" href="autocmd.html#autocmd-events">autocmd-events</a><br>
6. Patterns <a class="Identifier" href="autocmd.html#autocmd-patterns">autocmd-patterns</a><br>
7. Buffer-local autocommands <a class="Identifier" href="autocmd.html#autocmd-buflocal">autocmd-buflocal</a><br>
8. Groups <a class="Identifier" href="autocmd.html#autocmd-groups">autocmd-groups</a><br>
9. Executing autocommands <a class="Identifier" href="autocmd.html#autocmd-execute">autocmd-execute</a><br>
10. Using autocommands <a class="Identifier" href="autocmd.html#autocmd-use">autocmd-use</a><br>
11. Disabling autocommands <a class="Identifier" href="autocmd.html#autocmd-disable">autocmd-disable</a><br>
<br>
<span class="Special">{Vi does not have any of these commands}</span><br>
<span class="Special">{only when the </span><a class="Identifier" href="various.html#+autocmd">+autocmd</a><span class="Special"> feature has not been disabled at compile time}</span><br>
<br>
<span class="PreProc">==============================================================================</span><br>
1. Introduction <a class="Constant" href="autocmd.html#autocmd-intro" name="autocmd-intro">autocmd-intro</a><br>
<br>
You can specify commands to be executed automatically when reading or writing<br>
a file, when entering or leaving a buffer or window, and when exiting Vim.<br>
For example, you can create an autocommand to set the <a class="Type" href="options.html#'cindent'">'cindent'</a> option for<br>
files matching *.c. You can also use autocommands to implement advanced<br>
features, such as editing compressed files (see <a class="Identifier" href="autocmd.html#gzip-example">gzip-example</a>). The usual<br>
place to put autocommands is in your .vimrc or .exrc file.<br>
<br>
<a class="Constant" href="autocmd.html#E203" name="E203">E203</a> <a class="Constant" href="autocmd.html#E204" name="E204">E204</a> <a class="Constant" href="autocmd.html#E143" name="E143">E143</a> <a class="Constant" href="autocmd.html#E855" name="E855">E855</a> <a class="Constant" href="autocmd.html#E937" name="E937">E937</a><br>
WARNING: Using autocommands is very powerful, and may lead to unexpected side<br>
effects. Be careful not to destroy your text.<br>
- It's a good idea to do some testing on an expendable copy of a file first.<br>
For example: If you use autocommands to decompress a file when starting to<br>
edit it, make sure that the autocommands for compressing when writing work<br>
correctly.<br>
- Be prepared for an error halfway through (e.g., disk full). Vim will mostly<br>
be able to undo the changes to the buffer, but you may have to clean up the<br>
changes to other files by hand (e.g., compress a file that has been<br>
decompressed).<br>
- If the BufRead* events allow you to edit a compressed file, the FileRead*<br>
events should do the same (this makes recovery possible in some rare cases).<br>
It's a good idea to use the same autocommands for the File* and Buf* events<br>
when possible.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
2. Defining autocommands <a class="Constant" href="autocmd.html#autocmd-define" name="autocmd-define">autocmd-define</a><br>
<br>
<a class="Constant" href="autocmd.html#:au" name=":au">:au</a> <a class="Constant" href="autocmd.html#:autocmd" name=":autocmd">:autocmd</a><br>
:au[tocmd] <span class="Special">[group]</span> <span class="Special">{event}</span> <span class="Special">{pat}</span> <span class="Special">[nested]</span> <span class="Special">{cmd}</span><br>
Add <span class="Special">{cmd}</span> to the list of commands that Vim will<br>
execute automatically on <span class="Special">{event}</span> for a file matching<br>
<span class="Special">{pat}</span> <a class="Identifier" href="autocmd.html#autocmd-patterns">autocmd-patterns</a>.<br>
Vim always adds the <span class="Special">{cmd}</span> after existing autocommands,<br>
so that the autocommands execute in the order in which<br>
they were given. See <a class="Identifier" href="autocmd.html#autocmd-nested">autocmd-nested</a> for <span class="Special">[nested]</span>.<br>
<br>
The special pattern <span class="Special"><buffer></span> or <buffer=<span class="Special">N</span>> defines a buffer-local autocommand.<br>
See <a class="Identifier" href="autocmd.html#autocmd-buflocal">autocmd-buflocal</a>.<br>
<br>
<span class="Todo">Note</span>: The ":autocmd" command can only be followed by another command when the<br>
'|' appears before <span class="Special">{cmd}</span>. This works:<br>
<div class="helpExample"> :augroup mine | au! BufRead | augroup END</div>
But this sees "augroup" as part of the defined command:<br>
<div class="helpExample"> :augroup mine | au BufRead * set tw=70 | augroup END</div>
<br>
<span class="Todo">Note</span> that special characters (e.g., "%", "<span class="Special"><cword></span>") in the ":autocmd"<br>
arguments are not expanded when the autocommand is defined. These will be<br>
expanded when the Event is recognized, and the <span class="Special">{cmd}</span> is executed. The only<br>
exception is that "<span class="Special"><sfile></span>" is expanded when the autocmd is defined. Example:<br>
<br>
<div class="helpExample"> :au BufNewFile,BufRead *.html so <sfile>:h/html.vim</div>
<br>
Here Vim expands <span class="Special"><sfile></span> to the name of the file containing this line.<br>
<br>
<a class="Comment" href="autocmd.html#:autocmd">:autocmd</a> adds to the list of autocommands regardless of whether they are<br>
already present. When your .vimrc file is sourced twice, the autocommands<br>
will appear twice. To avoid this, define your autocommands in a group, so<br>
that you can easily clear them:<br>
<br>
<div class="helpExample"> augroup vimrc<br>
autocmd! " Remove all vimrc autocommands<br>
au BufNewFile,BufRead *.html so <sfile>:h/html.vim<br>
augroup END</div>
<br>
If you don't want to remove all autocommands, you can instead use a variable<br>
to ensure that Vim includes the autocommands only once:<br>
<br>
<div class="helpExample"> :if !exists("autocommands_loaded")<br>
: let autocommands_loaded = 1<br>
: au ...<br>
:endif</div>
<br>
When the <span class="Special">[group]</span> argument is not given, Vim uses the current group (as defined<br>
with ":augroup"); otherwise, Vim uses the group defined with <span class="Special">[group]</span>. <span class="Todo">Note</span><br>
that <span class="Special">[group]</span> must have been defined before. You cannot define a new group<br>
with ":au group ..."; use ":augroup" for that.<br>
<br>
While testing autocommands, you might find the <a class="Type" href="options.html#'verbose'">'verbose'</a> option to be useful:<br>
<div class="helpExample"> :set verbose=9</div>
This setting makes Vim echo the autocommands as it executes them.<br>
<br>
When defining an autocommand in a script, it will be able to call functions<br>
local to the script and use mappings local to the script. When the event is<br>
triggered and the command executed, it will run in the context of the script<br>
it was defined in. This matters if <a class="Identifier" href="map.html#<SID>"><SID></a> is used in a command.<br>
<br>
When executing the commands, the message from one command overwrites a<br>
previous message. This is different from when executing the commands<br>
manually. Mostly the screen will not scroll up, thus there is no hit-enter<br>
prompt. When one command outputs two messages this can happen anyway.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
3. Removing autocommands <a class="Constant" href="autocmd.html#autocmd-remove" name="autocmd-remove">autocmd-remove</a><br>
<br>
:au[tocmd]! <span class="Special">[group]</span> <span class="Special">{event}</span> <span class="Special">{pat}</span> <span class="Special">[nested]</span> <span class="Special">{cmd}</span><br>
Remove all autocommands associated with <span class="Special">{event}</span> and<br>
<span class="Special">{pat}</span>, and add the command <span class="Special">{cmd}</span>. See<br>
<a class="Identifier" href="autocmd.html#autocmd-nested">autocmd-nested</a> for <span class="Special">[nested]</span>.<br>
<br>
:au[tocmd]! <span class="Special">[group]</span> <span class="Special">{event}</span> <span class="Special">{pat}</span><br>
Remove all autocommands associated with <span class="Special">{event}</span> and<br>
<span class="Special">{pat}</span>.<br>
<br>
:au[tocmd]! <span class="Special">[group]</span> * <span class="Special">{pat}</span><br>
Remove all autocommands associated with <span class="Special">{pat}</span> for all<br>
events.<br>
<br>
:au[tocmd]! <span class="Special">[group]</span> <span class="Special">{event}</span><br>
Remove ALL autocommands for <span class="Special">{event}</span>.<br>
Warning: You should not do this without a group for<br>
<a class="Identifier" href="autocmd.html#BufRead">BufRead</a> and other common events, it can break<br>
plugins, syntax highlighting, etc.<br>
<br>
:au[tocmd]! <span class="Special">[group]</span> Remove ALL autocommands.<br>
Warning: You should normally not do this without a<br>
group, it breaks plugins, syntax highlighting, etc.<br>
<br>
When the <span class="Special">[group]</span> argument is not given, Vim uses the current group (as defined<br>
with ":augroup"); otherwise, Vim uses the group defined with <span class="Special">[group]</span>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
4. Listing autocommands <a class="Constant" href="autocmd.html#autocmd-list" name="autocmd-list">autocmd-list</a><br>
<br>
:au[tocmd] <span class="Special">[group]</span> <span class="Special">{event}</span> <span class="Special">{pat}</span><br>
Show the autocommands associated with <span class="Special">{event}</span> and<br>
<span class="Special">{pat}</span>.<br>
<br>
:au[tocmd] <span class="Special">[group]</span> * <span class="Special">{pat}</span><br>
Show the autocommands associated with <span class="Special">{pat}</span> for all<br>
events.<br>
<br>
:au[tocmd] <span class="Special">[group]</span> <span class="Special">{event}</span><br>
Show all autocommands for <span class="Special">{event}</span>.<br>
<br>
:au[tocmd] <span class="Special">[group]</span> Show all autocommands.<br>
<br>
If you provide the <span class="Special">[group]</span> argument, Vim lists only the autocommands for<br>
<span class="Special">[group]</span>; otherwise, Vim lists the autocommands for ALL groups. <span class="Todo">Note</span> that this<br>
argument behavior differs from that for defining and removing autocommands.<br>
<br>
In order to list buffer-local autocommands, use a pattern in the form <span class="Special"><buffer></span><br>
or <buffer=<span class="Special">N</span>>. See <a class="Identifier" href="autocmd.html#autocmd-buflocal">autocmd-buflocal</a>.<br>
<br>
<a class="Constant" href="autocmd.html#:autocmd-verbose" name=":autocmd-verbose">:autocmd-verbose</a><br>
When <a class="Type" href="options.html#'verbose'">'verbose'</a> is non-zero, listing an autocommand will also display where it<br>
was last defined. Example:<br>
<br>
<div class="helpExample"> :verbose autocmd BufEnter<br>
FileExplorer BufEnter<br>
* call s:LocalBrowse(expand("<amatch>"))<br>
Last set from /usr/share/vim/vim-7.0/plugin/NetrwPlugin.vim</div>
<br>
See <a class="Identifier" href="various.html#:verbose-cmd">:verbose-cmd</a> for more information.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
5. Events <a class="Constant" href="autocmd.html#autocmd-events" name="autocmd-events">autocmd-events</a> <a class="Constant" href="autocmd.html#E215" name="E215">E215</a> <a class="Constant" href="autocmd.html#E216" name="E216">E216</a><br>
<br>
You can specify a comma-separated list of event names. No white space can be<br>
used in this list. The command applies to all the events in the list.<br>
<br>
For READING FILES there are four kinds of events possible:<br>
BufNewFile starting to edit a non-existent file<br>
BufReadPre BufReadPost starting to edit an existing file<br>
FilterReadPre FilterReadPost read the temp file with filter output<br>
FileReadPre FileReadPost any other file read<br>
Vim uses only one of these four kinds when reading a file. The "Pre" and<br>
"Post" events are both triggered, before and after reading the file.<br>
<br>
<span class="Todo">Note</span> that the autocommands for the *ReadPre events and all the Filter events<br>
are not allowed to change the current buffer (you will get an error message if<br>
this happens). This is to prevent the file to be read into the wrong buffer.<br>
<br>
<span class="Todo">Note</span> that the <a class="Type" href="options.html#'modified'">'modified'</a> flag is reset AFTER executing the BufReadPost<br>
and BufNewFile autocommands. But when the <a class="Type" href="options.html#'modified'">'modified'</a> option was set by the<br>
autocommands, this doesn't happen.<br>
<br>
You can use the <a class="Type" href="options.html#'eventignore'">'eventignore'</a> option to ignore a number of events or all<br>
events.<br>
<a class="Constant" href="autocmd.html#autocommand-events" name="autocommand-events">autocommand-events</a> <a class="Constant" href="autocmd.html#{event}" name="{event}">{event}</a><br>
Vim recognizes the following events. Vim ignores the case of event names<br>
(e.g., you can use "BUFread" or "bufread" instead of "BufRead").<br>
<br>
First an overview by function with a short explanation. Then the list<br>
alphabetically with full explanations <a class="Identifier" href="autocmd.html#autocmd-events-abc">autocmd-events-abc</a>.<br>
<br>
<span class="PreProc">Name triggered by</span><br>
<br>
Reading<br>
<a class="Identifier" href="autocmd.html#BufNewFile">BufNewFile</a> starting to edit a file that doesn't exist<br>
<a class="Identifier" href="autocmd.html#BufReadPre">BufReadPre</a> starting to edit a new buffer, before reading the file<br>
<a class="Identifier" href="autocmd.html#BufRead">BufRead</a> starting to edit a new buffer, after reading the file<br>
<a class="Identifier" href="autocmd.html#BufReadPost">BufReadPost</a> starting to edit a new buffer, after reading the file<br>
<a class="Identifier" href="autocmd.html#BufReadCmd">BufReadCmd</a> before starting to edit a new buffer <a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<br>
<a class="Identifier" href="autocmd.html#FileReadPre">FileReadPre</a> before reading a file with a ":read" command<br>
<a class="Identifier" href="autocmd.html#FileReadPost">FileReadPost</a> after reading a file with a ":read" command<br>
<a class="Identifier" href="autocmd.html#FileReadCmd">FileReadCmd</a> before reading a file with a ":read" command <a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<br>
<a class="Identifier" href="autocmd.html#FilterReadPre">FilterReadPre</a> before reading a file from a filter command<br>
<a class="Identifier" href="autocmd.html#FilterReadPost">FilterReadPost</a> after reading a file from a filter command<br>
<br>
<a class="Identifier" href="autocmd.html#StdinReadPre">StdinReadPre</a> before reading from stdin into the buffer<br>
<a class="Identifier" href="autocmd.html#StdinReadPost">StdinReadPost</a> After reading from the stdin into the buffer<br>
<br>
Writing<br>
<a class="Identifier" href="autocmd.html#BufWrite">BufWrite</a> starting to write the whole buffer to a file<br>
<a class="Identifier" href="autocmd.html#BufWritePre">BufWritePre</a> starting to write the whole buffer to a file<br>
<a class="Identifier" href="autocmd.html#BufWritePost">BufWritePost</a> after writing the whole buffer to a file<br>
<a class="Identifier" href="autocmd.html#BufWriteCmd">BufWriteCmd</a> before writing the whole buffer to a file <a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<br>
<a class="Identifier" href="autocmd.html#FileWritePre">FileWritePre</a> starting to write part of a buffer to a file<br>
<a class="Identifier" href="autocmd.html#FileWritePost">FileWritePost</a> after writing part of a buffer to a file<br>
<a class="Identifier" href="autocmd.html#FileWriteCmd">FileWriteCmd</a> before writing part of a buffer to a file <a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<br>
<a class="Identifier" href="autocmd.html#FileAppendPre">FileAppendPre</a> starting to append to a file<br>
<a class="Identifier" href="autocmd.html#FileAppendPost">FileAppendPost</a> after appending to a file<br>
<a class="Identifier" href="autocmd.html#FileAppendCmd">FileAppendCmd</a> before appending to a file <a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<br>
<a class="Identifier" href="autocmd.html#FilterWritePre">FilterWritePre</a> starting to write a file for a filter command or diff<br>
<a class="Identifier" href="autocmd.html#FilterWritePost">FilterWritePost</a> after writing a file for a filter command or diff<br>
<br>
Buffers<br>
<a class="Identifier" href="autocmd.html#BufAdd">BufAdd</a> just after adding a buffer to the buffer list<br>
<a class="Identifier" href="autocmd.html#BufCreate">BufCreate</a> just after adding a buffer to the buffer list<br>
<a class="Identifier" href="autocmd.html#BufDelete">BufDelete</a> before deleting a buffer from the buffer list<br>
<a class="Identifier" href="autocmd.html#BufWipeout">BufWipeout</a> before completely deleting a buffer<br>
<br>
<a class="Identifier" href="autocmd.html#BufFilePre">BufFilePre</a> before changing the name of the current buffer<br>
<a class="Identifier" href="autocmd.html#BufFilePost">BufFilePost</a> after changing the name of the current buffer<br>
<br>
<a class="Identifier" href="autocmd.html#BufEnter">BufEnter</a> after entering a buffer<br>
<a class="Identifier" href="autocmd.html#BufLeave">BufLeave</a> before leaving to another buffer<br>
<a class="Identifier" href="autocmd.html#BufWinEnter">BufWinEnter</a> after a buffer is displayed in a window<br>
<a class="Identifier" href="autocmd.html#BufWinLeave">BufWinLeave</a> before a buffer is removed from a window<br>
<br>
<a class="Identifier" href="autocmd.html#BufUnload">BufUnload</a> before unloading a buffer<br>
<a class="Identifier" href="autocmd.html#BufHidden">BufHidden</a> just after a buffer has become hidden<br>
<a class="Identifier" href="autocmd.html#BufNew">BufNew</a> just after creating a new buffer<br>
<br>
<a class="Identifier" href="autocmd.html#SwapExists">SwapExists</a> detected an existing swap file<br>
<br>
Options<br>
<a class="Identifier" href="autocmd.html#FileType">FileType</a> when the <a class="Type" href="options.html#'filetype'">'filetype'</a> option has been set<br>
<a class="Identifier" href="autocmd.html#Syntax">Syntax</a> when the <a class="Type" href="options.html#'syntax'">'syntax'</a> option has been set<br>
<a class="Identifier" href="autocmd.html#EncodingChanged">EncodingChanged</a> after the <a class="Type" href="options.html#'encoding'">'encoding'</a> option has been changed<br>
<a class="Identifier" href="autocmd.html#TermChanged">TermChanged</a> after the value of <a class="Type" href="options.html#'term'">'term'</a> has changed<br>
<a class="Identifier" href="autocmd.html#OptionSet">OptionSet</a> after setting any option<br>
<br>
Startup and exit<br>
<a class="Identifier" href="autocmd.html#VimEnter">VimEnter</a> after doing all the startup stuff<br>
<a class="Identifier" href="autocmd.html#GUIEnter">GUIEnter</a> after starting the GUI successfully<br>
<a class="Identifier" href="autocmd.html#GUIFailed">GUIFailed</a> after starting the GUI failed<br>
<a class="Identifier" href="autocmd.html#TermResponse">TermResponse</a> after the terminal response to <a class="Identifier" href="term.html#t_RV">t_RV</a> is received<br>
<br>
<a class="Identifier" href="autocmd.html#QuitPre">QuitPre</a> when using <a class="Comment" href="editing.html#:quit">:quit</a>, before deciding whether to quit<br>
<a class="Identifier" href="autocmd.html#VimLeavePre">VimLeavePre</a> before exiting Vim, before writing the viminfo file<br>
<a class="Identifier" href="autocmd.html#VimLeave">VimLeave</a> before exiting Vim, after writing the viminfo file<br>
<br>
Various<br>
<a class="Identifier" href="autocmd.html#FileChangedShell">FileChangedShell</a> Vim notices that a file changed since editing started<br>
<a class="Identifier" href="autocmd.html#FileChangedShellPost">FileChangedShellPost</a> After handling a file changed since editing started<br>
<a class="Identifier" href="autocmd.html#FileChangedRO">FileChangedRO</a> before making the first change to a read-only file<br>
<br>
<a class="Identifier" href="autocmd.html#ShellCmdPost">ShellCmdPost</a> after executing a shell command<br>
<a class="Identifier" href="autocmd.html#ShellFilterPost">ShellFilterPost</a> after filtering with a shell command<br>
<br>
<a class="Identifier" href="autocmd.html#CmdUndefined">CmdUndefined</a> a user command is used but it isn't defined<br>
<a class="Identifier" href="autocmd.html#FuncUndefined">FuncUndefined</a> a user function is used but it isn't defined<br>
<a class="Identifier" href="autocmd.html#SpellFileMissing">SpellFileMissing</a> a spell file is used but it can't be found<br>
<a class="Identifier" href="autocmd.html#SourcePre">SourcePre</a> before sourcing a Vim script<br>
<a class="Identifier" href="autocmd.html#SourceCmd">SourceCmd</a> before sourcing a Vim script <a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<br>
<a class="Identifier" href="autocmd.html#VimResized">VimResized</a> after the Vim window size changed<br>
<a class="Identifier" href="autocmd.html#FocusGained">FocusGained</a> Vim got input focus<br>
<a class="Identifier" href="autocmd.html#FocusLost">FocusLost</a> Vim lost input focus<br>
<a class="Identifier" href="autocmd.html#CursorHold">CursorHold</a> the user doesn't press a key for a while<br>
<a class="Identifier" href="autocmd.html#CursorHoldI">CursorHoldI</a> the user doesn't press a key for a while in Insert mode<br>
<a class="Identifier" href="autocmd.html#CursorMoved">CursorMoved</a> the cursor was moved in Normal mode<br>
<a class="Identifier" href="autocmd.html#CursorMovedI">CursorMovedI</a> the cursor was moved in Insert mode<br>
<br>
<a class="Identifier" href="autocmd.html#WinNew">WinNew</a> after creating a new window<br>
<a class="Identifier" href="autocmd.html#TabNew">TabNew</a> after creating a new tab page<br>
<a class="Identifier" href="autocmd.html#TabClosed">TabClosed</a> after closing a tab page<br>
<a class="Identifier" href="autocmd.html#WinEnter">WinEnter</a> after entering another window<br>
<a class="Identifier" href="autocmd.html#WinLeave">WinLeave</a> before leaving a window<br>
<a class="Identifier" href="autocmd.html#TabEnter">TabEnter</a> after entering another tab page<br>
<a class="Identifier" href="autocmd.html#TabLeave">TabLeave</a> before leaving a tab page<br>
<a class="Identifier" href="autocmd.html#CmdwinEnter">CmdwinEnter</a> after entering the command-line window<br>
<a class="Identifier" href="autocmd.html#CmdwinLeave">CmdwinLeave</a> before leaving the command-line window<br>
<br>
<a class="Identifier" href="autocmd.html#InsertEnter">InsertEnter</a> starting Insert mode<br>
<a class="Identifier" href="autocmd.html#InsertChange">InsertChange</a> when typing <span class="Special"><Insert></span> while in Insert or Replace mode<br>
<a class="Identifier" href="autocmd.html#InsertLeave">InsertLeave</a> when leaving Insert mode<br>
<a class="Identifier" href="autocmd.html#InsertCharPre">InsertCharPre</a> when a character was typed in Insert mode, before<br>
inserting it<br>
<br>
<a class="Identifier" href="autocmd.html#TextChanged">TextChanged</a> after a change was made to the text in Normal mode<br>
<a class="Identifier" href="autocmd.html#TextChangedI">TextChangedI</a> after a change was made to the text in Insert mode<br>
<br>
<a class="Identifier" href="autocmd.html#ColorScheme">ColorScheme</a> after loading a color scheme<br>
<br>
<a class="Identifier" href="autocmd.html#RemoteReply">RemoteReply</a> a reply from a server Vim was received<br>
<br>
<a class="Identifier" href="autocmd.html#QuickFixCmdPre">QuickFixCmdPre</a> before a quickfix command is run<br>
<a class="Identifier" href="autocmd.html#QuickFixCmdPost">QuickFixCmdPost</a> after a quickfix command is run<br>
<br>
<a class="Identifier" href="autocmd.html#SessionLoadPost">SessionLoadPost</a> after loading a session file<br>
<br>
<a class="Identifier" href="autocmd.html#MenuPopup">MenuPopup</a> just before showing the popup menu<br>
<a class="Identifier" href="autocmd.html#CompleteDone">CompleteDone</a> after Insert mode completion is done<br>
<br>
<a class="Identifier" href="autocmd.html#User">User</a> to be used in combination with ":doautocmd"<br>
<br>
<br>
The alphabetical list of autocommand events: <a class="Constant" href="autocmd.html#autocmd-events-abc" name="autocmd-events-abc">autocmd-events-abc</a><br>
<br>
<a class="Constant" href="autocmd.html#BufCreate" name="BufCreate">BufCreate</a> <a class="Constant" href="autocmd.html#BufAdd" name="BufAdd">BufAdd</a><br>
BufAdd or BufCreate Just after creating a new buffer which is<br>
added to the buffer list, or adding a buffer<br>
to the buffer list.<br>
Also used just after a buffer in the buffer<br>
list has been renamed.<br>
The BufCreate event is for historic reasons.<br>
<span class="Todo">NOTE</span>: When this autocommand is executed, the<br>
current buffer "%" may be different from the<br>
buffer being created "<span class="Special"><afile></span>".<br>
<a class="Constant" href="autocmd.html#BufDelete" name="BufDelete">BufDelete</a><br>
BufDelete Before deleting a buffer from the buffer list.<br>
The BufUnload may be called first (if the<br>
buffer was loaded).<br>
Also used just before a buffer in the buffer<br>
list is renamed.<br>
<span class="Todo">NOTE</span>: When this autocommand is executed, the<br>
current buffer "%" may be different from the<br>
buffer being deleted "<span class="Special"><afile></span>" and "<span class="Special"><abuf></span>".<br>
Don't change to another buffer, it will cause<br>
problems.<br>
<a class="Constant" href="autocmd.html#BufEnter" name="BufEnter">BufEnter</a><br>
BufEnter After entering a buffer. Useful for setting<br>
options for a file type. Also executed when<br>
starting to edit a buffer, after the<br>
BufReadPost autocommands.<br>
<a class="Constant" href="autocmd.html#BufFilePost" name="BufFilePost">BufFilePost</a><br>
BufFilePost After changing the name of the current buffer<br>
with the ":file" or ":saveas" command.<br>
<a class="Constant" href="autocmd.html#BufFilePre" name="BufFilePre">BufFilePre</a><br>
BufFilePre Before changing the name of the current buffer<br>
with the ":file" or ":saveas" command.<br>
<a class="Constant" href="autocmd.html#BufHidden" name="BufHidden">BufHidden</a><br>
BufHidden Just after a buffer has become hidden. That<br>
is, when there are no longer windows that show<br>
the buffer, but the buffer is not unloaded or<br>
deleted. Not used for ":qa" or ":q" when<br>
exiting Vim.<br>
<span class="Todo">NOTE</span>: When this autocommand is executed, the<br>
current buffer "%" may be different from the<br>
buffer being unloaded "<span class="Special"><afile></span>".<br>
<a class="Constant" href="autocmd.html#BufLeave" name="BufLeave">BufLeave</a><br>
BufLeave Before leaving to another buffer. Also when<br>
leaving or closing the current window and the<br>
new current window is not for the same buffer.<br>
Not used for ":qa" or ":q" when exiting Vim.<br>
<a class="Constant" href="autocmd.html#BufNew" name="BufNew">BufNew</a><br>
BufNew Just after creating a new buffer. Also used<br>
just after a buffer has been renamed. When<br>
the buffer is added to the buffer list BufAdd<br>
will be triggered too.<br>
<span class="Todo">NOTE</span>: When this autocommand is executed, the<br>
current buffer "%" may be different from the<br>
buffer being created "<span class="Special"><afile></span>".<br>
<a class="Constant" href="autocmd.html#BufNewFile" name="BufNewFile">BufNewFile</a><br>
BufNewFile When starting to edit a file that doesn't<br>
exist. Can be used to read in a skeleton<br>
file.<br>
<a class="Constant" href="autocmd.html#BufRead" name="BufRead">BufRead</a> <a class="Constant" href="autocmd.html#BufReadPost" name="BufReadPost">BufReadPost</a><br>
BufRead or BufReadPost When starting to edit a new buffer, after<br>
reading the file into the buffer, before<br>
executing the modelines. See <a class="Identifier" href="autocmd.html#BufWinEnter">BufWinEnter</a><br>
for when you need to do something after<br>
processing the modelines.<br>
This does NOT work for ":r file". Not used<br>
when the file doesn't exist. Also used after<br>
successfully recovering a file.<br>
Also triggered for the filetypedetect group<br>
when executing ":filetype detect" and when<br>
writing an unnamed buffer in a way that the<br>
buffer gets a name.<br>
<a class="Constant" href="autocmd.html#BufReadCmd" name="BufReadCmd">BufReadCmd</a><br>
BufReadCmd Before starting to edit a new buffer. Should<br>
read the file into the buffer. <a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<a class="Constant" href="autocmd.html#BufReadPre" name="BufReadPre">BufReadPre</a> <a class="Constant" href="autocmd.html#E200" name="E200">E200</a> <a class="Constant" href="autocmd.html#E201" name="E201">E201</a><br>
BufReadPre When starting to edit a new buffer, before<br>
reading the file into the buffer. Not used<br>
if the file doesn't exist.<br>
<a class="Constant" href="autocmd.html#BufUnload" name="BufUnload">BufUnload</a><br>
BufUnload Before unloading a buffer. This is when the<br>
text in the buffer is going to be freed. This<br>
may be after a BufWritePost and before a<br>
BufDelete. Also used for all buffers that are<br>
loaded when Vim is going to exit.<br>
<span class="Todo">NOTE</span>: When this autocommand is executed, the<br>
current buffer "%" may be different from the<br>
buffer being unloaded "<span class="Special"><afile></span>".<br>
Don't change to another buffer or window, it<br>
will cause problems!<br>
When exiting and v:dying is 2 or more this<br>
event is not triggered.<br>
<a class="Constant" href="autocmd.html#BufWinEnter" name="BufWinEnter">BufWinEnter</a><br>
BufWinEnter After a buffer is displayed in a window. This<br>
can be when the buffer is loaded (after<br>
processing the modelines) or when a hidden<br>
buffer is displayed in a window (and is no<br>
longer hidden).<br>
Does not happen for <a class="Identifier" href="windows.html#:split">:split</a> without<br>
arguments, since you keep editing the same<br>
buffer, or ":split" with a file that's already<br>
open in a window, because it re-uses an<br>
existing buffer. But it does happen for a<br>
":split" with the name of the current buffer,<br>
since it reloads that buffer.<br>
<a class="Constant" href="autocmd.html#BufWinLeave" name="BufWinLeave">BufWinLeave</a><br>
BufWinLeave Before a buffer is removed from a window.<br>
Not when it's still visible in another window.<br>
Also triggered when exiting. It's triggered<br>
before BufUnload or BufHidden.<br>
<span class="Todo">NOTE</span>: When this autocommand is executed, the<br>
current buffer "%" may be different from the<br>
buffer being unloaded "<span class="Special"><afile></span>".<br>
When exiting and v:dying is 2 or more this<br>
event is not triggered.<br>
<a class="Constant" href="autocmd.html#BufWipeout" name="BufWipeout">BufWipeout</a><br>
BufWipeout Before completely deleting a buffer. The<br>
BufUnload and BufDelete events may be called<br>
first (if the buffer was loaded and was in the<br>
buffer list). Also used just before a buffer<br>
is renamed (also when it's not in the buffer<br>
list).<br>
<span class="Todo">NOTE</span>: When this autocommand is executed, the<br>
current buffer "%" may be different from the<br>
buffer being deleted "<span class="Special"><afile></span>".<br>
Don't change to another buffer, it will cause<br>
problems.<br>
<a class="Constant" href="autocmd.html#BufWrite" name="BufWrite">BufWrite</a> <a class="Constant" href="autocmd.html#BufWritePre" name="BufWritePre">BufWritePre</a><br>
BufWrite or BufWritePre Before writing the whole buffer to a file.<br>
<a class="Constant" href="autocmd.html#BufWriteCmd" name="BufWriteCmd">BufWriteCmd</a><br>
BufWriteCmd Before writing the whole buffer to a file.<br>
Should do the writing of the file and reset<br>
<a class="Type" href="options.html#'modified'">'modified'</a> if successful, unless '+' is in<br>
<a class="Type" href="options.html#'cpo'">'cpo'</a> and writing to another file <a class="Identifier" href="options.html#cpo-+">cpo-+</a>.<br>
The buffer contents should not be changed.<br>
When the command resets <a class="Type" href="options.html#'modified'">'modified'</a> the undo<br>
information is adjusted to mark older undo<br>
states as <a class="Type" href="options.html#'modified'">'modified'</a>, like <a class="Identifier" href="editing.html#:write">:write</a> does.<br>
<a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<a class="Constant" href="autocmd.html#BufWritePost" name="BufWritePost">BufWritePost</a><br>
BufWritePost After writing the whole buffer to a file<br>
(should undo the commands for BufWritePre).<br>
<a class="Constant" href="autocmd.html#CmdUndefined" name="CmdUndefined">CmdUndefined</a><br>
CmdUndefined When a user command is used but it isn't<br>
defined. Useful for defining a command only<br>
when it's used. The pattern is matched<br>
against the command name. Both <span class="Special"><amatch></span> and<br>
<span class="Special"><afile></span> are set to the name of the command.<br>
<span class="Todo">NOTE</span>: Autocompletion won't work until the<br>
command is defined. An alternative is to<br>
always define the user command and have it<br>
invoke an autoloaded function. See <a class="Identifier" href="eval.html#autoload">autoload</a>.<br>
<a class="Constant" href="autocmd.html#CmdwinEnter" name="CmdwinEnter">CmdwinEnter</a><br>
CmdwinEnter After entering the command-line window.<br>
Useful for setting options specifically for<br>
this special type of window. This is<br>
triggered _instead_ of BufEnter and WinEnter.<br>
<span class="Special"><afile></span> is set to a single character,<br>
indicating the type of command-line.<br>
<a class="Identifier" href="cmdline.html#cmdwin-char">cmdwin-char</a><br>
<a class="Constant" href="autocmd.html#CmdwinLeave" name="CmdwinLeave">CmdwinLeave</a><br>
CmdwinLeave Before leaving the command-line window.<br>
Useful to clean up any global setting done<br>
with CmdwinEnter. This is triggered _instead_<br>
of BufLeave and WinLeave.<br>
<span class="Special"><afile></span> is set to a single character,<br>
indicating the type of command-line.<br>
<a class="Identifier" href="cmdline.html#cmdwin-char">cmdwin-char</a><br>
<a class="Constant" href="autocmd.html#ColorScheme" name="ColorScheme">ColorScheme</a><br>
ColorScheme After loading a color scheme. <a class="Identifier" href="syntax.html#:colorscheme">:colorscheme</a><br>
The pattern is matched against the<br>
colorscheme name. <span class="Special"><afile></span> can be used for the<br>
name of the actual file where this option was<br>
set, and <span class="Special"><amatch></span> for the new colorscheme<br>
name.<br>
<br>
<br>
<a class="Constant" href="autocmd.html#CompleteDone" name="CompleteDone">CompleteDone</a><br>
CompleteDone After Insert mode completion is done. Either<br>
when something was completed or abandoning<br>
completion. <a class="Identifier" href="insert.html#ins-completion">ins-completion</a><br>
The <a class="Identifier" href="eval.html#v:completed_item">v:completed_item</a> variable contains<br>
information about the completed item.<br>
<br>
<a class="Constant" href="autocmd.html#CursorHold" name="CursorHold">CursorHold</a><br>
CursorHold When the user doesn't press a key for the time<br>
specified with <a class="Type" href="options.html#'updatetime'">'updatetime'</a>. Not re-triggered<br>
until the user has pressed a key (i.e. doesn't<br>
fire every <a class="Type" href="options.html#'updatetime'">'updatetime'</a> ms if you leave Vim to<br>
make some coffee. :) See <a class="Identifier" href="windows.html#CursorHold-example">CursorHold-example</a><br>
for previewing tags.<br>
This event is only triggered in Normal mode.<br>
It is not triggered when waiting for a command<br>
argument to be typed, or a movement after an<br>
operator.<br>
While recording the CursorHold event is not<br>
triggered. <a class="Identifier" href="repeat.html#q">q</a><br>
<a class="Constant" href="autocmd.html#<CursorHold>" name="<CursorHold>"><CursorHold></a><br>
Internally the autocommand is triggered by the<br>
<span class="Special"><CursorHold></span> key. In an expression mapping<br>
<a class="Identifier" href="eval.html#getchar()">getchar()</a> may see this character.<br>
<br>
<span class="Todo">Note</span>: Interactive commands cannot be used for<br>
this event. There is no hit-enter prompt,<br>
the screen is updated directly (when needed).<br>
<span class="Todo">Note</span>: In the future there will probably be<br>
another option to set the time.<br>
Hint: to force an update of the status lines<br>
use:<br>
<div class="helpExample"> :let &ro = &ro</div>
<span class="Special">{only on Amiga, Unix, Win32, MSDOS and all GUI</span><br>
<span class="Special">versions}</span><br>
<a class="Constant" href="autocmd.html#CursorHoldI" name="CursorHoldI">CursorHoldI</a><br>
CursorHoldI Just like CursorHold, but in Insert mode.<br>
Not triggered when waiting for another key,<br>
e.g. after <span class="Special">CTRL-V</span>, and not when in <span class="Special">CTRL-X</span> mode<br>
<a class="Identifier" href="insert.html#insert_expand">insert_expand</a>.<br>
<br>
<a class="Constant" href="autocmd.html#CursorMoved" name="CursorMoved">CursorMoved</a><br>
CursorMoved After the cursor was moved in Normal or Visual<br>
mode. Also when the text of the cursor line<br>
has been changed, e.g., with "x", "rx" or "p".<br>
Not triggered when there is typeahead or when<br>
an operator is pending.<br>
For an example see <a class="Identifier" href="tips.html#match-parens">match-parens</a>.<br>
Careful: This is triggered very often, don't<br>
do anything that the user does not expect or<br>
that is slow.<br>
<a class="Constant" href="autocmd.html#CursorMovedI" name="CursorMovedI">CursorMovedI</a><br>
CursorMovedI After the cursor was moved in Insert mode.<br>
Not triggered when the popup menu is visible.<br>
Otherwise the same as CursorMoved.<br>
<a class="Constant" href="autocmd.html#EncodingChanged" name="EncodingChanged">EncodingChanged</a><br>
EncodingChanged Fires off after the <a class="Type" href="options.html#'encoding'">'encoding'</a> option has been<br>
changed. Useful to set up fonts, for example.<br>
<a class="Constant" href="autocmd.html#FileAppendCmd" name="FileAppendCmd">FileAppendCmd</a><br>
FileAppendCmd Before appending to a file. Should do the<br>
appending to the file. Use the '[ and ']<br>
marks for the range of lines.<a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<a class="Constant" href="autocmd.html#FileAppendPost" name="FileAppendPost">FileAppendPost</a><br>
FileAppendPost After appending to a file.<br>
<a class="Constant" href="autocmd.html#FileAppendPre" name="FileAppendPre">FileAppendPre</a><br>
FileAppendPre Before appending to a file. Use the '[ and ']<br>
marks for the range of lines.<br>
<a class="Constant" href="autocmd.html#FileChangedRO" name="FileChangedRO">FileChangedRO</a><br>
FileChangedRO Before making the first change to a read-only<br>
file. Can be used to check-out the file from<br>
a source control system. Not triggered when<br>
the change was caused by an autocommand.<br>
This event is triggered when making the first<br>
change in a buffer or the first change after<br>
<a class="Type" href="options.html#'readonly'">'readonly'</a> was set, just before the change is<br>
applied to the text.<br>
WARNING: If the autocommand moves the cursor<br>
the effect of the change is undefined.<br>
<a class="Constant" href="autocmd.html#E788" name="E788">E788</a><br>
It is not allowed to change to another buffer<br>
here. You can reload the buffer but not edit<br>
another one.<br>
<a class="Constant" href="autocmd.html#E881" name="E881">E881</a><br>
If the number of lines changes saving for undo<br>
may fail and the change will be aborted.<br>
<a class="Constant" href="autocmd.html#FileChangedShell" name="FileChangedShell">FileChangedShell</a><br>
FileChangedShell When Vim notices that the modification time of<br>
a file has changed since editing started.<br>
Also when the file attributes of the file<br>
change or when the size of the file changes.<br>
<a class="Identifier" href="editing.html#timestamp">timestamp</a><br>
Mostly triggered after executing a shell<br>
command, but also with a <a class="Identifier" href="editing.html#:checktime">:checktime</a> command<br>
or when gvim regains input focus.<br>
This autocommand is triggered for each changed<br>
file. It is not used when <a class="Type" href="options.html#'autoread'">'autoread'</a> is set<br>
and the buffer was not changed. If a<br>
FileChangedShell autocommand is present the<br>
warning message and prompt is not given.<br>
The <a class="Identifier" href="eval.html#v:fcs_reason">v:fcs_reason</a> variable is set to indicate<br>
what happened and <a class="Identifier" href="eval.html#v:fcs_choice">v:fcs_choice</a> can be used<br>
to tell Vim what to do next.<br>
<span class="Todo">NOTE</span>: When this autocommand is executed, the<br>
current buffer "%" may be different from the<br>
buffer that was changed, which is in "<span class="Special"><afile></span>".<br>
<span class="Todo">NOTE</span>: The commands must not change the current<br>
buffer, jump to another buffer or delete a<br>
buffer. <a class="Constant" href="autocmd.html#E246" name="E246">E246</a> <a class="Constant" href="autocmd.html#E811" name="E811">E811</a><br>
<span class="Todo">NOTE</span>: This event never nests, to avoid an<br>
endless loop. This means that while executing<br>
commands for the FileChangedShell event no<br>
other FileChangedShell event will be<br>
triggered.<br>
<a class="Constant" href="autocmd.html#FileChangedShellPost" name="FileChangedShellPost">FileChangedShellPost</a><br>
FileChangedShellPost After handling a file that was changed outside<br>
of Vim. Can be used to update the statusline.<br>
<a class="Constant" href="autocmd.html#FileEncoding" name="FileEncoding">FileEncoding</a><br>
FileEncoding Obsolete. It still works and is equivalent<br>
to <a class="Identifier" href="autocmd.html#EncodingChanged">EncodingChanged</a>.<br>
<a class="Constant" href="autocmd.html#FileReadCmd" name="FileReadCmd">FileReadCmd</a><br>
FileReadCmd Before reading a file with a ":read" command.<br>
Should do the reading of the file. <a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<a class="Constant" href="autocmd.html#FileReadPost" name="FileReadPost">FileReadPost</a><br>
FileReadPost After reading a file with a ":read" command.<br>
<span class="Todo">Note</span> that Vim sets the '[ and '] marks to the<br>
first and last line of the read. This can be<br>
used to operate on the lines just read.<br>
<a class="Constant" href="autocmd.html#FileReadPre" name="FileReadPre">FileReadPre</a><br>
FileReadPre Before reading a file with a ":read" command.<br>
<a class="Constant" href="autocmd.html#FileType" name="FileType">FileType</a><br>
FileType When the <a class="Type" href="options.html#'filetype'">'filetype'</a> option has been set. The<br>
pattern is matched against the filetype.<br>
<span class="Special"><afile></span> can be used for the name of the file<br>
where this option was set, and <span class="Special"><amatch></span> for<br>
the new value of <a class="Type" href="options.html#'filetype'">'filetype'</a>. Navigating to<br>
another window or buffer is not allowed.<br>
See <a class="Identifier" href="filetype.html#filetypes">filetypes</a>.<br>
<a class="Constant" href="autocmd.html#FileWriteCmd" name="FileWriteCmd">FileWriteCmd</a><br>
FileWriteCmd Before writing to a file, when not writing the<br>
whole buffer. Should do the writing to the<br>
file. Should not change the buffer. Use the<br>
'[ and '] marks for the range of lines.<br>
<a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<a class="Constant" href="autocmd.html#FileWritePost" name="FileWritePost">FileWritePost</a><br>
FileWritePost After writing to a file, when not writing the<br>
whole buffer.<br>
<a class="Constant" href="autocmd.html#FileWritePre" name="FileWritePre">FileWritePre</a><br>
FileWritePre Before writing to a file, when not writing the<br>
whole buffer. Use the '[ and '] marks for the<br>
range of lines.<br>
<a class="Constant" href="autocmd.html#FilterReadPost" name="FilterReadPost">FilterReadPost</a><br>
FilterReadPost After reading a file from a filter command.<br>
Vim checks the pattern against the name of<br>
the current buffer as with FilterReadPre.<br>
Not triggered when <a class="Type" href="options.html#'shelltemp'">'shelltemp'</a> is off.<br>
<a class="Constant" href="autocmd.html#FilterReadPre" name="FilterReadPre">FilterReadPre</a> <a class="Constant" href="autocmd.html#E135" name="E135">E135</a><br>
FilterReadPre Before reading a file from a filter command.<br>
Vim checks the pattern against the name of<br>
the current buffer, not the name of the<br>
temporary file that is the output of the<br>
filter command.<br>
Not triggered when <a class="Type" href="options.html#'shelltemp'">'shelltemp'</a> is off.<br>
<a class="Constant" href="autocmd.html#FilterWritePost" name="FilterWritePost">FilterWritePost</a><br>
FilterWritePost After writing a file for a filter command or<br>
making a diff.<br>
Vim checks the pattern against the name of<br>
the current buffer as with FilterWritePre.<br>
Not triggered when <a class="Type" href="options.html#'shelltemp'">'shelltemp'</a> is off.<br>
<a class="Constant" href="autocmd.html#FilterWritePre" name="FilterWritePre">FilterWritePre</a><br>
FilterWritePre Before writing a file for a filter command or<br>
making a diff.<br>
Vim checks the pattern against the name of<br>
the current buffer, not the name of the<br>
temporary file that is the output of the<br>
filter command.<br>
Not triggered when <a class="Type" href="options.html#'shelltemp'">'shelltemp'</a> is off.<br>
<a class="Constant" href="autocmd.html#FocusGained" name="FocusGained">FocusGained</a><br>
FocusGained When Vim got input focus. Only for the GUI<br>
version and a few console versions where this<br>
can be detected.<br>
<a class="Constant" href="autocmd.html#FocusLost" name="FocusLost">FocusLost</a><br>
FocusLost When Vim lost input focus. Only for the GUI<br>
version and a few console versions where this<br>
can be detected. May also happen when a<br>
dialog pops up.<br>
<a class="Constant" href="autocmd.html#FuncUndefined" name="FuncUndefined">FuncUndefined</a><br>
FuncUndefined When a user function is used but it isn't<br>
defined. Useful for defining a function only<br>
when it's used. The pattern is matched<br>
against the function name. Both <span class="Special"><amatch></span> and<br>
<span class="Special"><afile></span> are set to the name of the function.<br>
<span class="Todo">NOTE</span>: When writing Vim scripts a better<br>
alternative is to use an autoloaded function.<br>
See <a class="Identifier" href="eval.html#autoload-functions">autoload-functions</a>.<br>
<a class="Constant" href="autocmd.html#GUIEnter" name="GUIEnter">GUIEnter</a><br>
GUIEnter After starting the GUI successfully, and after<br>
opening the window. It is triggered before<br>
VimEnter when using gvim. Can be used to<br>
position the window from a .gvimrc file:<br>
<div class="helpExample"> :autocmd GUIEnter * winpos 100 50</div>
<a class="Constant" href="autocmd.html#GUIFailed" name="GUIFailed">GUIFailed</a><br>
GUIFailed After starting the GUI failed. Vim may<br>
continue to run in the terminal, if possible<br>
(only on Unix and alikes, when connecting the<br>
X server fails). You may want to quit Vim:<br>
<div class="helpExample"> :autocmd GUIFailed * qall</div>
<a class="Constant" href="autocmd.html#InsertChange" name="InsertChange">InsertChange</a><br>
InsertChange When typing <span class="Special"><Insert></span> while in Insert or<br>
Replace mode. The <a class="Identifier" href="eval.html#v:insertmode">v:insertmode</a> variable<br>
indicates the new mode.<br>
Be careful not to move the cursor or do<br>
anything else that the user does not expect.<br>
<a class="Constant" href="autocmd.html#InsertCharPre" name="InsertCharPre">InsertCharPre</a><br>
InsertCharPre When a character is typed in Insert mode,<br>
before inserting the char.<br>
The <a class="Identifier" href="eval.html#v:char">v:char</a> variable indicates the char typed<br>
and can be changed during the event to insert<br>
a different character. When <a class="Identifier" href="eval.html#v:char">v:char</a> is set<br>
to more than one character this text is<br>
inserted literally.<br>
It is not allowed to change the text <a class="Identifier" href="eval.html#textlock">textlock</a>.<br>
The event is not triggered when <a class="Type" href="options.html#'paste'">'paste'</a> is<br>
set.<br>
<a class="Constant" href="autocmd.html#InsertEnter" name="InsertEnter">InsertEnter</a><br>
InsertEnter Just before starting Insert mode. Also for<br>
Replace mode and Virtual Replace mode. The<br>
<a class="Identifier" href="eval.html#v:insertmode">v:insertmode</a> variable indicates the mode.<br>
Be careful not to do anything else that the<br>
user does not expect.<br>
The cursor is restored afterwards. If you do<br>
not want that set <a class="Identifier" href="eval.html#v:char">v:char</a> to a non-empty<br>
string.<br>
<a class="Constant" href="autocmd.html#InsertLeave" name="InsertLeave">InsertLeave</a><br>
InsertLeave When leaving Insert mode. Also when using<br>
<span class="Special">CTRL-O</span> <a class="Identifier" href="insert.html#i_CTRL-O">i_CTRL-O</a>. But not for <a class="Identifier" href="insert.html#i_CTRL-C">i_CTRL-C</a>.<br>
<a class="Constant" href="autocmd.html#MenuPopup" name="MenuPopup">MenuPopup</a><br>
MenuPopup Just before showing the popup menu (under the<br>
right mouse button). Useful for adjusting the<br>
menu for what is under the cursor or mouse<br>
pointer.<br>
The pattern is matched against a single<br>
character representing the mode:<br>
n Normal<br>
v Visual<br>
o Operator-pending<br>
i Insert<br>
c Command line<br>
<a class="Constant" href="autocmd.html#OptionSet" name="OptionSet">OptionSet</a><br>
OptionSet After setting an option. The pattern is<br>
matched against the long option name.<br>
The <a class="Identifier" href="eval.html#v:option_old">v:option_old</a> variable indicates the<br>
old option value, <a class="Identifier" href="eval.html#v:option_new">v:option_new</a> variable<br>
indicates the newly set value, the<br>
<a class="Identifier" href="eval.html#v:option_type">v:option_type</a> variable indicates whether<br>
it's global or local scoped and <a class="Identifier" href="cmdline.html#<amatch>"><amatch></a><br>
indicates what option has been set.<br>
<br>
Is not triggered on startup and for the <a class="Type" href="options.html#'key'">'key'</a><br>
option for obvious reasons.<br>
<br>
Usage example: Check for the existence of the<br>
directory in the <a class="Type" href="options.html#'backupdir'">'backupdir'</a> and <a class="Type" href="options.html#'undodir'">'undodir'</a><br>
options, create the directory if it doesn't<br>
exist yet.<br>
<br>
<span class="Todo">Note</span>: It's a bad idea to reset an option<br>
during this autocommand, this may break a<br>
plugin. You can always use <a class="Comment" href="autocmd.html#:noa">:noa</a> to prevent<br>
triggering this autocommand.<br>
<br>
<a class="Constant" href="autocmd.html#QuickFixCmdPre" name="QuickFixCmdPre">QuickFixCmdPre</a><br>
QuickFixCmdPre Before a quickfix command is run (<a class="Identifier" href="quickfix.html#:make">:make</a>,<br>
<a class="Identifier" href="quickfix.html#:lmake">:lmake</a>, <a class="Identifier" href="quickfix.html#:grep">:grep</a>, <a class="Identifier" href="quickfix.html#:lgrep">:lgrep</a>, <a class="Identifier" href="quickfix.html#:grepadd">:grepadd</a>,<br>
<a class="Identifier" href="quickfix.html#:lgrepadd">:lgrepadd</a>, <a class="Identifier" href="quickfix.html#:vimgrep">:vimgrep</a>, <a class="Identifier" href="quickfix.html#:lvimgrep">:lvimgrep</a>,<br>
<a class="Identifier" href="quickfix.html#:vimgrepadd">:vimgrepadd</a>, <a class="Identifier" href="quickfix.html#:lvimgrepadd">:lvimgrepadd</a>, <a class="Identifier" href="if_cscop.html#:cscope">:cscope</a>,<br>
<a class="Identifier" href="quickfix.html#:cfile">:cfile</a>, <a class="Identifier" href="quickfix.html#:cgetfile">:cgetfile</a>, <a class="Identifier" href="quickfix.html#:caddfile">:caddfile</a>, <a class="Identifier" href="quickfix.html#:lfile">:lfile</a>,<br>
<a class="Identifier" href="quickfix.html#:lgetfile">:lgetfile</a>, <a class="Identifier" href="quickfix.html#:laddfile">:laddfile</a>, <a class="Identifier" href="helphelp.html#:helpgrep">:helpgrep</a>,<br>
<a class="Identifier" href="helphelp.html#:lhelpgrep">:lhelpgrep</a>, <a class="Identifier" href="quickfix.html#:cexpr">:cexpr</a>, <a class="Identifier" href="quickfix.html#:cgetexpr">:cgetexpr</a>,<br>
<a class="Identifier" href="quickfix.html#:caddexpr">:caddexpr</a>, <a class="Identifier" href="quickfix.html#:cbuffer">:cbuffer</a>, <a class="Identifier" href="quickfix.html#:cgetbuffer">:cgetbuffer</a>,<br>
<a class="Identifier" href="quickfix.html#:caddbuffer">:caddbuffer</a>).<br>
The pattern is matched against the command<br>
being run. When <a class="Identifier" href="quickfix.html#:grep">:grep</a> is used but <a class="Type" href="options.html#'grepprg'">'grepprg'</a><br>
is set to "internal" it still matches "grep".<br>
This command cannot be used to set the<br>
<a class="Type" href="options.html#'makeprg'">'makeprg'</a> and <a class="Type" href="options.html#'grepprg'">'grepprg'</a> variables.<br>
If this command causes an error, the quickfix<br>
command is not executed.<br>
<a class="Constant" href="autocmd.html#QuickFixCmdPost" name="QuickFixCmdPost">QuickFixCmdPost</a><br>
QuickFixCmdPost Like QuickFixCmdPre, but after a quickfix<br>
command is run, before jumping to the first<br>
location. For <a class="Identifier" href="quickfix.html#:cfile">:cfile</a> and <a class="Identifier" href="quickfix.html#:lfile">:lfile</a> commands<br>
it is run after error file is read and before<br>
moving to the first error.<br>
See <a class="Identifier" href="quickfix.html#QuickFixCmdPost-example">QuickFixCmdPost-example</a>.<br>
<a class="Constant" href="autocmd.html#QuitPre" name="QuitPre">QuitPre</a><br>
QuitPre When using <a class="Comment" href="editing.html#:quit">:quit</a>, <a class="Comment" href="editing.html#:wq">:wq</a> or <a class="Comment" href="editing.html#:qall">:qall</a>, before<br>
deciding whether it closes the current window<br>
or quits Vim. Can be used to close any<br>
non-essential window if the current window is<br>
the last ordinary window.<br>
<a class="Constant" href="autocmd.html#RemoteReply" name="RemoteReply">RemoteReply</a><br>
RemoteReply When a reply from a Vim that functions as<br>
server was received <a class="Identifier" href="eval.html#server2client()">server2client()</a>. The<br>
pattern is matched against the <span class="Special">{serverid}</span>.<br>
<span class="Special"><amatch></span> is equal to the <span class="Special">{serverid}</span> from which<br>
the reply was sent, and <span class="Special"><afile></span> is the actual<br>
reply string.<br>
<span class="Todo">Note</span> that even if an autocommand is defined,<br>
the reply should be read with <a class="Identifier" href="eval.html#remote_read()">remote_read()</a><br>
to consume it.<br>
<a class="Constant" href="autocmd.html#SessionLoadPost" name="SessionLoadPost">SessionLoadPost</a><br>
SessionLoadPost After loading the session file created using<br>
the <a class="Identifier" href="starting.html#:mksession">:mksession</a> command.<br>
<a class="Constant" href="autocmd.html#ShellCmdPost" name="ShellCmdPost">ShellCmdPost</a><br>
ShellCmdPost After executing a shell command with <a class="Identifier" href="various.html#:!cmd">:!cmd</a>,<br>
<a class="Identifier" href="various.html#:shell">:shell</a>, <a class="Identifier" href="quickfix.html#:make">:make</a> and <a class="Identifier" href="quickfix.html#:grep">:grep</a>. Can be used to<br>
check for any changed files.<br>
<a class="Constant" href="autocmd.html#ShellFilterPost" name="ShellFilterPost">ShellFilterPost</a><br>
ShellFilterPost After executing a shell command with<br>
":<span class="Special">{range}</span>!cmd", ":w !cmd" or ":r !cmd".<br>
Can be used to check for any changed files.<br>
<a class="Constant" href="autocmd.html#SourcePre" name="SourcePre">SourcePre</a><br>
SourcePre Before sourcing a Vim script. <a class="Identifier" href="repeat.html#:source">:source</a><br>
<span class="Special"><afile></span> is the name of the file being sourced.<br>
<a class="Constant" href="autocmd.html#SourceCmd" name="SourceCmd">SourceCmd</a><br>
SourceCmd When sourcing a Vim script. <a class="Identifier" href="repeat.html#:source">:source</a><br>
<span class="Special"><afile></span> is the name of the file being sourced.<br>
The autocommand must source this file.<br>
<a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<a class="Constant" href="autocmd.html#SpellFileMissing" name="SpellFileMissing">SpellFileMissing</a><br>
SpellFileMissing When trying to load a spell checking file and<br>
it can't be found. The pattern is matched<br>
against the language. <span class="Special"><amatch></span> is the<br>
language, <a class="Type" href="options.html#'encoding'">'encoding'</a> also matters. See<br>
<a class="Identifier" href="spell.html#spell-SpellFileMissing">spell-SpellFileMissing</a>.<br>
<a class="Constant" href="autocmd.html#StdinReadPost" name="StdinReadPost">StdinReadPost</a><br>
StdinReadPost After reading from the stdin into the buffer,<br>
before executing the modelines. Only used<br>
when the "-" argument was used when Vim was<br>
started <a class="Identifier" href="starting.html#--">--</a>.<br>
<a class="Constant" href="autocmd.html#StdinReadPre" name="StdinReadPre">StdinReadPre</a><br>
StdinReadPre Before reading from stdin into the buffer.<br>
Only used when the "-" argument was used when<br>
Vim was started <a class="Identifier" href="starting.html#--">--</a>.<br>
<a class="Constant" href="autocmd.html#SwapExists" name="SwapExists">SwapExists</a><br>
SwapExists Detected an existing swap file when starting<br>
to edit a file. Only when it is possible to<br>
select a way to handle the situation, when Vim<br>
would ask the user what to do.<br>
The <a class="Identifier" href="eval.html#v:swapname">v:swapname</a> variable holds the name of<br>
the swap file found, <span class="Special"><afile></span> the file being<br>
edited. <a class="Identifier" href="eval.html#v:swapcommand">v:swapcommand</a> may contain a command<br>
to be executed in the opened file.<br>
The commands should set the <a class="Identifier" href="eval.html#v:swapchoice">v:swapchoice</a><br>
variable to a string with one character to<br>
tell Vim what should be done next:<br>
'o' open read-only<br>
'e' edit the file anyway<br>
'r' recover<br>
'd' delete the swap file<br>
'q' quit, don't edit the file<br>
'a' abort, like hitting <span class="Special">CTRL-C</span><br>
When set to an empty string the user will be<br>
asked, as if there was no SwapExists autocmd.<br>
<a class="Constant" href="autocmd.html#E812" name="E812">E812</a><br>
It is not allowed to change to another buffer,<br>
change a buffer name or change directory<br>
here.<br>
<a class="Constant" href="autocmd.html#Syntax" name="Syntax">Syntax</a><br>
Syntax When the <a class="Type" href="options.html#'syntax'">'syntax'</a> option has been set. The<br>
pattern is matched against the syntax name.<br>
<span class="Special"><afile></span> can be used for the name of the file<br>
where this option was set, and <span class="Special"><amatch></span> for<br>
the new value of <a class="Type" href="options.html#'syntax'">'syntax'</a>.<br>
See <a class="Identifier" href="syntax.html#:syn-on">:syn-on</a>.<br>
<a class="Constant" href="autocmd.html#TabClosed" name="TabClosed">TabClosed</a><br>
TabClosed After closing a tab page.<br>
<a class="Constant" href="autocmd.html#TabEnter" name="TabEnter">TabEnter</a><br>
TabEnter Just after entering a tab page. <a class="Identifier" href="tabpage.html#tab-page">tab-page</a><br>
After triggering the WinEnter and before<br>
triggering the BufEnter event.<br>
<a class="Constant" href="autocmd.html#TabLeave" name="TabLeave">TabLeave</a><br>
TabLeave Just before leaving a tab page. <a class="Identifier" href="tabpage.html#tab-page">tab-page</a><br>
A WinLeave event will have been triggered<br>
first.<br>
<a class="Constant" href="autocmd.html#TabNew" name="TabNew">TabNew</a><br>
TabNew When a tab page was created. <a class="Identifier" href="tabpage.html#tab-page">tab-page</a><br>
A WinEnter event will have been triggered<br>
first, TabEnter follows.<br>
<a class="Constant" href="autocmd.html#TermChanged" name="TermChanged">TermChanged</a><br>
TermChanged After the value of <a class="Type" href="options.html#'term'">'term'</a> has changed. Useful<br>
for re-loading the syntax file to update the<br>
colors, fonts and other terminal-dependent<br>
settings. Executed for all loaded buffers.<br>
<a class="Constant" href="autocmd.html#TermResponse" name="TermResponse">TermResponse</a><br>
TermResponse After the response to <a class="Identifier" href="term.html#t_RV">t_RV</a> is received from<br>
the terminal. The value of <a class="Identifier" href="eval.html#v:termresponse">v:termresponse</a><br>
can be used to do things depending on the<br>
terminal version. <span class="Todo">Note</span> that this event may be<br>
triggered halfway executing another event,<br>
especially if file I/O, a shell command or<br>
anything else that takes time is involved.<br>
<a class="Constant" href="autocmd.html#TextChanged" name="TextChanged">TextChanged</a><br>
TextChanged After a change was made to the text in the<br>
current buffer in Normal mode. That is when<br>
<a class="Identifier" href="eval.html#b:changedtick">b:changedtick</a> has changed.<br>
Not triggered when there is typeahead or when<br>
an operator is pending.<br>
Careful: This is triggered very often, don't<br>
do anything that the user does not expect or<br>
that is slow.<br>
<a class="Constant" href="autocmd.html#TextChangedI" name="TextChangedI">TextChangedI</a><br>
TextChangedI After a change was made to the text in the<br>
current buffer in Insert mode.<br>
Not triggered when the popup menu is visible.<br>
Otherwise the same as TextChanged.<br>
<a class="Constant" href="autocmd.html#User" name="User">User</a><br>
User Never executed automatically. To be used for<br>
autocommands that are only executed with<br>
":doautocmd".<br>
<a class="Constant" href="autocmd.html#UserGettingBored" name="UserGettingBored">UserGettingBored</a><br>
UserGettingBored When the user presses the same key 42 times.<br>
Just kidding! :-)<br>
<a class="Constant" href="autocmd.html#VimEnter" name="VimEnter">VimEnter</a><br>
VimEnter After doing all the startup stuff, including<br>
loading .vimrc files, executing the "-c cmd"<br>
arguments, creating all windows and loading<br>
the buffers in them.<br>
Just before this event is triggered the<br>
<a class="Identifier" href="eval.html#v:vim_did_enter">v:vim_did_enter</a> variable is set, so that you<br>
can do:<br>
<div class="helpExample"> if v:vim_did_enter<br>
call s:init()<br>
else<br>
au VimEnter * call s:init()<br>
endif</div>
<a class="Constant" href="autocmd.html#VimLeave" name="VimLeave">VimLeave</a><br>
VimLeave Before exiting Vim, just after writing the<br>
.viminfo file. Executed only once, like<br>
VimLeavePre.<br>
To detect an abnormal exit use <a class="Identifier" href="eval.html#v:dying">v:dying</a>.<br>
When v:dying is 2 or more this event is not<br>
triggered.<br>
<a class="Constant" href="autocmd.html#VimLeavePre" name="VimLeavePre">VimLeavePre</a><br>
VimLeavePre Before exiting Vim, just before writing the<br>
.viminfo file. This is executed only once,<br>
if there is a match with the name of what<br>
happens to be the current buffer when exiting.<br>
Mostly useful with a "*" pattern.<br>
<div class="helpExample"> :autocmd VimLeavePre * call CleanupStuff()</div>
To detect an abnormal exit use <a class="Identifier" href="eval.html#v:dying">v:dying</a>.<br>
When v:dying is 2 or more this event is not<br>
triggered.<br>
<a class="Constant" href="autocmd.html#VimResized" name="VimResized">VimResized</a><br>
VimResized After the Vim window was resized, thus <a class="Type" href="options.html#'lines'">'lines'</a><br>
and/or <a class="Type" href="options.html#'columns'">'columns'</a> changed. Not when starting<br>
up though.<br>
<a class="Constant" href="autocmd.html#WinEnter" name="WinEnter">WinEnter</a><br>
WinEnter After entering another window. Not done for<br>
the first window, when Vim has just started.<br>
Useful for setting the window height.<br>
If the window is for another buffer, Vim<br>
executes the BufEnter autocommands after the<br>
WinEnter autocommands.<br>
<span class="Todo">Note</span>: When using ":split fname" the WinEnter<br>
event is triggered after the split but before<br>
the file "fname" is loaded.<br>
<a class="Constant" href="autocmd.html#WinLeave" name="WinLeave">WinLeave</a><br>
WinLeave Before leaving a window. If the window to be<br>
entered next is for a different buffer, Vim<br>
executes the BufLeave autocommands before the<br>
WinLeave autocommands (but not for ":new").<br>
Not used for ":qa" or ":q" when exiting Vim.<br>
<br>
<a class="Constant" href="autocmd.html#WinNew" name="WinNew">WinNew</a><br>
WinNew When a new window was created. Not done for<br>
the first window, when Vim has just started.<br>
Before a WinEnter event.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
6. Patterns <a class="Constant" href="autocmd.html#autocmd-patterns" name="autocmd-patterns">autocmd-patterns</a> <a class="Constant" href="autocmd.html#{pat}" name="{pat}">{pat}</a><br>
<br>
The <span class="Special">{pat}</span> argument can be a comma separated list. This works as if the<br>
command was given with each pattern separately. Thus this command:<br>
<div class="helpExample"> :autocmd BufRead *.txt,*.info set et</div>
Is equivalent to:<br>
<div class="helpExample"> :autocmd BufRead *.txt set et<br>
:autocmd BufRead *.info set et</div>
<br>
The file pattern <span class="Special">{pat}</span> is tested for a match against the file name in one of<br>
two ways:<br>
1. When there is no '/' in the pattern, Vim checks for a match against only<br>
the tail part of the file name (without its leading directory path).<br>
2. When there is a '/' in the pattern, Vim checks for a match against both the<br>
short file name (as you typed it) and the full file name (after expanding<br>
it to a full path and resolving symbolic links).<br>
<br>
The special pattern <span class="Special"><buffer></span> or <buffer=<span class="Special">N</span>> is used for buffer-local<br>
autocommands <a class="Identifier" href="autocmd.html#autocmd-buflocal">autocmd-buflocal</a>. This pattern is not matched against the name<br>
of a buffer.<br>
<br>
Examples:<br>
<div class="helpExample"> :autocmd BufRead *.txt set et</div>
Set the <a class="Type" href="options.html#'et'">'et'</a> option for all text files.<br>
<br>
<div class="helpExample"> :autocmd BufRead /vim/src/*.c set cindent</div>
Set the <a class="Type" href="options.html#'cindent'">'cindent'</a> option for C files in the /vim/src directory.<br>
<br>
<div class="helpExample"> :autocmd BufRead /tmp/*.c set ts=5</div>
If you have a link from "/tmp/test.c" to "/home/nobody/vim/src/test.c", and<br>
you start editing "/tmp/test.c", this autocommand will match.<br>
<br>
<span class="Todo">Note</span>: To match part of a path, but not from the root directory, use a '*' as<br>
the first character. Example:<br>
<div class="helpExample"> :autocmd BufRead */doc/*.txt set tw=78</div>
This autocommand will for example be executed for "/tmp/doc/xx.txt" and<br>
"/usr/home/piet/doc/yy.txt". The number of directories does not matter here.<br>
<br>
<br>
The file name that the pattern is matched against is after expanding<br>
wildcards. Thus if you issue this command:<br>
<div class="helpExample"> :e $ROOTDIR/main.$EXT</div>
The argument is first expanded to:<br>
<div class="helpExample"> /usr/root/main.py</div>
Before it's matched with the pattern of the autocommand. Careful with this<br>
when using events like FileReadCmd, the value of <span class="Special"><amatch></span> may not be what you<br>
expect.<br>
<br>
<br>
Environment variables can be used in a pattern:<br>
<div class="helpExample"> :autocmd BufRead $VIMRUNTIME/doc/*.txt set expandtab</div>
And ~ can be used for the home directory (if $HOME is defined):<br>
<div class="helpExample"> :autocmd BufWritePost ~/.vimrc so ~/.vimrc<br>
:autocmd BufRead ~archive/* set readonly</div>
The environment variable is expanded when the autocommand is defined, not when<br>
the autocommand is executed. This is different from the command!<br>
<br>
<a class="Constant" href="autocmd.html#file-pattern" name="file-pattern">file-pattern</a><br>
The pattern is interpreted like mostly used in file names:<br>
* matches any sequence of characters; Unusual: includes path<br>
separators<br>
? matches any single character<br>
\? matches a '?'<br>
. matches a '.'<br>
~ matches a '~'<br>
, separates patterns<br>
\, matches a ','<br>
{ } like \( \) in a <a class="Identifier" href="pattern.html#pattern">pattern</a><br>
, inside { }: like \| in a <a class="Identifier" href="pattern.html#pattern">pattern</a><br>
\} literal }<br>
\{ literal {<br>
\\\{n,m\} like \<span class="Special">{n,m}</span> in a <a class="Identifier" href="pattern.html#pattern">pattern</a><br>
\ special meaning like in a <a class="Identifier" href="pattern.html#pattern">pattern</a><br>
<span class="Special">[ch]</span> matches 'c' or 'h'<br>
<span class="Special">[^ch]</span> match any character but 'c' and 'h'<br>
<br>
<span class="Todo">Note</span> that for all systems the '/' character is used for path separator (even<br>
MS-DOS and OS/2). This was done because the backslash is difficult to use<br>
in a pattern and to make the autocommands portable across different systems.<br>
<br>
It is possible to use <a class="Identifier" href="pattern.html#pattern">pattern</a> items, but they may not work as expected,<br>
because of the translation done for the above.<br>
<br>
<a class="Constant" href="autocmd.html#autocmd-changes" name="autocmd-changes">autocmd-changes</a><br>
Matching with the pattern is done when an event is triggered. Changing the<br>
buffer name in one of the autocommands, or even deleting the buffer, does not<br>
change which autocommands will be executed. Example:<br>
<br>
<div class="helpExample"> au BufEnter *.foo bdel<br>
au BufEnter *.foo set modified</div>
<br>
This will delete the current buffer and then set <a class="Type" href="options.html#'modified'">'modified'</a> in what has become<br>
the current buffer instead. Vim doesn't take into account that "*.foo"<br>
doesn't match with that buffer name. It matches "*.foo" with the name of the<br>
buffer at the moment the event was triggered.<br>
<br>
However, buffer-local autocommands will not be executed for a buffer that has<br>
been wiped out with <a class="Identifier" href="windows.html#:bwipe">:bwipe</a>. After deleting the buffer with <a class="Identifier" href="windows.html#:bdel">:bdel</a> the<br>
buffer actually still exists (it becomes unlisted), thus the autocommands are<br>
still executed.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
7. Buffer-local autocommands <a class="Constant" href="autocmd.html#autocmd-buflocal" name="autocmd-buflocal">autocmd-buflocal</a> <a class="Constant" href="autocmd.html#autocmd-buffer-local" name="autocmd-buffer-local">autocmd-buffer-local</a><br>
<a class="Constant" href="autocmd.html#<buffer=N>" name="<buffer=N>"><buffer=N></a> <a class="Constant" href="autocmd.html#<buffer=abuf>" name="<buffer=abuf>"><buffer=abuf></a> <a class="Constant" href="autocmd.html#E680" name="E680">E680</a><br>
<br>
Buffer-local autocommands are attached to a specific buffer. They are useful<br>
if the buffer does not have a name and when the name does not match a specific<br>
pattern. But it also means they must be explicitly added to each buffer.<br>
<br>
Instead of a pattern buffer-local autocommands use one of these forms:<br>
<span class="Special"><buffer></span> current buffer<br>
<buffer=99> buffer number 99<br>
<buffer=abuf> using <span class="Special"><abuf></span> (only when executing autocommands)<br>
<a class="Identifier" href="cmdline.html#<abuf>"><abuf></a><br>
<br>
Examples:<br>
<div class="helpExample"> :au CursorHold <buffer> echo 'hold'<br>
:au CursorHold <buffer=33> echo 'hold'<br>
:au BufNewFile * au CursorHold <buffer=abuf> echo 'hold'</div>
<br>
All the commands for autocommands also work with buffer-local autocommands,<br>
simply use the special string instead of the pattern. Examples:<br>
<div class="helpExample"> :au! * <buffer> " remove buffer-local autocommands for<br>
" current buffer<br>
:au! * <buffer=33> " remove buffer-local autocommands for<br>
" buffer #33<br>
:bufdo :au! CursorHold <buffer> " remove autocmd for given event for all<br>
" buffers<br>
:au * <buffer> " list buffer-local autocommands for<br>
" current buffer</div>
<br>
<span class="Todo">Note</span> that when an autocommand is defined for the current buffer, it is stored<br>
with the buffer number. Thus it uses the form "<buffer=12>", where 12 is the<br>
number of the current buffer. You will see this when listing autocommands,<br>
for example.<br>
<br>
To test for presence of buffer-local autocommands use the <a class="Identifier" href="eval.html#exists()">exists()</a> function<br>
as follows:<br>
<div class="helpExample"> :if exists("#CursorHold#<buffer=12>") | ... | endif<br>
:if exists("#CursorHold#<buffer>") | ... | endif " for current buffer</div>
<br>
When a buffer is wiped out its buffer-local autocommands are also gone, of<br>
course. <span class="Todo">Note</span> that when deleting a buffer, e.g., with ":bdel", it is only<br>
unlisted, the autocommands are still present. In order to see the removal of<br>
buffer-local autocommands:<br>
<div class="helpExample"> :set verbose=6</div>
<br>
It is not possible to define buffer-local autocommands for a non-existent<br>
buffer.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
8. Groups <a class="Constant" href="autocmd.html#autocmd-groups" name="autocmd-groups">autocmd-groups</a><br>
<br>
Autocommands can be put together in a group. This is useful for removing or<br>
executing a group of autocommands. For example, all the autocommands for<br>
syntax highlighting are put in the "highlight" group, to be able to execute<br>
":doautoall highlight BufRead" when the GUI starts.<br>
<br>
When no specific group is selected, Vim uses the default group. The default<br>
group does not have a name. You cannot execute the autocommands from the<br>
default group separately; you can execute them only by executing autocommands<br>
for all groups.<br>
<br>
Normally, when executing autocommands automatically, Vim uses the autocommands<br>
for all groups. The group only matters when executing autocommands with<br>
":doautocmd" or ":doautoall", or when defining or deleting autocommands.<br>
<br>
The group name can contain any characters except white space. The group name<br>
"end" is reserved (also in uppercase).<br>
<br>
The group name is case sensitive. <span class="Todo">Note</span> that this is different from the event<br>
name!<br>
<br>
<a class="Constant" href="autocmd.html#:aug" name=":aug">:aug</a> <a class="Constant" href="autocmd.html#:augroup" name=":augroup">:augroup</a><br>
:aug[roup] <span class="Special">{name}</span> Define the autocmd group name for the<br>
following ":autocmd" commands. The name "end"<br>
or "END" selects the default group.<br>
To avoid confusion, the name should be<br>
different from existing <span class="Special">{event}</span> names, as this<br>
most likely will not do what you intended.<br>
<br>
<a class="Constant" href="autocmd.html#:augroup-delete" name=":augroup-delete">:augroup-delete</a> <a class="Constant" href="autocmd.html#E367" name="E367">E367</a> <a class="Constant" href="autocmd.html#W19" name="W19">W19</a> <a class="Constant" href="autocmd.html#E936" name="E936">E936</a><br>
:aug[roup]! <span class="Special">{name}</span> Delete the autocmd group <span class="Special">{name}</span>. Don't use<br>
this if there is still an autocommand using<br>
this group! You will get a warning if doing<br>
it anyway. when the group is the current group<br>
you will get error E936.<br>
<br>
To enter autocommands for a specific group, use this method:<br>
1. Select the group with ":augroup <span class="Special">{name}</span>".<br>
2. Delete any old autocommands with ":au!".<br>
3. Define the autocommands.<br>
4. Go back to the default group with "augroup END".<br>
<br>
Example:<br>
<div class="helpExample"> :augroup uncompress<br>
: au!<br>
: au BufEnter *.gz %!gunzip<br>
:augroup END</div>
<br>
This prevents having the autocommands defined twice (e.g., after sourcing the<br>
.vimrc file again).<br>
<br>
<span class="PreProc">==============================================================================</span><br>
9. Executing autocommands <a class="Constant" href="autocmd.html#autocmd-execute" name="autocmd-execute">autocmd-execute</a><br>
<br>
Vim can also execute Autocommands non-automatically. This is useful if you<br>
have changed autocommands, or when Vim has executed the wrong autocommands<br>
(e.g., the file pattern match was wrong).<br>
<br>
<span class="Todo">Note</span> that the <a class="Type" href="options.html#'eventignore'">'eventignore'</a> option applies here too. Events listed in this<br>
option will not cause any commands to be executed.<br>
<br>
<a class="Constant" href="autocmd.html#:do" name=":do">:do</a> <a class="Constant" href="autocmd.html#:doau" name=":doau">:doau</a> <a class="Constant" href="autocmd.html#:doautocmd" name=":doautocmd">:doautocmd</a> <a class="Constant" href="autocmd.html#E217" name="E217">E217</a><br>
:do[autocmd] [<span class="Special"><nomodeline></span>] <span class="Special">[group]</span> <span class="Special">{event}</span> <span class="Special">[fname]</span><br>
Apply the autocommands matching <span class="Special">[fname]</span> (default:<br>
current file name) for <span class="Special">{event}</span> to the current buffer.<br>
You can use this when the current file name does not<br>
match the right pattern, after changing settings, or<br>
to execute autocommands for a certain event.<br>
It's possible to use this inside an autocommand too,<br>
so you can base the autocommands for one extension on<br>
another extension. Example:<br>
<div class="helpExample"> :au BufEnter *.cpp so ~/.vimrc_cpp<br>
:au BufEnter *.cpp doau BufEnter x.c</div>
Be careful to avoid endless loops. See<br>
<a class="Identifier" href="autocmd.html#autocmd-nested">autocmd-nested</a>.<br>
<br>
When the <span class="Special">[group]</span> argument is not given, Vim executes<br>
the autocommands for all groups. When the <span class="Special">[group]</span><br>
argument is included, Vim executes only the matching<br>
autocommands for that group. <span class="Todo">Note</span>: if you use an<br>
undefined group name, Vim gives you an error message.<br>
<a class="Constant" href="autocmd.html#<nomodeline>" name="<nomodeline>"><nomodeline></a><br>
After applying the autocommands the modelines are<br>
processed, so that their settings overrule the<br>
settings from autocommands, like what happens when<br>
editing a file. This is skipped when the <span class="Special"><nomodeline></span><br>
argument is present. You probably want to use<br>
<span class="Special"><nomodeline></span> for events that are not used when loading<br>
a buffer, such as <a class="Identifier" href="autocmd.html#User">User</a>.<br>
Processing modelines is also skipped when no<br>
matching autocommands were executed.<br>
<br>
<a class="Constant" href="autocmd.html#:doautoa" name=":doautoa">:doautoa</a> <a class="Constant" href="autocmd.html#:doautoall" name=":doautoall">:doautoall</a><br>
:doautoa[ll] [<span class="Special"><nomodeline></span>] <span class="Special">[group]</span> <span class="Special">{event}</span> <span class="Special">[fname]</span><br>
Like ":doautocmd", but apply the autocommands to each<br>
loaded buffer. <span class="Todo">Note</span> that <span class="Special">[fname]</span> is used to select<br>
the autocommands, not the buffers to which they are<br>
applied.<br>
Careful: Don't use this for autocommands that delete a<br>
buffer, change to another buffer or change the<br>
contents of a buffer; the result is unpredictable.<br>
This command is intended for autocommands that set<br>
options, change highlighting, and things like that.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
10. Using autocommands <a class="Constant" href="autocmd.html#autocmd-use" name="autocmd-use">autocmd-use</a><br>
<br>
For WRITING FILES there are four possible sets of events. Vim uses only one<br>
of these sets for a write command:<br>
<br>
BufWriteCmd BufWritePre BufWritePost writing the whole buffer<br>
FilterWritePre FilterWritePost writing to filter temp file<br>
FileAppendCmd FileAppendPre FileAppendPost appending to a file<br>
FileWriteCmd FileWritePre FileWritePost any other file write<br>
<br>
When there is a matching "*Cmd" autocommand, it is assumed it will do the<br>
writing. No further writing is done and the other events are not triggered.<br>
<a class="Identifier" href="autocmd.html#Cmd-event">Cmd-event</a><br>
<br>
<span class="Todo">Note</span> that the *WritePost commands should undo any changes to the buffer that<br>
were caused by the *WritePre commands; otherwise, writing the file will have<br>
the side effect of changing the buffer.<br>
<br>
Before executing the autocommands, the buffer from which the lines are to be<br>
written temporarily becomes the current buffer. Unless the autocommands<br>
change the current buffer or delete the previously current buffer, the<br>
previously current buffer is made the current buffer again.<br>
<br>
The *WritePre and *AppendPre autocommands must not delete the buffer from<br>
which the lines are to be written.<br>
<br>
The '[ and '] marks have a special position:<br>
- Before the *ReadPre event the '[ mark is set to the line just above where<br>
the new lines will be inserted.<br>
- Before the *ReadPost event the '[ mark is set to the first line that was<br>
just read, the '] mark to the last line.<br>
- Before executing the *WriteCmd, *WritePre and *AppendPre autocommands the '[<br>
mark is set to the first line that will be written, the '] mark to the last<br>
line.<br>
Careful: '[ and '] change when using commands that change the buffer.<br>
<br>
In commands which expect a file name, you can use "<span class="Special"><afile></span>" for the file name<br>
that is being read <a class="Identifier" href="cmdline.html#:<afile>">:<afile></a> (you can also use "%" for the current file<br>
name). "<span class="Special"><abuf></span>" can be used for the buffer number of the currently effective<br>
buffer. This also works for buffers that doesn't have a name. But it doesn't<br>
work for files without a buffer (e.g., with ":r file").<br>
<br>
<a class="Constant" href="autocmd.html#gzip-example" name="gzip-example">gzip-example</a><br>
Examples for reading and writing compressed files:<br>
<div class="helpExample"> :augroup gzip<br>
: autocmd!<br>
: autocmd BufReadPre,FileReadPre *.gz set bin<br>
: autocmd BufReadPost,FileReadPost *.gz '[,']!gunzip<br>
: autocmd BufReadPost,FileReadPost *.gz set nobin<br>
: autocmd BufReadPost,FileReadPost *.gz execute ":doautocmd BufReadPost " . expand("%:r")<br>
: autocmd BufWritePost,FileWritePost *.gz !mv <afile> <afile>:r<br>
: autocmd BufWritePost,FileWritePost *.gz !gzip <afile>:r</div>
<br>
<div class="helpExample"> : autocmd FileAppendPre *.gz !gunzip <afile><br>
: autocmd FileAppendPre *.gz !mv <afile>:r <afile><br>
: autocmd FileAppendPost *.gz !mv <afile> <afile>:r<br>
: autocmd FileAppendPost *.gz !gzip <afile>:r<br>
:augroup END</div>
<br>
The "gzip" group is used to be able to delete any existing autocommands with<br>
":autocmd!", for when the file is sourced twice.<br>
<br>
("<span class="Special"><afile></span>:r" is the file name without the extension, see <a class="Identifier" href="cmdline.html#:_%:">:_%:</a>)<br>
<br>
The commands executed for the BufNewFile, BufRead/BufReadPost, BufWritePost,<br>
FileAppendPost and VimLeave events do not set or reset the changed flag of the<br>
buffer. When you decompress the buffer with the BufReadPost autocommands, you<br>
can still exit with ":q". When you use ":undo" in BufWritePost to undo the<br>
changes made by BufWritePre commands, you can still do ":q" (this also makes<br>
"ZZ" work). If you do want the buffer to be marked as modified, set the<br>
<a class="Type" href="options.html#'modified'">'modified'</a> option.<br>
<br>
To execute Normal mode commands from an autocommand, use the ":normal"<br>
command. Use with care! If the Normal mode command is not finished, the user<br>
needs to type characters (e.g., after ":normal m" you need to type a mark<br>
name).<br>
<br>
If you want the buffer to be unmodified after changing it, reset the<br>
<a class="Type" href="options.html#'modified'">'modified'</a> option. This makes it possible to exit the buffer with ":q"<br>
instead of ":q!".<br>
<br>
<a class="Constant" href="autocmd.html#autocmd-nested" name="autocmd-nested">autocmd-nested</a> <a class="Constant" href="autocmd.html#E218" name="E218">E218</a><br>
By default, autocommands do not nest. If you use ":e" or ":w" in an<br>
autocommand, Vim does not execute the BufRead and BufWrite autocommands for<br>
those commands. If you do want this, use the "nested" flag for those commands<br>
in which you want nesting. For example:<br>
<div class="helpExample"> :autocmd FileChangedShell *.c nested e!</div>
The nesting is limited to 10 levels to get out of recursive loops.<br>
<br>
It's possible to use the ":au" command in an autocommand. This can be a<br>
self-modifying command! This can be useful for an autocommand that should<br>
execute only once.<br>
<br>
If you want to skip autocommands for one command, use the <a class="Identifier" href="autocmd.html#:noautocmd">:noautocmd</a> command<br>
modifier or the <a class="Type" href="options.html#'eventignore'">'eventignore'</a> option.<br>
<br>
<span class="Todo">Note</span>: When reading a file (with ":read file" or with a filter command) and the<br>
last line in the file does not have an <span class="Special"><EOL></span>, Vim remembers this. At the next<br>
write (with ":write file" or with a filter command), if the same line is<br>
written again as the last line in a file AND <a class="Type" href="options.html#'binary'">'binary'</a> is set, Vim does not<br>
supply an <span class="Special"><EOL></span>. This makes a filter command on the just read lines write the<br>
same file as was read, and makes a write command on just filtered lines write<br>
the same file as was read from the filter. For example, another way to write<br>
a compressed file:<br>
<br>
<div class="helpExample"> :autocmd FileWritePre *.gz set bin|'[,']!gzip<br>
:autocmd FileWritePost *.gz undo|set nobin</div>
<br>
<a class="Constant" href="autocmd.html#autocommand-pattern" name="autocommand-pattern">autocommand-pattern</a><br>
You can specify multiple patterns, separated by commas. Here are some<br>
examples:<br>
<br>
<div class="helpExample"> :autocmd BufRead * set tw=79 nocin ic infercase fo=2croq<br>
:autocmd BufRead .letter set tw=72 fo=2tcrq<br>
:autocmd BufEnter .letter set dict=/usr/lib/dict/words<br>
:autocmd BufLeave .letter set dict=<br>
:autocmd BufRead,BufNewFile *.c,*.h set tw=0 cin noic<br>
:autocmd BufEnter *.c,*.h abbr FOR for (i = 0; i < 3; ++i)<CR>{<CR>}<Esc>O<br>
:autocmd BufLeave *.c,*.h unabbr FOR</div>
<br>
For makefiles (makefile, Makefile, imakefile, makefile.unix, etc.):<br>
<br>
<div class="helpExample"> :autocmd BufEnter ?akefile* set include=^s\=include<br>
:autocmd BufLeave ?akefile* set include&</div>
<br>
To always start editing C files at the first function:<br>
<br>
<div class="helpExample"> :autocmd BufRead *.c,*.h 1;/^{</div>
<br>
Without the "1;" above, the search would start from wherever the file was<br>
entered, rather than from the start of the file.<br>
<br>
<a class="Constant" href="autocmd.html#skeleton" name="skeleton">skeleton</a> <a class="Constant" href="autocmd.html#template" name="template">template</a><br>
To read a skeleton (template) file when opening a new file:<br>
<br>
<div class="helpExample"> :autocmd BufNewFile *.c 0r ~/vim/skeleton.c<br>
:autocmd BufNewFile *.h 0r ~/vim/skeleton.h<br>
:autocmd BufNewFile *.java 0r ~/vim/skeleton.java</div>
<br>
To insert the current date and time in a *.html file when writing it:<br>
<br>
<div class="helpExample"> :autocmd BufWritePre,FileWritePre *.html ks|call LastMod()|'s<br>
:fun LastMod()<br>
: if line("$") > 20<br>
: let l = 20<br>
: else<br>
: let l = line("$")<br>
: endif<br>
: exe "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " .<br>
: \ strftime("%Y %b %d")<br>
:endfun</div>
<br>
You need to have a line "Last modified: <date time>" in the first 20 lines<br>
of the file for this to work. Vim replaces <date time> (and anything in the<br>
same line after it) with the current date and time. Explanation:<br>
ks mark current position with mark 's'<br>
call LastMod() call the LastMod() function to do the work<br>
's return the cursor to the old position<br>
The LastMod() function checks if the file is shorter than 20 lines, and then<br>
uses the ":g" command to find lines that contain "Last modified: ". For those<br>
lines the ":s" command is executed to replace the existing date with the<br>
current one. The ":execute" command is used to be able to use an expression<br>
for the ":g" and ":s" commands. The date is obtained with the strftime()<br>
function. You can change its argument to get another date string.<br>
<br>
When entering :autocmd on the command-line, completion of events and command<br>
names may be done (with <span class="Special"><Tab></span>, <span class="Special">CTRL-D</span>, etc.) where appropriate.<br>
<br>
Vim executes all matching autocommands in the order that you specify them.<br>
It is recommended that your first autocommand be used for all files by using<br>
"*" as the file pattern. This means that you can define defaults you like<br>
here for any settings, and if there is another matching autocommand it will<br>
override these. But if there is no other matching autocommand, then at least<br>
your default settings are recovered (if entering this file from another for<br>
which autocommands did match). <span class="Todo">Note</span> that "*" will also match files starting<br>
with ".", unlike Unix shells.<br>
<br>
<a class="Constant" href="autocmd.html#autocmd-searchpat" name="autocmd-searchpat">autocmd-searchpat</a><br>
Autocommands do not change the current search patterns. Vim saves the current<br>
search patterns before executing autocommands then restores them after the<br>
autocommands finish. This means that autocommands do not affect the strings<br>
highlighted with the <a class="Type" href="options.html#'hlsearch'">'hlsearch'</a> option. Within autocommands, you can still<br>
use search patterns normally, e.g., with the "n" command.<br>
If you want an autocommand to set the search pattern, such that it is used<br>
after the autocommand finishes, use the ":let @/ =" command.<br>
The search-highlighting cannot be switched off with ":nohlsearch" in an<br>
autocommand. Use the 'h' flag in the <a class="Type" href="options.html#'viminfo'">'viminfo'</a> option to disable search-<br>
highlighting when starting Vim.<br>
<br>
<a class="Constant" href="autocmd.html#Cmd-event" name="Cmd-event">Cmd-event</a><br>
When using one of the "*Cmd" events, the matching autocommands are expected to<br>
do the file reading, writing or sourcing. This can be used when working with<br>
a special kind of file, for example on a remote system.<br>
CAREFUL: If you use these events in a wrong way, it may have the effect of<br>
making it impossible to read or write the matching files! Make sure you test<br>
your autocommands properly. Best is to use a pattern that will never match a<br>
normal file name, for example "ftp://*".<br>
<br>
When defining a BufReadCmd it will be difficult for Vim to recover a crashed<br>
editing session. When recovering from the original file, Vim reads only those<br>
parts of a file that are not found in the swap file. Since that is not<br>
possible with a BufReadCmd, use the <a class="Identifier" href="recover.html#:preserve">:preserve</a> command to make sure the<br>
original file isn't needed for recovery. You might want to do this only when<br>
you expect the file to be modified.<br>
<br>
For file read and write commands the <a class="Identifier" href="eval.html#v:cmdarg">v:cmdarg</a> variable holds the "++enc="<br>
and "++ff=" argument that are effective. These should be used for the command<br>
that reads/writes the file. The <a class="Identifier" href="eval.html#v:cmdbang">v:cmdbang</a> variable is one when "!" was<br>
used, zero otherwise.<br>
<br>
See the $VIMRUNTIME/plugin/netrwPlugin.vim for examples.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
11. Disabling autocommands <a class="Constant" href="autocmd.html#autocmd-disable" name="autocmd-disable">autocmd-disable</a><br>
<br>
To disable autocommands for some time use the <a class="Type" href="options.html#'eventignore'">'eventignore'</a> option. <span class="Todo">Note</span> that<br>
this may cause unexpected behavior, make sure you restore <a class="Type" href="options.html#'eventignore'">'eventignore'</a><br>
afterwards, using a <a class="Identifier" href="eval.html#:try">:try</a> block with <a class="Identifier" href="eval.html#:finally">:finally</a>.<br>
<br>
<a class="Constant" href="autocmd.html#:noautocmd" name=":noautocmd">:noautocmd</a> <a class="Constant" href="autocmd.html#:noa" name=":noa">:noa</a><br>
To disable autocommands for just one command use the ":noautocmd" command<br>
modifier. This will set <a class="Type" href="options.html#'eventignore'">'eventignore'</a> to "all" for the duration of the<br>
following command. Example:<br>
<br>
<div class="helpExample"> :noautocmd w fname.gz</div>
<br>
This will write the file without triggering the autocommands defined by the<br>
gzip plugin.<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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。