-*autocmd.txt* For Vim version 7.0aa. Last change: 2005 Nov 21
+*autocmd.txt* For Vim version 7.0aa. Last change: 2005 Dec 07
VIM REFERENCE MANUAL by Bram Moolenaar
==============================================================================
5. Events *autocmd-events* *E215* *E216*
+You can specify a comma-separated list of event names. No white space can be
+used in this list. The command applies to all the events in the list.
+
+For READING FILES there are four kinds of events possible:
+ BufNewFile starting to edit a non-existent file
+ BufReadPre BufReadPost starting to edit an existing file
+ FilterReadPre FilterReadPost read the temp file with filter output
+ FileReadPre FileReadPost any other file read
+Vim uses only one of these four kinds when reading a file. The "Pre" and
+"Post" events are both triggered, before and after reading the file.
+
+Note that the autocommands for the *ReadPre events and all the Filter events
+are not allowed to change the current buffer (you will get an error message if
+this happens). This is to prevent the file to be read into the wrong buffer.
+
+Note that the 'modified' flag is reset AFTER executing the BufReadPost
+and BufNewFile autocommands. But when the 'modified' option was set by the
+autocommands, this doesn't happen.
+
+You can use the 'eventignore' option to ignore a number of events or all
+events.
*autocommand-events* *{event}*
Vim recognizes the following events. Vim ignores the case of event names
(e.g., you can use "BUFread" or "bufread" instead of "BufRead").
+First an overview by function with a short explanation. Then the list
+alpabetically with full explanations |autocmd-events-abc|.
+
+Name triggered by ~
+
+ Reading
+|BufNewFile| starting to edit a file that doesn't exist
+|BufReadPre| starting to edit a new buffer, before reading the file
+|BufRead| starting to edit a new buffer, after reading the file
+|BufReadPost| starting to edit a new buffer, after reading the file
+|BufReadCmd| before starting to edit a new buffer |Cmd-event|
+
+|FileReadPre| before reading a file with a ":read" command
+|FileReadPost| after reading a file with a ":read" command
+|FileReadCmd| before reading a file with a ":read" comman |Cmd-event|
+
+|FilterReadPre| before reading a file from a filter command
+|FilterReadPost| after reading a file from a filter command
+
+|StdinReadPre| before reading from stdin into the buffer
+|StdinReadPost| After reading from the stdin into the buffer
+
+ Writing
+|BufWrite| starting to write the whole buffer to a file
+|BufWritePre| starting to write the whole buffer to a file
+|BufWritePost| after writing the whole buffer to a file
+|BufWriteCmd| before writing the whole buffer to a file |Cmd-event|
+
+|FileWritePre| starting to write part of a buffer to a file
+|FileWritePost| after writing part of a buffer to a file
+|FileWriteCmd| before writing part of a buffer to a file |Cmd-event|
+
+|FileAppendPre| starting to append to a file
+|FileAppendPost| after appending to a file
+|FileAppendCmd| before appending to a file |Cmd-event|
+
+|FilterWritePre| starting to write a file for a filter command or diff
+|FilterWritePost| after writing a file for a filter command or diff
+
+ Buffers
+|BufAdd| just after adding a buffer to the buffer list
+|BufCreate| just after adding a buffer to the buffer list
+|BufDelete| before deleting a buffer from the buffer list
+|BufWipeout| before completely deleting a buffer
+
+|BufFilePre| before changing the name of the current buffer
+|BufFilePost| after changing the name of the current buffer
+
+|BufEnter| after entering a buffer
+|BufLeave| before leaving to another buffer
+|BufWinEnter| after a buffer is displayed in a window
+|BufWinLeave| before a buffer is removed from a window
+
+|BufUnload| before unloading a buffer
+|BufHidden| just after a buffer has become hidden
+|BufNew| just after creating a new buffer
+
+|SwapExists| detected an existing swap file
+
+ Options
+|FileType| when the 'filetype' option has been set
+|Syntax| when the 'syntax' option has been set
+|EncodingChanged| after the 'encoding' option has been changed
+|TermChanged| after the value of 'term' has changed
+
+ Startup and exit
+|VimEnter| after doing all the startup stuff
+|GUIEnter| after starting the GUI successfully
+|TermResponse| after the termainal response to |t_RV| is received
+
+|VimLeavePre| before exiting Vim, before writing the viminfo file
+|VimLeave| before exiting Vim, after writing the viminfo file
+
+ Various
+|FileChangedShell| Vim notices that a file changed since editing started
+|FileChangedRO| before making the first change to a read-only file
+
+|FuncUndefined| a user function is used but it isn't defined
+
+|FocusGained| Vim got input focus
+|FocusLost| Vim lost input focus
+|CursorHold| the user doesn't press a key for a while
+
+|WinEnter| after entering another window
+|WinLeave| before leaving a window
+|CmdwinEnter| after entering the command-line window
+|CmdwinLeave| before leaving the command-line window
+
+|InsertEnter| starting Insert mode
+|InsertChange| when typing <Insert> while in Insert or Replace mode
+|InsertLeave| when leaving Insert mode
+
+|ColorScheme| after loading a color scheme
+
+|RemoteReply| a reply from a server Vim was received
+
+|QuickFixCmdPre| before a quickfix command is run
+|QuickFixCmdPost| after a quickfix command is run
+
+|SessionLoadPost| after loading a session file
+
+|MenuPopup| just before showing the popup menu
+
+|User| to be used in combination with ":doautocmd"
+
+
+The alphabetical list of autocommand events: *autocmd-events-abc*
+
+ *BufCreate* *BufAdd*
+BufAdd or BufCreate Just after creating a new buffer which is
+ added to the buffer list, or adding a buffer
+ to the buffer list.
+ Also used just after a buffer in the buffer
+ list has been renamed.
+ The BufCreate event is for historic reasons.
+ NOTE: When this autocommand is executed, the
+ current buffer "%" may be different from the
+ buffer being created "<afile>".
+ *BufDelete*
+BufDelete Before deleting a buffer from the buffer list.
+ The BufUnload may be called first (if the
+ buffer was loaded).
+ Also used just before a buffer in the buffer
+ list is renamed.
+ NOTE: When this autocommand is executed, the
+ current buffer "%" may be different from the
+ buffer being deleted "<afile>".
+ *BufEnter*
+BufEnter After entering a buffer. Useful for setting
+ options for a file type. Also executed when
+ starting to edit a buffer, after the
+ BufReadPost autocommands.
+ *BufFilePost*
+BufFilePost After changing the name of the current buffer
+ with the ":file" or ":saveas" command.
+ *BufReadCmd*
+BufFilePre Before changing the name of the current buffer
+ with the ":file" or ":saveas" command.
+ *BufHidden*
+BufHidden Just after a buffer has become hidden. That
+ is, when there are no longer windows that show
+ the buffer, but the buffer is not unloaded or
+ deleted. Not used for ":qa" or ":q" when
+ exiting Vim.
+ NOTE: When this autocommand is executed, the
+ current buffer "%" may be different from the
+ buffer being unloaded "<afile>".
+ *BufLeave*
+BufLeave Before leaving to another buffer. Also when
+ leaving or closing the current window and the
+ new current window is not for the same buffer.
+ Not used for ":qa" or ":q" when exiting Vim.
+ *BufNew*
+BufNew Just after creating a new buffer. Also used
+ just after a buffer has been renamed. When
+ the buffer is added to the buffer list BufAdd
+ will be triggered too.
+ NOTE: When this autocommand is executed, the
+ current buffer "%" may be different from the
+ buffer being created "<afile>".
*BufNewFile*
BufNewFile When starting to edit a file that doesn't
exist. Can be used to read in a skeleton
file.
- *BufReadPre* *E200* *E201*
-BufReadPre When starting to edit a new buffer, before
- reading the file into the buffer. Not used
- if the file doesn't exist.
*BufRead* *BufReadPost*
BufRead or BufReadPost When starting to edit a new buffer, after
reading the file into the buffer, before
This does NOT work for ":r file". Not used
when the file doesn't exist. Also used after
successfully recovering a file.
- *BufReadCmd*
+ *BufReadPre* *E200* *E201*
BufReadCmd Before starting to edit a new buffer. Should
read the file into the buffer. |Cmd-event|
*BufFilePre*
-BufFilePre Before changing the name of the current buffer
- with the ":file" or ":saveas" command.
- *BufFilePost*
-BufFilePost After changing the name of the current buffer
- with the ":file" or ":saveas" command.
- *FileReadPre*
-FileReadPre Before reading a file with a ":read" command.
- *FileReadPost*
-FileReadPost After reading a file with a ":read" command.
- Note that Vim sets the '[ and '] marks to the
- first and last line of the read. This can be
- used to operate on the lines just read.
- *FileReadCmd*
-FileReadCmd Before reading a file with a ":read" command.
- Should do the reading of the file. |Cmd-event|
- *FilterReadPre* *E135*
-FilterReadPre Before reading a file from a filter command.
- Vim checks the pattern against the name of
- the current buffer, not the name of the
- temporary file that is the output of the
- filter command.
- Not triggered when 'shelltemp' is off.
- *FilterReadPost*
-FilterReadPost After reading a file from a filter command.
- Vim checks the pattern against the name of
- the current buffer as with FilterReadPre.
- Not triggered when 'shelltemp' is off.
- *FileType*
-FileType When the 'filetype' option has been set.
- <afile> can be used for the name of the file
- where this option was set, and <amatch> for
- the new value of 'filetype'.
- See |filetypes|.
- *Syntax*
-Syntax When the 'syntax' option has been set.
- <afile> can be used for the name of the file
- where this option was set, and <amatch> for
- the new value of 'syntax'.
- See |:syn-on|.
- *StdinReadPre*
-StdinReadPre Before reading from stdin into the buffer.
- Only used when the "-" argument was used when
- Vim was started |--|.
- *StdinReadPost*
-StdinReadPost After reading from the stdin into the buffer,
- before executing the modelines. Only used
- when the "-" argument was used when Vim was
- started |--|.
- *BufWrite* *BufWritePre*
-BufWrite or BufWritePre Before writing the whole buffer to a file.
- *BufWritePost*
-BufWritePost After writing the whole buffer to a file
- (should undo the commands for BufWritePre).
- *BufWriteCmd*
-BufWriteCmd Before writing the whole buffer to a file.
- Should do the writing of the file and reset
- 'modified' if successful, unless '+' is in
- 'cpo' and writing to another file |cpo-+|.
- The buffer contents should not be changed.
- |Cmd-event|
- *FileWritePre*
-FileWritePre Before writing to a file, when not writing the
- whole buffer. Use the '[ and '] marks for the
- range of lines.
- *FileWritePost*
-FileWritePost After writing to a file, when not writing the
- whole buffer.
- *FileWriteCmd*
-FileWriteCmd Before writing to a file, when not writing the
- whole buffer. Should do the writing to the
- file. Should not change the buffer. Use the
- '[ and '] marks for the range of lines.
- |Cmd-event|
- *FileAppendPre*
-FileAppendPre Before appending to a file. Use the '[ and ']
- marks for the range of lines.
- *FileAppendPost*
-FileAppendPost After appending to a file.
- *FileAppendCmd*
-FileAppendCmd Before appending to a file. Should do the
- appending to the file. Use the '[ and ']
- marks for the range of lines.|Cmd-event|
- *FilterWritePre*
-FilterWritePre Before writing a file for a filter command or
- making a diff.
- Vim checks the pattern against the name of
- the current buffer, not the name of the
- temporary file that is the output of the
- filter command.
- Not triggered when 'shelltemp' is off.
- *FilterWritePost*
-FilterWritePost After writing a file for a filter command or
- making a diff.
- Vim checks the pattern against the name of
- the current buffer as with FilterWritePre.
- Not triggered when 'shelltemp' is off.
- *FileChangedShell*
-FileChangedShell When Vim notices that the modification time of
- a file has changed since editing started.
- Also when the file attributes of the file
- change. |timestamp|
- Mostly triggered after executing a shell
- command, but also with a |:checktime| command
- or when Gvim regains input focus.
- This autocommand is triggered for each changed
- file. It is not used when 'autoread' is set
- and the buffer was not changed. If a
- FileChangedShell autocommand is present the
- warning message and prompt is not given.
- This is useful for reloading related buffers
- which are affected by a single command.
- The |v:fcs_reason| variable is set to indicate
- what happened and |v:fcs_choice| can be used
- to tell Vim what to do next.
+BufReadPre When starting to edit a new buffer, before
+ reading the file into the buffer. Not used
+ if the file doesn't exist.
+ *BufUnload*
+BufUnload Before unloading a buffer. This is when the
+ text in the buffer is going to be freed. This
+ may be after a BufWritePost and before a
+ BufDelete. Also used for all buffers that are
+ loaded when Vim is going to exit.
NOTE: When this autocommand is executed, the
current buffer "%" may be different from the
- buffer that was changed "<afile>".
- NOTE: The commands must not change the current
- buffer, jump to another buffer or delete a
- buffer. *E246*
- NOTE: This event never nests, to avoid an
- endless loop. This means that while executing
- commands for the FileChangedShell event no
- other FileChangedShell event will be
- triggered.
- *FileChangedRO*
-FileChangedRO Before making the first change to a read-only
- file. Can be used to check-out the file from
- a source control system. Not triggered when
- the change was caused by an autocommand.
- This event is triggered when making the first
- change in a buffer or the first change after
- 'readonly' was set,
- just before the change is applied to the text.
- WARNING: If the autocommand moves the cursor
- the effect of the change is undefined.
- *FocusGained*
-FocusGained When Vim got input focus. Only for the GUI
- version and a few console versions where this
- can be detected.
- *FocusLost*
-FocusLost When Vim lost input focus. Only for the GUI
- version and a few console versions where this
- can be detected. May also happen when a
- dialog pops up.
- *FuncUndefined*
-FuncUndefined When a user function is used but it isn't
- defined. Useful for defining a function only
- when it's used. Both <amatch> and <afile> are
- set to the name of the function.
- See |autoload-functions|.
- *CursorHold*
-CursorHold When the user doesn't press a key for the time
- specified with 'updatetime'. Not re-triggered
- until the user has pressed a key (i.e. doesn't
- fire every 'updatetime' ms if you leave Vim to
- make some coffee. :) See |CursorHold-example|
- for previewing tags.
- This event is only triggered in Normal mode.
- Note: Interactive commands cannot be used for
- this event. There is no hit-enter prompt,
- the screen is updated directly (when needed).
- Note: In the future there will probably be
- another option to set the time.
- Hint: to force an update of the status lines
- use: >
- :let &ro = &ro
-< {only on Amiga, Unix, Win32, MSDOS and all GUI
- versions}
- *BufEnter*
-BufEnter After entering a buffer. Useful for setting
- options for a file type. Also executed when
- starting to edit a buffer, after the
- BufReadPost autocommands.
- *BufLeave*
-BufLeave Before leaving to another buffer. Also when
- leaving or closing the current window and the
- new current window is not for the same buffer.
- Not used for ":qa" or ":q" when exiting Vim.
+ buffer being unloaded "<afile>".
*BufWinEnter*
BufWinEnter After a buffer is displayed in a window. This
can be when the buffer is loaded (after
NOTE: When this autocommand is executed, the
current buffer "%" may be different from the
buffer being unloaded "<afile>".
- *BufUnload*
-BufUnload Before unloading a buffer. This is when the
- text in the buffer is going to be freed. This
- may be after a BufWritePost and before a
- BufDelete. Also used for all buffers that are
- loaded when Vim is going to exit.
- NOTE: When this autocommand is executed, the
- current buffer "%" may be different from the
- buffer being unloaded "<afile>".
- *BufHidden*
-BufHidden Just after a buffer has become hidden. That
- is, when there are no longer windows that show
- the buffer, but the buffer is not unloaded or
- deleted. Not used for ":qa" or ":q" when
- exiting Vim.
- NOTE: When this autocommand is executed, the
- current buffer "%" may be different from the
- buffer being unloaded "<afile>".
- *BufNew*
-BufNew Just after creating a new buffer. Also used
- just after a buffer has been renamed. When
- the buffer is added to the buffer list BufAdd
- will be triggered too.
- NOTE: When this autocommand is executed, the
- current buffer "%" may be different from the
- buffer being created "<afile>".
- *BufCreate* *BufAdd*
-BufAdd or BufCreate Just after creating a new buffer which is
- added to the buffer list, or adding a buffer
- to the buffer list.
- Also used just after a buffer in the buffer
- list has been renamed.
- The BufCreate event is for historic reasons.
- NOTE: When this autocommand is executed, the
- current buffer "%" may be different from the
- buffer being created "<afile>".
- *BufDelete*
-BufDelete Before deleting a buffer from the buffer list.
- The BufUnload may be called first (if the
- buffer was loaded).
- Also used just before a buffer in the buffer
- list is renamed.
- NOTE: When this autocommand is executed, the
- current buffer "%" may be different from the
- buffer being deleted "<afile>".
*BufWipeout*
BufWipeout Before completely deleting a buffer. The
BufUnload and BufDelete events may be called
NOTE: When this autocommand is executed, the
current buffer "%" may be different from the
buffer being deleted "<afile>".
- *WinEnter*
-WinEnter After entering another window. Not done for
- the first window, when Vim has just started.
- Useful for setting the window height.
- If the window is for another buffer, Vim
- executes the BufEnter autocommands after the
- WinEnter autocommands.
- Note: When using ":split fname" the WinEnter
- event is triggered after the split but before
- the file "fname" is loaded.
- *WinLeave*
-WinLeave Before leaving a window. If the window to be
- entered next is for a different buffer, Vim
- executes the BufLeave autocommands before the
- WinLeave autocommands (but not for ":new").
- Not used for ":qa" or ":q" when exiting Vim.
+ *BufWrite* *BufWritePre*
+BufWrite or BufWritePre Before writing the whole buffer to a file.
+ *BufWriteCmd*
+BufWriteCmd Before writing the whole buffer to a file.
+ Should do the writing of the file and reset
+ 'modified' if successful, unless '+' is in
+ 'cpo' and writing to another file |cpo-+|.
+ The buffer contents should not be changed.
+ |Cmd-event|
+ *BufWritePost*
+BufWritePost After writing the whole buffer to a file
+ (should undo the commands for BufWritePre).
*CmdwinEnter*
CmdwinEnter After entering the command-line window.
Useful for setting options specifically for
<afile> is set to a single character,
indicating the type of command-line.
|cmdwin-char|
+ *ColorScheme*
+ColorScheme After loading a color scheme. |:colorscheme|
+ *CursorHold*
+CursorHold When the user doesn't press a key for the time
+ specified with 'updatetime'. Not re-triggered
+ until the user has pressed a key (i.e. doesn't
+ fire every 'updatetime' ms if you leave Vim to
+ make some coffee. :) See |CursorHold-example|
+ for previewing tags.
+ This event is only triggered in Normal mode.
+ Note: Interactive commands cannot be used for
+ this event. There is no hit-enter prompt,
+ the screen is updated directly (when needed).
+ Note: In the future there will probably be
+ another option to set the time.
+ Hint: to force an update of the status lines
+ use: >
+ :let &ro = &ro
+< {only on Amiga, Unix, Win32, MSDOS and all GUI
+ versions}
+ *EncodingChanged*
+EncodingChanged Fires off after the 'encoding' option has been
+ changed. Useful to set up fonts, for example.
+ *FileAppendCmd*
+FileAppendCmd Before appending to a file. Should do the
+ appending to the file. Use the '[ and ']
+ marks for the range of lines.|Cmd-event|
+ *FileAppendPost*
+FileAppendPost After appending to a file.
+ *FileAppendPre*
+FileAppendPre Before appending to a file. Use the '[ and ']
+ marks for the range of lines.
+ *FileChangedRO*
+FileChangedRO Before making the first change to a read-only
+ file. Can be used to check-out the file from
+ a source control system. Not triggered when
+ the change was caused by an autocommand.
+ This event is triggered when making the first
+ change in a buffer or the first change after
+ 'readonly' was set,
+ just before the change is applied to the text.
+ WARNING: If the autocommand moves the cursor
+ the effect of the change is undefined.
+ *FileChangedShell*
+FileChangedShell When Vim notices that the modification time of
+ a file has changed since editing started.
+ Also when the file attributes of the file
+ change. |timestamp|
+ Mostly triggered after executing a shell
+ command, but also with a |:checktime| command
+ or when Gvim regains input focus.
+ This autocommand is triggered for each changed
+ file. It is not used when 'autoread' is set
+ and the buffer was not changed. If a
+ FileChangedShell autocommand is present the
+ warning message and prompt is not given.
+ This is useful for reloading related buffers
+ which are affected by a single command.
+ The |v:fcs_reason| variable is set to indicate
+ what happened and |v:fcs_choice| can be used
+ to tell Vim what to do next.
+ NOTE: When this autocommand is executed, the
+ current buffer "%" may be different from the
+ buffer that was changed "<afile>".
+ NOTE: The commands must not change the current
+ buffer, jump to another buffer or delete a
+ buffer. *E246*
+ NOTE: This event never nests, to avoid an
+ endless loop. This means that while executing
+ commands for the FileChangedShell event no
+ other FileChangedShell event will be
+ triggered.
+ *FileEncoding*
+FileEncoding Obsolete. It still works and is equivalent
+ to |EncodingChanged|.
+ *FileReadCmd*
+FileReadCmd Before reading a file with a ":read" command.
+ Should do the reading of the file. |Cmd-event|
+ *FileReadPost*
+FileReadPost After reading a file with a ":read" command.
+ Note that Vim sets the '[ and '] marks to the
+ first and last line of the read. This can be
+ used to operate on the lines just read.
+ *FileReadPre*
+FileReadPre Before reading a file with a ":read" command.
+ *FileType*
+FileType When the 'filetype' option has been set.
+ <afile> can be used for the name of the file
+ where this option was set, and <amatch> for
+ the new value of 'filetype'.
+ See |filetypes|.
+ *FileWriteCmd*
+FileWriteCmd Before writing to a file, when not writing the
+ whole buffer. Should do the writing to the
+ file. Should not change the buffer. Use the
+ '[ and '] marks for the range of lines.
+ |Cmd-event|
+ *FileWritePost*
+FileWritePost After writing to a file, when not writing the
+ whole buffer.
+ *FileWritePre*
+FileWritePre Before writing to a file, when not writing the
+ whole buffer. Use the '[ and '] marks for the
+ range of lines.
+ *FilterReadPost*
+FilterReadPost After reading a file from a filter command.
+ Vim checks the pattern against the name of
+ the current buffer as with FilterReadPre.
+ Not triggered when 'shelltemp' is off.
+ *FilterReadPre* *E135*
+FilterReadPre Before reading a file from a filter command.
+ Vim checks the pattern against the name of
+ the current buffer, not the name of the
+ temporary file that is the output of the
+ filter command.
+ Not triggered when 'shelltemp' is off.
+ *FilterWritePost*
+FilterWritePost After writing a file for a filter command or
+ making a diff.
+ Vim checks the pattern against the name of
+ the current buffer as with FilterWritePre.
+ Not triggered when 'shelltemp' is off.
+ *FilterWritePre*
+FilterWritePre Before writing a file for a filter command or
+ making a diff.
+ Vim checks the pattern against the name of
+ the current buffer, not the name of the
+ temporary file that is the output of the
+ filter command.
+ Not triggered when 'shelltemp' is off.
+ *FocusGained*
+FocusGained When Vim got input focus. Only for the GUI
+ version and a few console versions where this
+ can be detected.
+ *FocusLost*
+FocusLost When Vim lost input focus. Only for the GUI
+ version and a few console versions where this
+ can be detected. May also happen when a
+ dialog pops up.
+ *FuncUndefined*
+FuncUndefined When a user function is used but it isn't
+ defined. Useful for defining a function only
+ when it's used. Both <amatch> and <afile> are
+ set to the name of the function.
+ See |autoload-functions|.
*GUIEnter*
GUIEnter After starting the GUI successfully, and after
opening the window. It is triggered before
VimEnter when using gvim. Can be used to
position the window from a .gvimrc file: >
:autocmd GUIEnter * winpos 100 50
-< *VimEnter*
-VimEnter After doing all the startup stuff, including
- loading .vimrc files, executing the "-c cmd"
- arguments, creating all windows and loading
- the buffers in them.
- *VimLeavePre*
-VimLeavePre Before exiting Vim, just before writing the
- .viminfo file. This is executed only once,
- if there is a match with the name of what
- happens to be the current buffer when exiting.
- Mostly useful with a "*" pattern. >
- :autocmd VimLeavePre * call CleanupStuff()
-< To detect an abnormal exit use |v:dying|.
- *VimLeave*
-VimLeave Before exiting Vim, just after writing the
- .viminfo file. Executed only once, like
- VimLeavePre.
- To detect an abnormal exit use |v:dying|.
- *EncodingChanged*
-EncodingChanged Fires off after the 'encoding' option has been
- changed. Useful to set up fonts, for example.
+< *InsertChange*
+InsertChange When typing <Insert> while in Insert or
+ Replace mode. The |v:insertmode| variable
+ indicates the new mode.
+ Be careful not to move the cursor or do
+ anything else that the user does not expect.
*InsertEnter*
InsertEnter When starting Insert mode. Also for Replace
mode and Virtual Replace mode. The
|v:insertmode| variable indicates the mode.
Be careful not to move the cursor or do
- anything else that the user does not expect.
- *InsertChange*
-InsertChange When typing <Insert> while in Insert or
- Replace mode. The |v:insertmode| variable
- indicates the new mode.
- Be careful not to move the cursor or do
anything else that the user does not expect.
*InsertLeave*
InsertLeave When leaving Insert mode. Also when using
CTRL-O |i_CTRL-O|. But not for |i_CTRL-C|.
- *FileEncoding*
-FileEncoding Obsolete. It still works and is equivalent
- to |EncodingChanged|.
- *ColorScheme*
-ColorScheme After loading a color scheme. |:colorscheme|
+ *MenuPopup*
+MenuPopup Just before showing the popup menu (under the
+ right mouse button). Useful for adjusting the
+ menu for what is under the cursor or mouse
+ pointer.
+ The pattern is matched against a single
+ character representing the mode:
+ n Normal
+ v Visual
+ o Operator-pending
+ i Insert
+ c Commmand line
+ *QuickFixCmdPre*
+QuickFixCmdPre Before a quickfix command is run (|:make|,
+ |:grep|, |:grepadd|, |:vimgrep|,
+ |:vimgrepadd|). The pattern is matched against
+ the command being run. When |:grep| is used
+ but 'grepprg' is set to "internal" it still
+ matches "grep".
+ This command cannot be used to set the
+ 'makeprg' and 'grepprg' variables.
+ If this command causes an error, the quickfix
+ command is not executed.
+ *QuickFixCmdPost*
+QuickFixCmdPost Like QuickFixCmdPre, but after a quickfix
+ command is run.
*RemoteReply*
RemoteReply When a reply from a Vim that functions as
server was received |server2client()|.
Note that even if an autocommand is defined,
the reply should be read with |remote_read()|
to consume it.
+ *SessionLoadPost*
+SessionLoadPost After loading the session file created using
+ the |:mksession| command.
+ *StdinReadPost*
+StdinReadPost After reading from the stdin into the buffer,
+ before executing the modelines. Only used
+ when the "-" argument was used when Vim was
+ started |--|.
+ *StdinReadPre*
+StdinReadPre Before reading from stdin into the buffer.
+ Only used when the "-" argument was used when
+ Vim was started |--|.
+ *SwapExists*
+SwapExists Detected an existing swap file when starting
+ to edit a file. Only when it is possible to
+ select a way to handle the situation, when Vim
+ would ask the user what to do.
+ The |v:swapname| variable holds the name of
+ the swap file found.
+ The |v:swapchoice| variable should be set to
+ a string with one character to tell what Vim
+ should do next:
+ 'o' open read-only
+ 'e' edit the file anyway
+ 'r' recover
+ 'd' delete the swap file
+ 'q' quit, don't edit the file
+ 'a' abort, like hitting CTRL-C
+ When set to an empty string the user will be
+ asked, as if there was no SwapExists autocmd.
+ Note: Do not try to change the buffer, the
+ results are unpredictable.
+ *Syntax*
+Syntax When the 'syntax' option has been set.
+ <afile> can be used for the name of the file
+ where this option was set, and <amatch> for
+ the new value of 'syntax'.
+ See |:syn-on|.
*TermChanged*
TermChanged After the value of 'term' has changed. Useful
for re-loading the syntax file to update the
the terminal. The value of |v:termresponse|
can be used to do things depending on the
terminal version.
-QuickFixCmdPre *QuickFixCmdPre*
- Before a quickfix command is run (|:make|,
- |:grep|, |:grepadd|, |:vimgrep|,
- |:vimgrepadd|). The pattern is matched against
- the command being run. When |:grep| is used
- but 'grepprg' is set to "internal" it still
- matches "grep".
- This command cannot be used to set the
- 'makeprg' and 'grepprg' variables.
- If this command causes an error, the quickfix
- command is not executed.
-QuickFixCmdPost *QuickFixCmdPost*
- like QuickFixCmdPre, but after a quickfix
- command is run.
- *SessionLoadPost*
-SessionLoadPost After loading the session file created using
- the |:mksession| command.
- *MenuPopup*
-MenuPopup Just before showing the popup menu (under the
- right mouse button). Useful for adjusting the
- menu for what is under the cursor or mouse
- pointer.
- The pattern is matched against a single
- character representing the mode:
- n Normal
- v Visual
- o Operator-pending
- i Insert
- c Commmand line
- *UserGettingBored*
-UserGettingBored When the user hits CTRL-C. Just kidding! :-)
*User*
User Never executed automatically. To be used for
autocommands that are only executed with
":doautocmd".
-
-You can specify a comma-separated list of event names. No white space can be
-used in this list. The command applies to all the events in the list.
-
-For READING FILES there are four kinds of events possible:
- BufNewFile starting to edit a non-existent file
- BufReadPre BufReadPost starting to edit an existing file
- FilterReadPre FilterReadPost read the temp file with filter output
- FileReadPre FileReadPost any other file read
-Vim uses only one of these four kinds when reading a file. The "Pre" and
-"Post" events are both triggered, before and after reading the file.
-
-Note that the autocommands for the *ReadPre events and all the Filter events
-are not allowed to change the current buffer (you will get an error message if
-this happens). This is to prevent the file to be read into the wrong buffer.
-
-Note that the 'modified' flag is reset AFTER executing the BufReadPost
-and BufNewFile autocommands. But when the 'modified' option was set by the
-autocommands, this doesn't happen.
-
-You can use the 'eventignore' option to ignore a number of events or all
-events.
+ *UserGettingBored*
+UserGettingBored When the user hits CTRL-C. Just kidding! :-)
+ *VimEnter*
+VimEnter After doing all the startup stuff, including
+ loading .vimrc files, executing the "-c cmd"
+ arguments, creating all windows and loading
+ the buffers in them.
+ *VimLeave*
+VimLeave Before exiting Vim, just after writing the
+ .viminfo file. Executed only once, like
+ VimLeavePre.
+ To detect an abnormal exit use |v:dying|.
+ *VimLeavePre*
+VimLeavePre Before exiting Vim, just before writing the
+ .viminfo file. This is executed only once,
+ if there is a match with the name of what
+ happens to be the current buffer when exiting.
+ Mostly useful with a "*" pattern. >
+ :autocmd VimLeavePre * call CleanupStuff()
+< To detect an abnormal exit use |v:dying|.
+ *WinEnter*
+WinEnter After entering another window. Not done for
+ the first window, when Vim has just started.
+ Useful for setting the window height.
+ If the window is for another buffer, Vim
+ executes the BufEnter autocommands after the
+ WinEnter autocommands.
+ Note: When using ":split fname" the WinEnter
+ event is triggered after the split but before
+ the file "fname" is loaded.
+ *WinLeave*
+WinLeave Before leaving a window. If the window to be
+ entered next is for a different buffer, Vim
+ executes the BufLeave autocommands before the
+ WinLeave autocommands (but not for ":new").
+ Not used for ":qa" or ":q" when exiting Vim.
==============================================================================
6. Patterns *autocmd-patterns* *{pat}*