Vim:AutoCmd
lastmod 2018-09-18created 2018-09-181 edits
vim can run commands automatically when certain events occur, and these are specified with au[tocmd].
Reading/starting buffers
- BufNewFile: starting to edit a newly created file
- BufReadPre: before reading a file, starting to edit a new buffer
- BufRead: after reading a file, editing a new buffer
- BufReadPost: same as above, after reading a file, editing a new buffer (what's the difference?)
- BufReadCmd: when a command to start a new buffer is received
Reading files
- FileReadPre: just before reading a new file with the
:readcommand - FileReadPost: just after reading a new file with the
:readcommand - FileReadCmd: when the
:readcommand is received
Writing the whole buffer
- BufWrite: when starting to write the whole buffer to a file
- BufWritePre: when starting to write the whole buffer to a file
- BufWritePost: after writing the whole buffer to a file
- BufWriteCmd: when a write command is received, before writing to the file
Writing part of a buffer
- FileWritePre: starting to write part of a buffer to a file
- FileWritePre: starting to write part of a buffer to a file
- FileWriteCmd: when a command to write part of a buffer to a file is received
- FileAppendPre: when appending content to the end of a file
- FileAppendPost: after appending content to the end of a file
- FileAppendCmd: when an append-to-file command is received
Buffers
- BufAdd: just after a new buffer is added to the buffer list
- BufCreate: just after a new buffer is created and added to the buffer list
- BufDelete: before a buffer is deleted from the buffer list
- BufWipeout: just before a buffer is completely deleted
- BufFilePre: just before the current buffer is renamed
- BufFilePost: just after the current buffer is renamed
- BufEnter: just after entering a buffer
- BufLeave: just before leaving a buffer for another buffer
- BufWinEnter: after a buffer is displayed in a window
- BufWinLeave: just before a buffer is removed from a window
- BufUnload: before a buffer is unloaded
- BufHidden: just after a buffer is hidden
- BufNew: just after a new buffer is created
Swap
- SwapExists: when a swap file exists
Options
- FileType: when the
filetypeoption is set - Syntax: when the
syntaxoption is set - EncodingChanged: when the
encodingoption is set - TermChanged: when the value of
termchanges
Startup and exit
- VimEnter: after vim starts
- GUIEnter: after the GUI has started successfully
- TermResponse: after receiving the terminal response
t_RV - VimLeavePre: just before vim exits, before writing the
viminfofile - VimLeave: just before exiting, after writing the
viminfofile
Other
- FileChangedShell: when vim detects that a file has changed after it was edited in Vim
- FileChangedShellPost: when a file has changed after editing started
- FileChangedRO: when about to start changing a read-only file
- ShellCmdPost: after running a shell command
- ShellFilterPost: after filtering with a shell command
- FuncUndefined: when an undefined user function is called
- SpellFileMissing: when trying to use a nonexistent grammar file
- SourcePre: just before sourcing a vim script
- SourceCmd: when sourcing a vim script in command mode
- VimResized: when the vim window size changes
- FocusGained: when vim gains input focus
- FocusLost: when input focus is lost
- CursorHold: when nothing is pressed for a certain amount of time
- CursorHoldI: when no key is pressed for a certain amount of time in insert mode
- CursorMoved: when the cursor moves in normal mode
- CursorMovedI: when the cursor moves in insert mode
- WinEnter: when entering another window
- WinLeave: when leaving a window
- TabEnter: when entering a particular tab in the vim window
- TabLeave: when leaving a particular tab
- ColorScheme: when the color scheme changes
- RemoteReply: when vim receives a reply from a server
- QuickFixCmdPre: before a
quickfixcommand runs - QuickFixCmdPost: after a
quickfixcommand runs - SessionLoadPost: after a session file finishes loading
- MenuPopup: after showing a popup menu
- User: used with
:doautocmd