robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
77.8 KiB2123 linesraw
1*autocmd.txt*   Nvim
2
3
4		  VIM REFERENCE MANUAL	  by Bram Moolenaar
5
6
7Automatic commands					*autocmd* *autocommand*
8
9For a basic explanation, see section |40.3| in the user manual.
10
11				      Type |gO| to see the table of contents.
12
13==============================================================================
141. Introduction						*autocmd-intro*
15
16You can specify commands to be executed automatically when reading or writing
17a file, when entering or leaving a buffer or window, and when exiting Vim.
18For example, you can create an autocommand to set the 'cindent' option for
19files matching `*.c`.  You can also use autocommands to implement advanced
20features, such as editing compressed files (see |gzip-example|).  The usual
21place to put autocommands is in your vimrc file.
22
23				*E203* *E204* *E143* *E855* *E937* *E952* *E1312*
24WARNING: Using autocommands is very powerful, and may lead to unexpected side
25effects.  Be careful not to destroy your text.
26- It's a good idea to do some testing on an expendable copy of a file first.
27  For example: If you use autocommands to decompress a file when starting to
28  edit it, make sure that the autocommands for compressing when writing work
29  correctly.
30- Be prepared for an error halfway through (e.g., disk full).  Vim will mostly
31  be able to undo the changes to the buffer, but you may have to clean up the
32  changes to other files by hand (e.g., compress a file that has been
33  decompressed).
34- If the BufRead* events allow you to edit a compressed file, the FileRead*
35  events should do the same (this makes recovery possible in some rare cases).
36  It's a good idea to use the same autocommands for the File* and Buf* events
37  when possible.
38
39==============================================================================
402. Defining autocommands				*autocmd-define*
41
42Use |nvim_create_autocmd()| to define an event handler from Lua.
43
44Vimscript commands are described below.
45
46							*:au* *:autocmd*
47:au[tocmd] [group] {event} {aupat} [++once] [++nested] {cmd}
48			Add {cmd} to the list of commands that Vim will
49			execute automatically on {event} for a file matching
50			{aupat} |autocmd-pattern|.
51			Here {event} cannot be "*".  *E1155*
52			Note: A quote character is seen as argument to the
53			:autocmd and won't start a comment.
54			Nvim always adds {cmd} after existing autocommands so
55			they execute in the order in which they were defined.
56			See |autocmd-nested| for [++nested].
57							*autocmd-once*
58			If [++once] is supplied the command is executed once
59			(per {event}, which may be a comma-separated list),
60			then removed ("one shot").
61
62The special pattern <buffer> or <buffer=N> defines a buffer-local autocommand.
63See |autocmd-buflocal|.
64
65Note: The ":autocmd" command can only be followed by another command when the
66"|" appears where the pattern is expected.  This works: >
67	:augroup mine | au! BufRead | augroup END
68But this sees "augroup" as part of the defined command: >
69	:augroup mine | au! BufRead * | augroup END
70	:augroup mine | au BufRead * set tw=70 | augroup END
71Instead you can put the group name into the command: >
72	:au! mine BufRead *
73	:au mine BufRead * set tw=70
74Or use `:execute`: >
75	:augroup mine | exe "au! BufRead *" | augroup END
76	:augroup mine | exe "au BufRead * set tw=70" | augroup END
77
78<							*autocmd-expand*
79Note that special characters (e.g., "%", "<cword>") in the ":autocmd"
80arguments are not expanded when the autocommand is defined.  These will be
81expanded when the Event is recognized, and the {cmd} is executed.  The only
82exception is that "<sfile>" (unlike "<script>") is expanded when the autocmd
83is defined.  Example:
84>
85	:au BufNewFile,BufRead *.html so <sfile>:h/html.vim
86
87Here Vim expands <sfile> to the name of the file containing this line.
88However, <sfile> works differently in a function, in which case it's better to
89use `:execute` with <script> to achieve the same purpose:
90>
91	:exe $'au BufNewFile,BufRead *.html so {expand("<script>:h")}/html.vim'
92
93`:autocmd` adds to the list of autocommands regardless of whether they are
94already present.  When your .vimrc file is sourced twice, the autocommands
95will appear twice.  To avoid this, define your autocommands in a group, so
96that you can easily clear them: >
97
98	augroup vimrc
99	  " Remove all vimrc autocommands
100	  autocmd!
101	  au BufNewFile,BufRead *.html so <sfile>:h/html.vim
102	augroup END
103
104If you don't want to remove all autocommands, you can instead use a variable
105to ensure that Vim includes the autocommands only once: >
106
107	:if !exists("autocommands_loaded")
108	:  let autocommands_loaded = 1
109	:  au ...
110	:endif
111
112When the [group] argument is not given, Vim uses the current group (as defined
113with ":augroup"); otherwise, Vim uses the group defined with [group].  Note
114that [group] must have been defined before.  You cannot define a new group
115with ":au group ..."; use ":augroup" for that.
116
117While testing autocommands, you might find the 'verbose' option to be useful: >
118	:set verbose=9
119This setting makes Vim echo the autocommands as it executes them.
120
121When defining an autocommand in a script, it will be able to call functions
122local to the script and use mappings local to the script.  When the event is
123triggered and the command executed, it will run in the context of the script
124it was defined in.  This matters if |<SID>| is used in a command.
125
126When executing the commands, the message from one command overwrites a
127previous message.  This is different from when executing the commands
128manually.  Mostly the screen will not scroll up, thus there is no hit-enter
129prompt.  When one command outputs two messages this can happen anyway.
130
131==============================================================================
1323. Removing autocommands			*autocmd!* *autocmd-remove*
133
134Using Lua, these functions remove autocmds and autocmd groups:
135
136- |nvim_del_autocmd()|
137- |nvim_del_augroup_by_id()|
138- |nvim_del_augroup_by_name()|
139
140Vimscript commands are described below.
141
142:au[tocmd]! [group] {event} {aupat} [++once] [++nested] {cmd}
143			Remove all autocommands associated with {event} and
144			{aupat}, and add the command {cmd}.
145			See |autocmd-once| for [++once].
146			See |autocmd-nested| for [++nested].
147
148:au[tocmd]! [group] {event} {aupat}
149			Remove all autocommands associated with {event} and
150			{aupat}.
151
152:au[tocmd]! [group] * {aupat}
153			Remove all autocommands associated with {aupat} for
154			all events.
155
156:au[tocmd]! [group] {event}
157			Remove ALL autocommands for {event}.
158			Warning: You should not do this without a group for
159			|BufRead| and other common events, it can break
160			plugins, syntax highlighting, etc.
161
162:au[tocmd]! [group]	Remove ALL autocommands.
163			Note: a quote will be seen as argument to the :autocmd
164			and won't start a comment.
165			Warning: You should normally not do this without a
166			group, it breaks plugins, syntax highlighting, etc.
167
168When the [group] argument is not given, Vim uses the current group (as defined
169with ":augroup"); otherwise, Vim uses the group defined with [group].
170
171==============================================================================
1724. Listing autocommands					*autocmd-list*
173
174:au[tocmd] [group] {event} {aupat}
175			Show the autocommands associated with {event} and
176			{aupat}.
177
178:au[tocmd] [group] * {aupat}
179			Show the autocommands associated with {aupat} for all
180			events.
181
182:au[tocmd] [group] {event}
183			Show all autocommands for {event}.
184
185:au[tocmd] [group]	Show all autocommands.
186
187If you provide the [group] argument, Vim lists only the autocommands for
188[group]; otherwise, Vim lists the autocommands for ALL groups.  Note that this
189argument behavior differs from that for defining and removing autocommands.
190
191In order to list buffer-local autocommands, use a pattern in the form <buffer>
192or <buffer=N>.  See |autocmd-buflocal|.
193
194							*:autocmd-verbose*
195When 'verbose' is non-zero, listing an autocommand will also display where it
196was last defined.  Example: >
197
198    :verbose autocmd BufEnter
199    FileExplorer  BufEnter
200	*	  call s:LocalBrowse(expand("<amatch>"))
201	    Last set from /usr/share/vim/vim-7.0/plugin/NetrwPlugin.vim
202<
203See |:verbose-cmd| for more information.
204
205==============================================================================
2065. Events					*autocmd-events* *E215* *E216*
207
208You can specify a comma-separated list of event names.  No white space can be
209used in this list.  The command applies to all the events in the list.
210
211For READING FILES there are four kinds of events possible:
212	BufNewFile			starting to edit a non-existent file
213	BufReadPre	BufReadPost	starting to edit an existing file
214	FilterReadPre	FilterReadPost	read the temp file with filter output
215	FileReadPre	FileReadPost	any other file read
216Vim uses only one of these four kinds when reading a file.  The "Pre" and
217"Post" events are both triggered, before and after reading the file.
218
219Note that the autocommands for the "*ReadPre" events and all the Filter events
220are not allowed to change the current buffer (you will get an error message if
221this happens).  This is to prevent the file to be read into the wrong buffer.
222
223Note that the 'modified' flag is reset AFTER executing the BufReadPost
224and BufNewFile autocommands.  But when the 'modified' option was set by the
225autocommands, this doesn't happen.
226
227You can use the 'eventignore' option to ignore a number of events or all
228events.
229
230							*event-data-types*
231Events that provide |event-data| have a corresponding `vim.event.<name>.data`
232type defined in `runtime/lua/vim/_meta/events.lua`. If you have Lua LSP
233enabled, you can annotate your handler to get type-checking and completion: >lua
234
235    vim.api.nvim_create_autocmd('LspAttach', {
236      ---@param ev {data: vim.event.lspattach.data}
237      callback = function(ev)
238        local client = vim.lsp.get_client_by_id(ev.data.client_id)
239      end,
240    })
241<
242							*events* *{event}*
243Nvim recognizes the following events.  Names are case-insensitive.
244
245							*BufAdd*
246BufAdd				After adding a new buffer or existing unlisted
247				buffer to the buffer list (except during
248				startup, see |VimEnter|), or renaming a listed
249				buffer.
250				Before |BufEnter|.
251				NOTE: Current buffer "%" is not the target
252				buffer "<afile>", "<abuf>". |<buffer=abuf>|
253
254							*BufDelete*
255BufDelete			Before deleting a buffer from the buffer list.
256				The BufUnload may be called first (if the
257				buffer was loaded).
258				Also used just before a buffer in the buffer
259				list is renamed.
260				NOTE: Current buffer "%" is not the target
261				buffer "<afile>", "<abuf>". |<buffer=abuf>|
262				Do not change to another buffer.
263
264							*BufEnter*
265BufEnter			After entering (visiting, switching-to) a new
266				or existing buffer. Useful for setting
267				filetype options.  Compare |BufNew| which
268				does not trigger for existing buffers.
269				After |BufAdd|.
270				After |BufReadPost|.
271
272							*BufFilePost*
273BufFilePost			After changing the name of the current buffer
274				with the ":file" or ":saveas" command.
275
276							*BufFilePre*
277BufFilePre			Before changing the name of the current buffer
278				with the ":file" or ":saveas" command.
279
280							*BufHidden*
281BufHidden			Before a buffer becomes hidden: when there are
282				no longer windows that show the buffer, but
283				the buffer is not unloaded or deleted.
284
285				Not used for ":qa" or ":q" when exiting Vim.
286				NOTE: Current buffer "%" is not the target
287				buffer "<afile>", "<abuf>". |<buffer=abuf>|
288
289							*BufLeave*
290BufLeave			Before leaving to another buffer.  Also when
291				leaving or closing the current window and the
292				new current window is not for the same buffer.
293
294				Not used for ":qa" or ":q" when exiting Vim.
295
296							*BufNew*
297BufNew				After creating a new buffer (except during
298				startup, see |VimEnter|) or renaming an
299				existing buffer. Unlike |BufEnter|, visiting
300				(switching to) an existing buffer will not
301				trigger this again.
302				NOTE: Current buffer "%" is not the target
303				buffer "<afile>", "<abuf>". |<buffer=abuf>|
304				See also |BufAdd|, |BufNewFile|.
305
306							*BufNewFile*
307BufNewFile			When starting to edit a file that doesn't
308				exist.  Can be used to read in a skeleton
309				file.
310
311						*BufRead* *BufReadPost*
312BufRead or BufReadPost		When starting to edit a new buffer, after
313				reading the file into the buffer, before
314				processing modelines.  See |BufWinEnter| to do
315				something after processing modelines.
316				Also triggered:
317				- when writing an unnamed buffer in a way that
318				  the buffer gets a name
319				- after successfully recovering a file
320				- for the "filetypedetect" group when
321				  executing ":filetype detect"
322				Not triggered:
323				- for the `:read file` command
324				- when the file doesn't exist
325
326							*BufReadCmd*
327BufReadCmd			Before starting to edit a new buffer.  Should
328				read the file into the buffer. |Cmd-event|
329
330						*BufReadPre* *E200* *E201*
331BufReadPre			When starting to edit a new buffer, before
332				reading the file into the buffer.  Not used
333				if the file doesn't exist.
334
335							*BufUnload*
336BufUnload			Before unloading a buffer, when the text in
337				the buffer is going to be freed.
338				After BufWritePost.
339				Before BufDelete.
340				Triggers for all loaded buffers when Vim is
341				going to exit.
342				NOTE: Current buffer "%" is not the target
343				buffer "<afile>", "<abuf>". |<buffer=abuf>|
344								*E1546*
345				Do not switch buffers or windows!
346				Not triggered when exiting and v:dying is 2 or
347				more.
348
349							*BufWinEnter*
350BufWinEnter			After a buffer is displayed in a window.  This
351				may be when the buffer is loaded (after
352				processing modelines) or when a hidden buffer
353				is displayed (and is no longer hidden).
354
355				Not triggered for |:split| without arguments,
356				since the buffer does not change, or :split
357				with a file already open in a window.
358				Triggered for ":split" with the name of the
359				current buffer, since it reloads that buffer.
360
361							*BufWinLeave*
362BufWinLeave			Before a buffer is removed from a window.
363				Not when it's still visible in another window.
364				Also triggered when exiting.
365				Before BufUnload, BufHidden.
366				NOTE: Current buffer "%" is not the target
367				buffer "<afile>", "<abuf>". |<buffer=abuf>|
368				Not triggered when exiting and v:dying is 2 or
369				more.
370
371							*BufWipeout*
372BufWipeout			Before completely deleting a buffer.  The
373				BufUnload and BufDelete events may be called
374				first (if the buffer was loaded and was in the
375				buffer list).  Also used just before a buffer
376				is renamed (also when it's not in the buffer
377				list).
378				NOTE: Current buffer "%" is not the target
379				buffer "<afile>", "<abuf>". |<buffer=abuf>|
380				Do not change to another buffer.
381
382						*BufWrite* *BufWritePre*
383BufWrite or BufWritePre		Before writing the whole buffer to a file.
384
385							*BufWriteCmd*
386BufWriteCmd			Before writing the whole buffer to a file.
387				Should do the writing of the file and reset
388				'modified' if successful, unless '+' is in
389				'cpo' and writing to another file |cpo-+|.
390				The buffer contents should not be changed.
391				When the command resets 'modified' the undo
392				information is adjusted to mark older undo
393				states as 'modified', like |:write| does.  Use
394				the |'[| and |']| marks for the range of lines.
395				|Cmd-event|
396
397							*BufWritePost*
398BufWritePost			After writing the whole buffer to a file
399				(should undo the commands for BufWritePre).
400
401							*ChanClose*
402ChanClose			After a channel was closed, before it is removed.
403				This is triggered even when inside an
404				autocommand defined without |autocmd-nested|.
405				Sets these |v:event| keys:
406				    info	as from |nvim_get_chan_info()|
407
408							*ChanInfo*
409ChanInfo			State of channel changed, for instance the
410				client of a RPC channel described itself.
411				This is triggered even when inside an
412				autocommand defined without |autocmd-nested|.
413				Sets these |v:event| keys:
414				    info	as from |nvim_get_chan_info()|
415
416							*ChanOpen*
417ChanOpen			Just after a channel was opened.
418				This is triggered even when inside an
419				autocommand defined without |autocmd-nested|.
420				Sets these |v:event| keys:
421				    info	as from |nvim_get_chan_info()|
422
423							*CmdAtom*
424CmdAtom				After a user action (an "atom" of input): any
425				normal command, motion, operator, insert
426				session, Visual sequence, Ex cmdline
427				(":cnext<CR>"), mapping (and subatoms), macro,
428				or scroll/mouse.
429
430				<amatch> is the atom "type" (see below).
431				Event is |deferred|.
432
433				Only for user input, not programmatic input:
434					INPUT			ATOM ~
435					Typed keys		yes
436					Mapping, macro "@q"	yes
437					|nvim_input()|		yes
438					|nvim_feedkeys()|	with "t" (see note)
439					Hydrogen		yes
440					|:normal|		no
441					API requests		no
442					"@q" fed by a script	no
443					|multicursor| cascade	no
444					Aborted operation	no
445					Terminal-mode keys	no
446					Mouse drag/release	no (TODO?)
447
448				Note: All keys fed during a mapping execution
449				are part of the resolved `keys`. But entering
450				|Terminal-mode| (e.g. a picker/fuzzy-finder
451				UI) completes the atom: terminal input is not
452				captured, because there is no defined way to
453				delimit the "end" of such an action.
454
455				Plugins should not publish "fake" CmdAtom
456				events via `nvim_exec_autocmds`.
457
458				The |event-data| has these fields (type: `vim.event.cmdatom.data`):
459
460				- atoms: Ordered "subatoms" of a composite
461				  atom (complex mapping, Visual sequence).
462				- changed: Buffer was changed by the command.
463				- cmd: Command/motion/object name: "w", "f",
464				  "iw", "gJ", "<Home>", …. |key-notation|
465				- cmdarg: Operand of `cmd`: the "x" of "fx",
466				  the replacement char of |r|. |key-notation|
467				- count: Effective |count|, or nil.
468				- keys:	Resolved (post-mapping) keysequence.
469				  Raw internal bytes (use |keytrans()| to get
470				  key-notation): feed to |nvim_feedkeys()|
471				  (mode "n") to replay. Empty: unreplayable.
472				  Nil: lossy capture, replay `lhs` (mode "m").
473				- lhs: User input, before it is resolved.
474				  Mapping LHS plus any payload it read
475				  (|getchar()|), macro register ("@q"), or
476				  Visual sequence. Raw bytes, like `keys`.
477				- motionforce |forced-motion|: "v", "V", or
478				  "<C-V>" (|key-notation|).
479				- moved: Cursor moved. May be `false` even if
480				  the action is classified as a "motion" (e.g.
481				  "w" at buffer end, failed "fx").
482				- operator: Operator: "d", "g@", "zf", ….
483				  |key-notation|, like `cmd`.
484				- pos: Start position: [row, col], 1-indexed
485				  row, 0-indexed col.
486				- reg: Register name.
487				- text: Payload: full text of an insert
488				  session, Ex cmdline, or search. Raw bytes,
489				  like `keys`.
490				  Examples:
491				    - typed "iab<Esc>" → text="ab"
492				    - typed ":cnext<CR>" → text="cnext"
493				    - typed "<Cmd>cnext<CR>" → text="cnext"
494				    - typed "iab<Left>c<Esc>" → text="c"
495				- type:
496				    - "excmd": Ex cmdline session.
497				    - "insert": Insert session.
498				    - "jump": Absolute motion ("G", marks,
499				      "H", |jumplist).
500				    - "mapping": Composite (≥2 subatoms).
501				    - "motion": Cursor-relative motion ("w",
502				      "%", "fx", "*").
503				    - "mouse"
504				    - "normal": Other commands ("u", CTRL-R,
505				      "za", CTRL-W, …).
506				    - "operator"
507				    - "scroll": Viewport scroll.
508				    - "visual": Visual composite.
509				- undoseq: Undo state after the action
510				  (|undotree()| `seq_cur`). Decreases on undo.
511
512							*CmdlineChanged*
513CmdlineChanged			After EVERY change inside command line. Also
514				triggered during mappings! Use |<Cmd>| instead
515				of ":" in mappings, to avoid that.
516
517				<afile> expands to the |cmdline-char|.
518
519							*CmdlineEnter*
520CmdlineEnter			After entering the command-line (including
521				non-interactive use of ":" in a mapping: use
522				|<Cmd>| instead to avoid this).
523				The pattern is matched against |cmdline-char|.
524				<afile> expands to the |cmdline-char|.
525				Sets these |v:event| keys:
526				    cmdlevel
527				    cmdtype
528
529							*CmdlineLeave*
530CmdlineLeave			Before leaving the command-line (including
531				non-interactive use of ":" in a mapping: use
532				|<Cmd>| instead to avoid this).
533				<afile> expands to the |cmdline-char|.
534				Sets the |v:char| to the key that exited the
535				command-line (e.g. <CR>, <CTRL-C>, <Esc>).
536				Sets these |v:event| keys:
537				    abort (mutable)
538				    cmdlevel
539				    cmdtype
540				Note: `abort` can only be changed from false
541				to true: cannot execute an already aborted
542				cmdline by changing it to false.
543
544							*CmdlineLeavePre*
545CmdlineLeavePre			Just before leaving the command line, and
546				before |CmdlineLeave|.  Useful for capturing
547				completion info with |cmdcomplete_info()|, as
548				this information is cleared before
549				|CmdlineLeave| is triggered.  Triggered for
550				non-interactive use of ":" in a mapping, but
551				not when using |<Cmd>|.  Also triggered when
552				abandoning the command line by typing CTRL-C
553				or <Esc>.  <afile> is set to |cmdline-char|.
554				Sets |v:char| as with |CmdlineLeave|.
555
556							*CmdUndefined*
557CmdUndefined			When a user command is used but it isn't
558				defined.  Useful for defining a command only
559				when it's used.  The pattern is matched
560				against the command name.  Both <amatch> and
561				<afile> expand to the command name.
562				This is triggered even when inside an
563				autocommand defined without |autocmd-nested|.
564				NOTE: Autocompletion won't work until the
565				command is defined.  An alternative is to
566				always define the user command and have it
567				invoke an autoloaded function.  See |autoload|.
568
569							*CmdwinEnter*
570CmdwinEnter			After entering the command-line window.
571				Useful for setting options specifically for
572				this special type of window.
573				<afile> expands to a single character,
574				indicating the type of command-line.
575				|cmdwin-char|
576
577							*CmdwinLeave*
578CmdwinLeave			Before leaving the command-line window.
579				Useful to clean up any global setting done
580				with CmdwinEnter.
581				<afile> expands to a single character,
582				indicating the type of command-line.
583				|cmdwin-char|
584
585							*ColorScheme*
586ColorScheme			After loading a color scheme. |:colorscheme|
587				Not triggered if the color scheme is not
588				found.
589				The pattern is matched against the
590				colorscheme name.  <afile> can be used for the
591				name of the actual file where this option was
592				set, and <amatch> for the new colorscheme
593				name.
594
595							*ColorSchemePre*
596ColorSchemePre			Before loading a color scheme. |:colorscheme|
597				Useful to setup removing things added by a
598				color scheme, before another one is loaded.
599
600CompleteChanged						*CompleteChanged*
601				After each time the Insert mode completion
602				menu changed.  Not fired on popup menu hide,
603				use |CompleteDonePre| or |CompleteDone| for
604				that.
605
606				Sets these |v:event| keys:
607				    completed_item	See |complete-items|.
608				    height		nr of items visible
609				    width		screen cells
610				    row			top screen row
611				    col			leftmost screen column
612				    size		total nr of items
613				    scrollbar		TRUE if visible
614
615				Non-recursive (event cannot trigger itself).
616				Cannot change the text. |textlock|
617
618				The size and position of the popup are also
619				available by calling |pum_getpos()|.
620
621							*CompleteDone*
622CompleteDone			After Insert mode completion is done.  Either
623				when something was completed or discarded.
624				|ins-completion|
625				|complete_info()| is cleared before this; use
626				CompleteDonePre if you need it.
627				|v:completed_item| gives the completed item,
628				or empty dict if completion was discarded.
629
630				Sets these |v:event| keys:
631				    complete_word	The word that was
632							selected, empty if
633							completion was
634							abandoned (discarded).
635				    complete_type	|complete_info_mode|
636				    reason	Reason for completion being
637						done. Can be one of:
638						- "accept": completion was
639						  accepted by |complete_CTRL-Y|.
640						- "cancel": completion was
641						  stopped by |complete_CTRL-E|.
642						- "discard": completion was
643						  abandoned for other reason.
644
645							*CompleteDonePre*
646CompleteDonePre			After Insert mode completion is done.  Either
647				when something was completed or discarded.
648				|ins-completion|
649				|complete_info()| is valid during this event.
650				|v:completed_item| gives the completed item.
651
652							*CursorHold*
653CursorHold			When there is no user input for 'updatetime'
654				duration, in Normal-mode. Not triggered while
655				waiting for a command argument or movement
656				after an operator, nor while |recording|
657				a macro. See |CursorHold-example|.
658
659				Note: Interactive commands cannot be used for
660				this event.  There is no hit-enter prompt,
661				the screen is updated directly (when needed).
662				Note: In the future there will probably be
663				another option to set the time.
664				Hint: to force an update of the status lines
665				use: >
666					:let &ro = &ro
667<
668							*CursorHoldI*
669CursorHoldI			Like CursorHold, but in Insert mode. Not
670				triggered when waiting for another key, e.g.
671				after CTRL-V, and not in CTRL-X mode
672				|insert_expand|.
673
674							*CursorMoved*
675CursorMoved			After the cursor was moved in Normal or Visual
676				mode or to another window.  Also when the text
677				of the cursor line has been changed, e.g. with
678				"x", "rx" or "p".
679				Not always triggered when there is typeahead,
680				while executing commands in a script file, or
681				when an operator is pending.
682				For an example see |match-parens|.
683				Note: Cannot be skipped with |:noautocmd|.
684				Careful: This is triggered very often, don't
685				do anything that the user does not expect or
686				that is slow.
687
688							*CursorMovedC*
689CursorMovedC			After the cursor was moved in the command
690				line.  Be careful not to mess up the command
691				line, it may cause Vim to lock up.
692				<afile> expands to the |cmdline-char|.
693
694							*CursorMovedI*
695CursorMovedI			After the cursor was moved in Insert mode.
696				Not triggered when the popup menu is visible.
697				Otherwise the same as CursorMoved.
698
699							*DiffUpdated*
700DiffUpdated			After diffs have been updated.  Depending on
701				what kind of diff is being used (internal or
702				external) this can be triggered on every
703				change or when doing |:diffupdate|.
704
705							*DirChanged*
706DirChanged			After the |current-directory| was changed.
707				The pattern can be:
708					"auto"    triggered on 'autochdir'.
709					"buffer"  triggered on `:bcd`.
710					"global"  triggered on `:cd`.
711					"tabpage" triggered on `:tcd`.
712					"window"  triggered on `:lcd`.
713				Sets these |v:event| keys:
714				    cwd:            current working directory
715				    scope:          "global", "tabpage", "window", "buffer"
716				    changed_window: v:true if we fired the event
717				                    switching window (or tab)
718				<afile> is set to the new directory name.
719				Non-recursive (event cannot trigger itself).
720
721							*DirChangedPre*
722DirChangedPre			When the |current-directory| is going to be
723				changed, as with |DirChanged|.
724				The pattern is like with |DirChanged|.
725				Sets these |v:event| keys:
726				    directory:      new working directory
727				    scope:          "global", "tabpage", "window", "buffer"
728				    changed_window: v:true if we fired the event
729				                    switching window (or tab)
730				<afile> is set to the new directory name.
731				Non-recursive (event cannot trigger itself).
732
733							*ExitPre*
734ExitPre				When using `:quit`, `:wq` in a way it makes
735				Vim exit, or using `:qall`, just after
736				|QuitPre|.  Can be used to close any
737				non-essential window.  Exiting may still be
738				cancelled if there is a modified buffer that
739				isn't automatically saved, use |VimLeavePre|
740				for really exiting.
741				See also |QuitPre|, |WinClosed|.
742
743							*FileAppendCmd*
744FileAppendCmd			Before appending to a file.  Should do the
745				appending to the file.  Use the '[ and ']
746				marks for the range of lines. |Cmd-event|
747
748							*FileAppendPost*
749FileAppendPost			After appending to a file.
750
751							*FileAppendPre*
752FileAppendPre			Before appending to a file.  Use the '[ and ']
753				marks for the range of lines.
754
755							*FileChangedRO*
756FileChangedRO			Before making the first change to a read-only
757				file.  Can be used to checkout the file from
758				a source control system.  Not triggered when
759				the change was caused by an autocommand.
760				Triggered when making the first change in
761				a buffer or the first change after 'readonly'
762				was set, just before the change is applied to
763				the text.
764				WARNING: If the autocommand moves the cursor
765				the effect of the change is undefined.
766							*E788*
767				Cannot switch buffers.  You can reload the
768				buffer but not edit another one.
769							*E881*
770				If the number of lines changes saving for undo
771				may fail and the change will be aborted.
772
773							*FileChangedShell*
774FileChangedShell		When Vim notices that the modification time of
775				a file has changed since editing started.
776				Also when the file attributes of the file
777				change or when the size of the file changes.
778				|timestamp|
779				Triggered for each changed file, after:
780				- executing a shell command or |:terminal| job
781				- |:checktime|
782				- |FocusGained|
783
784				Not used when 'autoread' is set and the buffer
785				was not changed.  If a FileChangedShell
786				autocommand exists the warning message and
787				prompt is not given.
788				|v:fcs_reason| indicates what happened. Set
789				|v:fcs_choice| to control what happens next.
790				NOTE: Current buffer "%" is not the target
791				buffer "<afile>" and "<abuf>". |<buffer=abuf>|
792							*E246* *E811*
793				Cannot switch, jump to or delete buffers.
794				Non-recursive (event cannot trigger itself).
795
796							*FileChangedShellPost*
797FileChangedShellPost		After handling a file that was changed outside
798				of Vim.  Can be used to update the statusline.
799
800							*FileReadCmd*
801FileReadCmd			Before reading a file with a ":read" command.
802				Should do the reading of the file. |Cmd-event|
803
804							*FileReadPost*
805FileReadPost			After reading a file with a ":read" command.
806				Note that Vim sets the '[ and '] marks to the
807				first and last line of the read.  This can be
808				used to operate on the lines just read.
809
810							*FileReadPre*
811FileReadPre			Before reading a file with a ":read" command.
812
813							*FileType*
814FileType			When the 'filetype' option has been set.  The
815				pattern is matched against the filetype.
816				<afile> is the name of the file where this
817				option was set.  <amatch> is the new value of
818				'filetype'.
819				Cannot switch windows or buffers.
820				See |filetypes|.
821
822							*FileWriteCmd*
823FileWriteCmd			Before writing to a file, when not writing the
824				whole buffer.  Should do the writing to the
825				file.  Should not change the buffer.  Use the
826				|'[| and |']| marks for the range of lines.
827				|Cmd-event|
828
829							*FileWritePost*
830FileWritePost			After writing to a file, when not writing the
831				whole buffer.
832
833							*FileWritePre*
834FileWritePre			Before writing to a file, when not writing the
835				whole buffer.  Use the |'[| and |']| marks for the
836				range of lines.
837
838							*FilterReadPost*
839FilterReadPost			After reading a file from a filter command.
840				Vim checks the pattern against the name of
841				the current buffer as with FilterReadPre.
842				Not triggered when 'shelltemp' is off.
843
844							*FilterReadPre* *E135*
845FilterReadPre			Before reading a file from a filter command.
846				Vim checks the pattern against the name of
847				the current buffer, not the name of the
848				temporary file that is the output of the
849				filter command.
850				Not triggered when 'shelltemp' is off.
851
852							*FilterWritePost*
853FilterWritePost			After writing a file for a filter command or
854				making a diff with an external diff (see
855				|DiffUpdated| for internal diff).
856				Vim checks the pattern against the name of
857				the current buffer as with FilterWritePre.
858				Not triggered when 'shelltemp' is off.
859
860							*FilterWritePre*
861FilterWritePre			Before writing a file for a filter command or
862				making a diff with an external diff.
863				Vim checks the pattern against the name of
864				the current buffer, not the name of the
865				temporary file that is the output of the
866				filter command.
867				Not triggered when 'shelltemp' is off.
868
869							*FocusGained*
870FocusGained			Nvim got focus.
871
872							*FocusLost*
873FocusLost			Nvim lost focus.  Also (potentially) when
874				a GUI dialog pops up.
875
876							*FuncUndefined*
877FuncUndefined			When a user function is used but it isn't
878				defined.  Useful for defining a function only
879				when it's used.  The pattern is matched
880				against the function name.  Both <amatch> and
881				<afile> are set to the name of the function.
882				This is triggered even when inside an
883				autocommand defined without |autocmd-nested|.
884				NOTE: When writing Vim scripts a better
885				alternative is to use an autoloaded function.
886				See |autoload-functions|.
887
888							*InsertChange*
889InsertChange			When typing <Insert> while in Insert or
890				Replace mode.  The |v:insertmode| variable
891				indicates the new mode.
892				Be careful not to move the cursor or do
893				anything else that the user does not expect.
894
895							*InsertCharPre*
896InsertCharPre			When a character is typed in Insert mode,
897				before inserting the char.
898				The |v:char| variable indicates the char typed
899				and can be changed during the event to insert
900				a different character.  When |v:char| is set
901				to more than one character this text is
902				inserted literally.
903
904				Not triggered for |.| redo, |i_CTRL-R|, |i_CTRL-A|.
905
906				Cannot change the text. |textlock|
907
908							*InsertEnter*
909InsertEnter			Just before starting Insert mode.  Also for
910				Replace mode and Virtual Replace mode.  The
911				|v:insertmode| variable indicates the mode.
912				Be careful not to do anything else that the
913				user does not expect.
914				The cursor is restored afterwards.  If you do
915				not want that set |v:char| to a non-empty
916				string.
917
918							*InsertLeavePre*
919InsertLeavePre			Just before leaving Insert mode.  Also when
920				using CTRL-O |i_CTRL-O|.  Be careful not to
921				change mode or use `:normal`, it will likely
922				cause trouble.
923
924							*InsertLeave*
925InsertLeave			Just after leaving Insert mode.  Also when
926				using CTRL-O |i_CTRL-O|.  But not for |i_CTRL-C|.
927
928LspAttach			See |LspAttach|
929LspDetach			See |LspDetach|
930LspNotify			See |LspNotify|
931LspProgress			See |LspProgress|
932LspRequest			See |LspRequest|
933LspTokenUpdate			See |LspTokenUpdate|
934
935							*MarkSet*
936MarkSet				After a |mark| is set by |m|, |:mark|, and
937				|nvim_buf_set_mark()|, or deleted by |:delmarks|
938				and |nvim_buf_del_mark()|. Supports `[a-zA-Z]`
939				marks (may support more in the future).
940				The |autocmd-pattern| is matched against the
941				mark name (e.g. `[ab]` matches `a` or `b`, `*`
942				matches all). If line is 0, the mark has been
943				deleted.
944
945				The |event-data| has these keys (type: `vim.event.markset.data`):
946				- name: Mark name (e.g. "a")
947				- line: Mark line.
948				- col: Mark column.
949
950							*MenuPopup*
951MenuPopup			Just before showing the popup menu (under the
952				right mouse button).  Useful for adjusting the
953				menu for what is under the cursor or mouse
954				pointer.
955				The pattern is matched against one or two
956				characters representing the mode:
957					n	Normal
958					v	Visual
959					o	Operator-pending
960					i	Insert
961					c	Command line
962					tl	Terminal
963
964							*ModeChanged*
965ModeChanged			After changing the mode.  The pattern is
966				matched against `'old_mode:new_mode'`, for
967				example match against `*:c*` to simulate
968				|CmdlineEnter|.
969				The following values of |v:event| are set:
970				   old_mode	The mode before it changed.
971				   new_mode	The new mode as also returned
972						by |mode()| called with a
973						non-zero argument.
974				When ModeChanged is triggered, old_mode will
975				have the value of new_mode when the event was
976				last triggered.
977				This will be triggered on every minor mode
978				change.
979				Usage example to use relative line numbers
980				when entering visual mode: >vim
981		:au ModeChanged [vV\x16]*:* let &l:rnu = mode() =~# '^[vV\x16]'
982		:au ModeChanged *:[vV\x16]* let &l:rnu = mode() =~# '^[vV\x16]'
983		:au WinEnter,WinLeave * let &l:rnu = mode() =~# '^[vV\x16]'
984<
985							*OptionSet*
986OptionSet			After setting an option (except during
987				|startup|).  The |autocmd-pattern| is matched
988				against the long option name.  |<amatch>|
989				indicates what option has been set.
990
991				|v:option_type| indicates whether it's global
992				or local scoped.
993				|v:option_command| indicates what type of
994				set/let command was used (follow the tag to
995				see the table).
996				|v:option_new| indicates the newly set value.
997				|v:option_oldlocal| has the old local value.
998				|v:option_oldglobal| has the old global value.
999				|v:option_old| indicates the old option value.
1000
1001				|v:option_oldlocal| is only set when |:set|
1002				or |:setlocal| or a |modeline| was used to set
1003				the option.  Similarly |v:option_oldglobal| is
1004				only set when |:set| or |:setglobal| was used.
1005
1006				This does not set |<abuf>|, you could use
1007				|bufnr()|.
1008
1009				Note that when setting a |global-local| option
1010				with |:set|, then |v:option_old| is the old
1011				global value.  However, for all options that
1012				are not global-local it is the old local
1013				value.
1014
1015				Usage example: Check for the existence of the
1016				directory in the 'backupdir' and 'undodir'
1017				options, create the directory if it doesn't
1018				exist yet.
1019
1020				Note: Do not reset the same option during this
1021				autocommand, that may break plugins.  You can
1022				always use |:noautocmd| to prevent triggering
1023				OptionSet.
1024
1025				Note: OptionSet is |deferred| when triggered by
1026				'modified', even when set via |:set|.
1027
1028				Non-recursive: |:set| in the autocommand does
1029				not trigger OptionSet again.
1030
1031				Not triggered on startup.
1032
1033PackChangedPre			See |PackChangedPre|
1034PackChanged			See |PackChanged|
1035
1036Progress						*Progress*
1037				After a |progress-message| is created or updated via
1038				`nvim_echo`. The pattern is matched against
1039				`source` of the message.
1040
1041				The |event-data| has these keys (type: `vim.event.progress.data`):
1042				- id: id of the message
1043				- text: text of the message
1044				- title: title of the progress message
1045				- source: source of the progress message
1046				- status: status of the progress message
1047				- percent: how much progress has been made
1048				- data: arbitrary data sent with the message
1049
1050				Usage example:
1051>lua
1052		vim.api.nvim_create_autocmd('Progress', {
1053		  pattern={'term'},
1054		  callback = function(ev)
1055		    print(string.format('event fired: %s', vim.inspect(ev)))
1056		  end
1057		})
1058		local id = vim.api.nvim_echo({{'searching...'}}, true, {kind='progress', status='running', percent=10, title='term', source='search'})
1059		vim.api.nvim_echo({{'searching'}}, true, {id = id, kind='progress', status='running', percent=50, title='term', source='search'})
1060		vim.api.nvim_echo({{'done'}}, true, {id = id, kind='progress', status='success', percent=100, title='term', source='search'})
1061
1062<
1063							*QuickFixCmdPre*
1064QuickFixCmdPre			Before a quickfix command is run (|:make|,
1065				|:lmake|, |:grep|, |:lgrep|, |:grepadd|,
1066				|:lgrepadd|, |:vimgrep|, |:lvimgrep|,
1067				|:vimgrepadd|, |:lvimgrepadd|,
1068				|:cfile|, |:cgetfile|, |:caddfile|, |:lfile|,
1069				|:lgetfile|, |:laddfile|, |:helpgrep|,
1070				|:lhelpgrep|, |:cexpr|, |:cgetexpr|,
1071				|:caddexpr|, |:cbuffer|, |:cgetbuffer|,
1072				|:caddbuffer|).
1073				The pattern is matched against the command
1074				being run.  When |:grep| is used but 'grepprg'
1075				is set to "internal" it still matches "grep".
1076				This command cannot be used to set the
1077				'makeprg' and 'grepprg' variables.
1078				If this command causes an error, the quickfix
1079				command is not executed.
1080
1081							*QuickFixCmdPost*
1082QuickFixCmdPost			Like QuickFixCmdPre, but after a quickfix
1083				command is run, before jumping to the first
1084				location.  For |:cfile| and |:lfile| commands
1085				it is run after the error file is read and
1086				before moving to the first error.
1087				See |QuickFixCmdPost-example|.
1088
1089							*QuitPre*
1090QuitPre				When using `:quit`, `:wq` or `:qall`, before
1091				deciding whether it closes the current window
1092				or quits Vim.  For `:wq` the buffer is written
1093				before QuitPre is triggered.  Can be used to
1094				close any non-essential window if the current
1095				window is the last ordinary window.
1096				See also |ExitPre|, |WinClosed|.
1097
1098							*RecordingEnter*
1099RecordingEnter			When a macro starts recording.
1100				The pattern is the current file name, and
1101				|reg_recording()| is the current register that
1102				is used.
1103
1104							*RecordingLeave*
1105RecordingLeave			When a macro stops recording.
1106				The pattern is the current file name, and
1107				|reg_recording()| is the recorded
1108				register.
1109				|reg_recorded()| is only updated after this
1110				event.
1111				Sets these |v:event| keys:
1112				    regcontents
1113				    regname
1114
1115							*RemoteReply*
1116RemoteReply			When a reply from a Vim that functions as
1117				server was received server2client().  The
1118				pattern is matched against the {serverid}.
1119				<amatch> is equal to the {serverid} from which
1120				the reply was sent, and <afile> is the actual
1121				reply string.
1122				Note that even if an autocommand is defined,
1123				the reply should be read with remote_read()
1124				to consume it.
1125
1126							*SafeState*
1127SafeState			When nothing is pending, going to wait for the
1128				user to type a character.
1129				This will not be triggered when:
1130				- an operator is pending
1131				- a register was entered with "r
1132				- halfway executing a command
1133				- executing a mapping
1134				- there is typeahead
1135				- Insert mode completion is active
1136				- Command line completion is active
1137				You can use `mode()` to find out what state
1138				Vim is in.  That may be:
1139				- Visual mode
1140				- Normal mode
1141				- Insert mode
1142				- Command-line mode
1143				Depending on what you want to do, you may also
1144				check more with `state()`, e.g. whether the
1145				screen was scrolled for messages.
1146
1147							*SearchWrapped*
1148SearchWrapped			After making a search with |n| or |N| if the
1149				search wraps around the document back to
1150				the start/finish respectively.
1151
1152							*SessionLoadPre*
1153SessionLoadPre			Before loading the session file created using
1154				the |:mksession| command.
1155
1156							*SessionLoadPost*
1157SessionLoadPost			After loading the session file created using
1158				the |:mksession| command.
1159
1160							*SessionWritePre*
1161SessionWritePre			Before writing the session file created using
1162				the |:mksession| command.
1163
1164							*SessionWritePost*
1165SessionWritePost		After writing a session file by calling
1166				the |:mksession| command.
1167
1168							*ShellCmdPost*
1169ShellCmdPost			After executing a shell command with |:!cmd|,
1170				|:make| and |:grep|.  Can be used to check for
1171				any changed files.
1172
1173				For non-blocking shell commands, see
1174				|TermClose| |job-control|.
1175
1176							*ShellFilterPost*
1177ShellFilterPost			After executing a shell command with
1178				":{range}!cmd", ":w !cmd" or ":r !cmd".
1179				Can be used to check for any changed files.
1180
1181							*Signal*
1182Signal				After Nvim receives a signal. The pattern is
1183				matched against the signal name. Only
1184				"SIGUSR1" and "SIGWINCH" are supported.
1185				This is triggered even when inside an
1186				autocommand defined without |autocmd-nested|.
1187				Example: >vim
1188				    autocmd Signal SIGUSR1 call some#func()
1189
1190<							*SourceCmd*
1191SourceCmd			When sourcing a Vimscript/Lua file. |:source|
1192				<afile> is the name of the file being sourced.
1193				The autocommand must source that file.
1194				|Cmd-event|
1195
1196							*SourcePre*
1197SourcePre			Before sourcing a Vimscript/Lua file. |:source|
1198				<afile> is the name of the file being sourced.
1199
1200							*SourcePost*
1201SourcePost			After sourcing a Vimscript/Lua file. |:source|
1202				<afile> is the name of the file being sourced.
1203				Not triggered when sourcing was interrupted.
1204				Also triggered after a SourceCmd autocommand
1205				was triggered.
1206
1207							*SpellFileMissing*
1208SpellFileMissing		When trying to load a spell checking file and
1209				it can't be found.  The pattern is matched
1210				against the language.  <amatch> is the
1211				language, 'encoding' also matters.  See
1212				|spell-SpellFileMissing|.
1213
1214							*StdinReadPost*
1215StdinReadPost			During startup, after reading from stdin into
1216				the buffer, before executing modelines. |--|
1217
1218							*StdinReadPre*
1219StdinReadPre			During startup, before reading from stdin into
1220				the buffer. |--|
1221
1222							*SwapExists*
1223SwapExists			Detected an existing swap file when starting
1224				to edit a file.  Only when it is possible to
1225				select a way to handle the situation, when Vim
1226				would ask the user what to do.
1227				The |v:swapname| variable holds the name of
1228				the swap file found, <afile> the file being
1229				edited.  |v:swapcommand| may contain a command
1230				to be executed in the opened file.
1231				The commands should set the |v:swapchoice|
1232				variable to a string with one character to
1233				tell Vim what should be done next:
1234					'o'	open read-only
1235					'e'	edit the file anyway
1236					'r'	recover
1237					'd'	delete the swap file
1238					'q'	quit, don't edit the file
1239					'a'	abort, like hitting CTRL-C
1240				When set to an empty string the user will be
1241				asked, as if there was no SwapExists autocmd.
1242							*E812*
1243				Cannot change to another buffer, change
1244				the buffer name or change directory.
1245
1246							*Syntax*
1247Syntax				When the 'syntax' option has been set.  The
1248				pattern is matched against the syntax name.
1249				<afile> expands to the name of the file where
1250				this option was set. <amatch> expands to the
1251				new value of 'syntax'.
1252				See |:syn-on|.
1253
1254							*TabClosed*
1255TabClosed			After closing a tabpage. <afile> expands to
1256				the closing |tabpage-number|.
1257
1258							*TabClosedPre*
1259TabClosedPre			Before closing a tabpage. The current tabpage
1260				(|tabpagenr()|) is the one being closed. The
1261				window layout is locked, thus opening and
1262				closing of windows is prohibited.
1263
1264							*TabEnter*
1265TabEnter			Just after entering a |tabpage|.
1266				After WinEnter.
1267				Before BufEnter.
1268
1269							*TabLeave*
1270TabLeave			Just before leaving a |tabpage|.
1271				After WinLeave.
1272
1273							*TabMoved*
1274TabMoved			After a |tabpage| is moved (by |:tabmove| or
1275				mouse drag). <amatch> expands to the old
1276				|tabpage-number| before the move.
1277
1278				The |event-data| has these keys (type: `vim.event.tabmoved.data`)
1279				- tabnr_old: |tabpage-number| before the move.
1280				- tabnr_new: |tabpage-number| after the move.
1281
1282							*TabNew*
1283TabNew				When creating a new |tabpage|.
1284				After WinEnter.
1285				Before TabEnter.
1286
1287							*TabNewEntered*
1288TabNewEntered			After entering a new |tabpage|.
1289				After BufEnter.
1290
1291							*TermClose*
1292TermClose			When a |terminal| job ends.
1293				Sets these |v:event| keys:
1294				    status	job exit status, or -1 if the
1295						terminal buffer is deleted
1296
1297							*TermEnter*
1298TermEnter			After entering |Terminal-mode|.
1299				After TermOpen.
1300
1301							*TermLeave*
1302TermLeave			After leaving |Terminal-mode|.
1303				After TermClose.
1304
1305							*TermOpen*
1306TermOpen			When a |terminal| job is starting.  Can be
1307				used to configure the terminal buffer. To get
1308				the terminal process details: >lua
1309				    vim.print(vim.api.nvim_get_chan_info(vim.bo.channel))
1310<
1311							*TermRequest*
1312TermRequest			When a |:terminal| child process emits an OSC,
1313				DCS, or APC sequence. Sets |v:termrequest|.
1314
1315				The |event-data| has these keys (type: `vim.event.termrequest.data`):
1316				- sequence: the received sequence
1317				- terminator: the received sequence terminator (i.e. BEL or ST)
1318				- cursor: (1,0)-indexed, buffer-relative
1319				  position of the cursor when the sequence was
1320				  received (line number may be <= 0 if the
1321				  position is no longer in the buffer)
1322
1323				This is triggered even when inside an
1324				autocommand defined without |autocmd-nested|.
1325
1326							*TermResponse*
1327TermResponse			When Nvim receives an OSC, DCS, APC, or recognized
1328				CSI (DA1, kitty multiple-cursors) response from
1329				the host terminal. Sets |v:termresponse|.
1330
1331				The |event-data| has these keys (type: `vim.event.termresponse.data`):
1332				- chan: the source channel id
1333				- sequence: the received sequence
1334
1335				This is triggered even when inside an
1336				autocommand defined without |autocmd-nested|.
1337
1338				May be triggered during another event (file
1339				I/O, a shell command, or anything else that
1340				takes time).
1341
1342				Example: >lua
1343
1344				-- Query the terminal palette for the RGB value of color 1
1345				-- (red) using OSC 4
1346				vim.api.nvim_create_autocmd('TermResponse', {
1347				  once = true,
1348				  callback = function(ev)
1349				    local resp = ev.data.sequence
1350				    local r, g, b = resp:match("\027%]4;1;rgb:(%w+)/(%w+)/(%w+)")
1351				  end,
1352				})
1353				vim.api.nvim_ui_send("\027]4;1;?\027\\")
1354<
1355							*TextChanged*
1356TextChanged			After a change was made to the text in the
1357				current buffer in Normal mode.  That is after
1358				|b:changedtick| has changed (also when that
1359				happened before the TextChanged autocommand
1360				was defined).
1361				Not triggered when there is typeahead or when
1362				an operator is pending.
1363				Note: Cannot be skipped with `:noautocmd`.
1364				Careful: This is triggered very often, don't
1365				do anything that the user does not expect or
1366				that is slow.
1367
1368							*TextChangedI*
1369TextChangedI			After a change was made to the text in the
1370				current buffer in Insert mode.
1371				Not triggered when the popup menu is visible.
1372				Otherwise the same as TextChanged.
1373
1374							*TextChangedP*
1375TextChangedP			After a change was made to the text in the
1376				current buffer in Insert mode, only when the
1377				popup menu is visible.  Otherwise the same as
1378				TextChanged.
1379
1380							*TextChangedT*
1381TextChangedT			After a change was made to the text in the
1382				current buffer in |Terminal-mode|.  Otherwise
1383				the same as TextChanged.
1384
1385							*TextPutPost*
1386TextPutPost			After text has been put in the current buffer.
1387				The following values in |v:event| are mostly
1388				the same as |TextYankPost|:
1389				   operator	The operation performed,
1390						either 'p' or 'P'.
1391				   regcontents	Text that was put. For
1392						|quote_=|, this is the result
1393						of the expression.
1394				   regname	Name of the register or empty
1395						string for the unnamed
1396						register.  For |nvim_put()|
1397						this is set to '_'.
1398				   regtype	Type of the register, see
1399						|getregtype()|.
1400				   visual	True if the operation is
1401						performed in |Visual| mode.
1402				Not triggered when |quote_| is used nor when
1403				called recursively.
1404				It is not allowed to change the buffer text,
1405				see |textlock|.
1406				Note that for the |quote_.| register, since
1407				the last inserted text is buffered into the
1408				input buffer (buffer isn't modified directly),
1409				this autocommand is called directly after
1410				|TextPutPre|.
1411
1412							*TextPutPre*
1413TextPutPre			Before text has been put in the current buffer.
1414				Same values as |TextPutPost| in |v:event|.  It
1415				is valid to call |setreg()| in this
1416				autocommand, allowing you to process and
1417				modify the text in "regcontents" before it is
1418				put.  However this does not apply to |quote_#|,
1419				|quote_=|, |quote_%|, |quote_:|, |quote_/| or |quote_.|.
1420				Not triggered when |quote_| is used nor when
1421				called recursively.
1422				It is not allowed to change the buffer text,
1423				see |textlock|.
1424
1425							*TextYankPost*
1426TextYankPost			Just after a |yank| or |deleting| command, but not
1427				if the black hole register |quote_| is used nor
1428				for |setreg()|. Pattern must be "*".
1429				Sets these |v:event| keys:
1430				    inclusive
1431				    operator
1432				    regcontents
1433				    regname
1434				    regtype
1435				    visual
1436				The `inclusive` flag combined with the |'[|
1437				and |']| marks can be used to calculate the
1438				precise region of the operation.
1439
1440				Non-recursive (event cannot trigger itself).
1441				Cannot change the text. |textlock|
1442
1443							*UIEnter*
1444UIEnter				After a UI connects via |nvim_ui_attach()|, or
1445				after builtin TUI is started, after |VimEnter|.
1446				Sets these |v:event| keys:
1447				    chan: |channel-id| of the UI
1448
1449							*UILeave*
1450UILeave				After a UI disconnects from Nvim, or after
1451				builtin TUI is stopped, after |VimLeave|.
1452				Sets these |v:event| keys:
1453				    chan: |channel-id| of the UI
1454
1455							*User*
1456User				Not executed automatically.  Use |:doautocmd|
1457				to trigger this, typically for "custom events"
1458				in a plugin.  Example: >
1459				    :autocmd User MyPlugin echom 'got MyPlugin event'
1460				    :doautocmd User MyPlugin
1461
1462<							*UserGettingBored*
1463UserGettingBored		When the user presses the same key 42 times.
1464				Just kidding! :-)
1465
1466							*VimEnter*
1467VimEnter			After doing all the startup stuff, including
1468				loading vimrc files, executing the "-c cmd"
1469				arguments, creating all windows and loading
1470				the buffers in them.
1471				Just before this event is triggered the
1472				|v:vim_did_enter| variable is set, so that you
1473				can do: >
1474				    if v:vim_did_enter
1475				      call s:init()
1476				    else
1477				      au VimEnter * call s:init()
1478				    endif
1479
1480							*VimInit*
1481VimInit				After sourcing all init files, including
1482				executing the "-c cmd" arguments. Just before
1483				this event is triggered the |v:vim_did_init|
1484				variable is set, so that you can do: >
1485				    if v:vim_did_init
1486				      call s:after()
1487				    else
1488				      au VimInit * call s:after()
1489				    endif
1490
1491<							*VimLeave*
1492VimLeave			Before exiting Vim, just after writing the
1493				.shada file.  Executed only once, like
1494				VimLeavePre.
1495				Use |v:dying| to detect an abnormal exit.
1496				Use |v:exiting| to get the exit code.
1497				Not triggered if |v:dying| is 2 or more.
1498
1499							*VimLeavePre*
1500VimLeavePre			Before exiting Vim, just before writing the
1501				|shada| file.  Executed only once, if the
1502				pattern matches the current buffer on exit.
1503				Mostly useful with a "*" pattern. >
1504				   :autocmd VimLeavePre * call CleanupStuff()
1505<				Use |v:dying| to detect an abnormal exit.
1506				Use |v:exiting| to get the exit code.
1507				Not triggered if |v:dying| is 2 or more.
1508
1509							*VimResized*
1510VimResized			After Nvim itself was resized: 'lines' and/or
1511				'columns' changed.  But not during |startup|.
1512
1513				To ensure the window layout is always
1514				"equalized" on resize: >
1515				    :autocmd VimResized * wincmd =
1516<
1517							*VimResume*
1518VimResume			After Nvim resumes from |suspend| state.
1519
1520							*VimSuspend*
1521VimSuspend			Before Nvim enters |suspend| state.
1522
1523							*WinClosed*
1524WinClosed			When closing a window, just before it is
1525				removed from the window layout.  The pattern
1526				is matched against the |window-ID|.  Both
1527				<amatch> and <afile> are set to the |window-ID|.
1528				After WinLeave.
1529				Non-recursive (event cannot trigger itself).
1530				See also |ExitPre|, |QuitPre|.
1531
1532							*WinEnter*
1533WinEnter			After entering another window.  Not done for
1534				the first window, when Vim has just started.
1535				Useful for setting the window height.
1536				If the window is for another buffer, Vim
1537				executes the BufEnter autocommands after the
1538				WinEnter autocommands.
1539				Note: For split and tabpage commands the
1540				WinEnter event is triggered after the split
1541				or tab command but before the file is loaded.
1542
1543							*WinLeave*
1544WinLeave			Before leaving a window.  If the window to be
1545				entered next is for a different buffer, Vim
1546				executes the BufLeave autocommands before the
1547				WinLeave autocommands (but not for ":new").
1548				Not used for ":qa" or ":q" when exiting Vim.
1549				Before WinClosed.
1550
1551							*WinNewPre*
1552WinNewPre			Before creating a new window.  Triggered
1553				before commands that modify window layout by
1554				creating a split.
1555				Not done when creating tabpages and for the
1556				first window, as the window structure is not
1557				initialized yet and so is generally not safe.
1558				It is not allowed to modify window layout
1559				while executing commands for the WinNewPre
1560				event.
1561				Most useful to store current window layout
1562				and compare it with the new layout after the
1563				Window has been created.
1564
1565							*WinNew*
1566WinNew				When a new window was created.  Not done for
1567				the first window, when Vim has just started.
1568				Before WinEnter.
1569
1570							*WinResized*
1571WinResized			After a window in the current tabpage changed
1572				width or height.
1573				See |win-scrolled-resized|.
1574
1575				|v:event| is set with information about size
1576				changes. |WinResized-event|
1577
1578				Same behavior as |WinScrolled| for the
1579				pattern, triggering and recursiveness.
1580
1581							*WinScrolled*
1582WinScrolled			After any window in the current tabpage
1583				scrolled the text (horizontally or vertically)
1584				or changed width or height.  See
1585				|win-scrolled-resized|.
1586
1587				Note: This can not be skipped with
1588				`:noautocmd`, because it triggers after
1589				processing normal commands when Vim is back in
1590				the main loop.  If you want to disable this,
1591				consider setting the 'eventignore' option
1592				instead.
1593
1594				The pattern is matched against the |window-ID|
1595				of the first window that scrolled or resized.
1596				Both <amatch> and <afile> are set to the
1597				|window-ID|.
1598
1599				|v:event| is set with information about size
1600				and scroll changes. |WinScrolled-event|
1601
1602				Only starts triggering after startup finished
1603				and the first screen redraw was done.
1604				Does not trigger when defining the first
1605				WinScrolled or WinResized event, but may
1606				trigger when adding more.
1607
1608				Non-recursive: the event will not trigger
1609				while executing commands for the WinScrolled
1610				event.  However, if the command causes a
1611				window to scroll or change size, then another
1612				WinScrolled event will be triggered later.
1613
1614==============================================================================
16156. Patterns					*autocmd-pattern* *{aupat}*
1616
1617The {aupat} argument of `:autocmd` can be a comma-separated list.  This works as
1618if the command was given with each pattern separately.  Thus this command: >
1619	:autocmd BufRead *.txt,*.info set et
1620Is equivalent to: >
1621	:autocmd BufRead *.txt set et
1622	:autocmd BufRead *.info set et
1623
1624The file pattern {aupat} is tested for a match against the file name in one of
1625two ways:
16261. When there is no '/' in the pattern, Vim checks for a match against only
1627   the tail part of the file name (without its leading directory path).
16282. When there is a '/' in the pattern, Vim checks for a match against both the
1629   short file name (as you typed it) and the full file name (after expanding
1630   it to a full path and resolving symbolic links).
1631
1632The special pattern <buffer> or <buffer=N> is used for buffer-local
1633autocommands |autocmd-buflocal|.  This pattern is not matched against the name
1634of a buffer.
1635
1636Examples: >
1637	:autocmd BufRead *.txt		set et
1638Set the 'et' option for all text files. >
1639
1640	:autocmd BufRead /vim/src/*.c	set cindent
1641Set the 'cindent' option for C files in the /vim/src directory. >
1642
1643	:autocmd BufRead /tmp/*.c	set ts=5
1644If you have a link from "/tmp/test.c" to "/home/nobody/vim/src/test.c", and
1645you start editing "/tmp/test.c", this autocommand will match.
1646
1647Note:  To match part of a path, but not from the root directory, use a "*" as
1648the first character.  Example: >
1649	:autocmd BufRead */doc/*.txt	set tw=78
1650This autocommand will for example be executed for "/tmp/doc/xx.txt" and
1651"/usr/home/piet/doc/yy.txt".  The number of directories does not matter here.
1652
1653
1654The file name that the pattern is matched against is after expanding
1655wildcards.  Thus if you issue this command: >
1656	:e $ROOTDIR/main.$EXT
1657The argument is first expanded to: >
1658	/usr/root/main.py
1659Before it's matched with the pattern of the autocommand.  Careful with this
1660when using events like FileReadCmd, the value of <amatch> may not be what you
1661expect.
1662
1663
1664Environment variables can be used in a pattern: >
1665	:autocmd BufRead $VIMRUNTIME/doc/*.txt  set expandtab
1666And ~ can be used for the home directory (if $HOME is defined): >
1667	:autocmd BufWritePost ~/.config/nvim/init.vim   so <afile>
1668	:autocmd BufRead ~archive/*      set readonly
1669The environment variable is expanded when the autocommand is defined, not when
1670the autocommand is executed.  This is different from the command!
1671
1672							*file-pattern*
1673The pattern is interpreted like mostly used in file names:
1674	*	matches any sequence of characters; Unusual: includes path
1675		separators
1676	?	matches any single character
1677	\?	matches a '?'
1678	.	matches a '.'
1679	~	matches a '~'
1680	,	separates patterns
1681	\,	matches a ','
1682	{ }	like \( \) in a |pattern|
1683	,	inside { }: like \| in a |pattern|
1684	\}	literal }
1685	\{	literal {
1686	\\\{n,m\}  like \{n,m} in a |pattern|
1687	\	special meaning like in a |pattern|
1688	[ch]	matches 'c' or 'h'
1689	[^ch]   match any character but 'c' and 'h'
1690
1691Note that for all systems the '/' character is used for path separator (even
1692for MS-Windows).  This was done because the backslash is difficult to use in a
1693pattern and to make the autocommands portable across different systems.  To
1694only match a '/' on all platforms (e.g. in a non-file pattern), use "\/".
1695
1696It is possible to use |pattern| items, but they may not work as expected,
1697because of the translation done for the above.
1698
1699							*autocmd-changes*
1700Matching with the pattern is done when an event is triggered.  Changing the
1701buffer name in one of the autocommands, or even deleting the buffer, does not
1702change which autocommands will be executed.  Example: >
1703
1704	au BufEnter *.foo  bdel
1705	au BufEnter *.foo  set modified
1706
1707This will delete the current buffer and then set 'modified' in what has become
1708the current buffer instead.  Vim doesn't take into account that "*.foo"
1709doesn't match with that buffer name.  It matches "*.foo" with the name of the
1710buffer at the moment the event was triggered.
1711
1712However, buffer-local autocommands will not be executed for a buffer that has
1713been wiped out with |:bwipe|.  After deleting the buffer with |:bdel| the
1714buffer actually still exists (it becomes unlisted), thus the autocommands are
1715still executed.
1716
1717==============================================================================
17187. Buffer-local autocommands	*autocmd-buflocal* *autocmd-buffer-local*
1719				*<buffer>* *<buffer=N>* *<buffer=abuf>* *E680*
1720
1721Buffer-local autocommands are attached to a specific buffer.  They are useful
1722if the buffer does not have a name and when the name does not match a specific
1723pattern.  But it also means they must be explicitly added to each buffer.
1724
1725Instead of a pattern buffer-local autocommands use one of these forms:
1726	<buffer>	current buffer
1727	<buffer=99>	buffer number 99
1728	<buffer=abuf>	using <abuf> (only when executing autocommands)
1729			|<abuf>|
1730
1731Examples: >
1732    :au CursorHold <buffer>  echo 'hold'
1733    :au CursorHold <buffer=33>  echo 'hold'
1734    :au BufNewFile * au CursorHold <buffer=abuf>  echo 'hold'
1735
1736All the commands for autocommands also work with buffer-local autocommands,
1737simply use the special string instead of the pattern.  Examples: >
1738    :au! * <buffer>		     " remove buffer-local autocommands for
1739				     " current buffer
1740    :au! * <buffer=33>		     " remove buffer-local autocommands for
1741				     " buffer #33
1742    :bufdo :au! CursorHold <buffer>  " remove autocmd for given event for all
1743				     " buffers
1744    :au * <buffer>		     " list buffer-local autocommands for
1745				     " current buffer
1746
1747Note that when an autocommand is defined for the current buffer, it is stored
1748with the buffer number.  Thus it uses the form "<buffer=12>", where 12 is the
1749number of the current buffer.  You will see this when listing autocommands,
1750for example.
1751
1752To test for presence of buffer-local autocommands use the |exists()| function
1753as follows: >
1754    :if exists("#CursorHold#<buffer=12>") | ... | endif
1755    :if exists("#CursorHold#<buffer>") | ... | endif    " for current buffer
1756
1757When a buffer is wiped out its buffer-local autocommands are also gone, of
1758course.  Note that when deleting a buffer, e.g., with ":bdel", it is only
1759unlisted, the autocommands are still present.  In order to see the removal of
1760buffer-local autocommands: >
1761    :set verbose=6
1762
1763It is not possible to define buffer-local autocommands for a non-existent
1764buffer.
1765
1766==============================================================================
17678. Groups						*autocmd-groups*
1768
1769Autocommands can be put together in a group.  This is useful for removing or
1770executing a group of autocommands.  For example, all the autocommands for
1771syntax highlighting are put in the "highlight" group, to be able to execute
1772":doautoall highlight BufRead" when the GUI starts.
1773
1774When no specific group is selected, Vim uses the default group.  The default
1775group does not have a name.  You cannot execute the autocommands from the
1776default group separately; you can execute them only by executing autocommands
1777for all groups.
1778
1779Normally, when executing autocommands automatically, Vim uses the autocommands
1780for all groups.  The group only matters when executing autocommands with
1781":doautocmd" or ":doautoall", or when defining or deleting autocommands.
1782
1783The group name can contain any characters except white space.  The group name
1784"end" is reserved (also in uppercase).
1785
1786The group name is case sensitive.  Note that this is different from the event
1787name!
1788
1789							*:aug* *:augroup*
1790:aug[roup] {name}		Define the autocmd group name for the
1791				following ":autocmd" commands.  The name "end"
1792				or "END" selects the default group.
1793				To avoid confusion, the name should be
1794				different from existing {event} names, as this
1795				most likely will not do what you intended.
1796
1797					*:augroup-delete* *E367* *W19* *E936*
1798:aug[roup]! {name}		Delete the autocmd group {name}.  Don't use
1799				this if there is still an autocommand using
1800				this group!  You will get a warning if doing
1801				it anyway.  When the group is the current
1802				group you will get error E936.
1803
1804To enter autocommands for a specific group, use this method:
18051. Select the group with ":augroup {name}".
18062. Delete any old autocommands with ":au!".
18073. Define the autocommands.
18084. Go back to the default group with "augroup END".
1809
1810Example: >
1811	:augroup uncompress
1812	:  au!
1813	:  au BufEnter *.gz	%!gunzip
1814	:augroup END
1815
1816This prevents having the autocommands defined twice (e.g., after sourcing the
1817vimrc file again).
1818
1819						*FileExplorer*
1820There is one group that is recognized by Vim: FileExplorer.  If this group
1821exists Vim assumes that editing a directory is possible and will trigger a
1822plugin that lists the files in that directory.  This is used by directory
1823browser plugins.  This allows you to do: >
1824	browse edit
1825
1826==============================================================================
18279. Executing autocommands				*autocmd-execute*
1828
1829Vim can also execute Autocommands non-automatically.  This is useful if you
1830have changed autocommands, or when Vim has executed the wrong autocommands
1831(e.g., the file pattern match was wrong).
1832
1833Note that the 'eventignore' option applies here too.  Events listed in this
1834option will not cause any commands to be executed.
1835
1836				*:do* *:doau* *:doaut* *:doautocmd* *E217*
1837:do[autocmd] [<nomodeline>] [group] {event} [fname]
1838			Apply the autocommands matching [fname] (default:
1839			current file name) for {event} to the current buffer.
1840			You can use this when the current file name does not
1841			match the right pattern, after changing settings, or
1842			to execute autocommands for a certain event.
1843			It's possible to use this inside an autocommand too,
1844			so you can base the autocommands for one extension on
1845			another extension.  Example: >
1846				:au BufEnter *.cpp so ~/.config/nvim/init_cpp.vim
1847				:au BufEnter *.cpp doau BufEnter x.c
1848<			Be careful to avoid endless loops.  |autocmd-nested|
1849
1850			When the [group] argument is not given, Vim executes
1851			the autocommands for all groups.  When the [group]
1852			argument is included, Vim executes only the matching
1853			autocommands for that group.  Undefined group is an
1854			error.
1855							*<nomodeline>*
1856			After applying the autocommands the modelines are
1857			processed, so that their settings overrule the
1858			settings from autocommands when editing a file.  This
1859			is skipped if <nomodeline> is specified.  You probably
1860			want to use <nomodeline> for events not used when
1861			loading a buffer, such as |User|.
1862			Modelines are also skipped when no matching
1863			autocommands were executed.
1864
1865						*:doautoa* *:doautoall*
1866:doautoa[ll] [<nomodeline>] [group] {event} [fname]
1867			Like ":doautocmd", but apply the autocommands to each
1868			loaded buffer.  The current buffer is done last.
1869
1870			Note that [fname] is used to select the autocommands,
1871			not the buffers to which they are applied.  Example: >
1872				augroup mine
1873				  autocmd!
1874				  autocmd FileType * echo expand('<amatch>')
1875				augroup END
1876				doautoall mine FileType Loaded-Buffer
1877<			Sourcing this script, you'll see as many
1878			"Loaded-Buffer" echoed as there are loaded buffers.
1879
1880			Careful: Don't use this for autocommands that delete a
1881			buffer, change to another buffer or change the
1882			contents of a buffer; the result is unpredictable.
1883			This command is intended for autocommands that set
1884			options, change highlighting, and things like that.
1885
1886==============================================================================
188710. Using autocommands					*autocmd-use*
1888
1889For WRITING FILES there are four possible sets of events.  Vim uses only one
1890of these sets for a write command:
1891
1892BufWriteCmd	BufWritePre	BufWritePost	writing the whole buffer
1893		FilterWritePre	FilterWritePost	writing to filter temp file
1894FileAppendCmd	FileAppendPre	FileAppendPost	appending to a file
1895FileWriteCmd	FileWritePre	FileWritePost	any other file write
1896
1897When there is a matching "*Cmd" autocommand, it is assumed it will do the
1898writing.  No further writing is done and the other events are not triggered.
1899|Cmd-event|
1900
1901Note that the "*WritePost" commands should undo any changes to the buffer that
1902were caused by the "*WritePre" commands; otherwise, writing the file will have
1903the side effect of changing the buffer.
1904
1905Before executing the autocommands, the buffer from which the lines are to be
1906written temporarily becomes the current buffer.  Unless the autocommands
1907change the current buffer or delete the previously current buffer, the
1908previously current buffer is made the current buffer again.
1909
1910The "*WritePre" and "*AppendPre" autocommands must not delete the buffer from
1911which the lines are to be written.
1912
1913The '[ and '] marks have a special position:
1914- Before the "*ReadPre" event the '[ mark is set to the line just above where
1915  the new lines will be inserted.
1916- Before the "*ReadPost" event the '[ mark is set to the first line that was
1917  just read, the '] mark to the last line.
1918- Before executing the "*WriteCmd", "*WritePre" and "*AppendPre" autocommands the '[
1919  mark is set to the first line that will be written, the '] mark to the last
1920  line.
1921Careful: '[ and '] change when using commands that change the buffer.
1922
1923In commands which expect a file name, you can use "<afile>" for the file name
1924that is being read |:<afile>| (you can also use "%" for the current file
1925name).  "<abuf>" can be used for the buffer number of the currently effective
1926buffer.  This also works for buffers that don't have a name.  But it doesn't
1927work for files without a buffer (e.g., with ":r file").
1928
1929							*gzip-example*
1930Examples for reading and writing compressed files: >
1931  :augroup gzip
1932  :  autocmd!
1933  :  autocmd BufReadPre,FileReadPre	*.gz set bin
1934  :  autocmd BufReadPost,FileReadPost	*.gz '[,']!gunzip
1935  :  autocmd BufReadPost,FileReadPost	*.gz set nobin
1936  :  autocmd BufReadPost,FileReadPost	*.gz execute ":doautocmd BufReadPost " .. expand("%:r")
1937  :  autocmd BufWritePost,FileWritePost	*.gz !mv <afile> <afile>:r
1938  :  autocmd BufWritePost,FileWritePost	*.gz !gzip <afile>:r
1939
1940  :  autocmd FileAppendPre		*.gz !gunzip <afile>
1941  :  autocmd FileAppendPre		*.gz !mv <afile>:r <afile>
1942  :  autocmd FileAppendPost		*.gz !mv <afile> <afile>:r
1943  :  autocmd FileAppendPost		*.gz !gzip <afile>:r
1944  :augroup END
1945
1946The "gzip" group is used to be able to delete any existing autocommands with
1947":autocmd!", for when the file is sourced twice.
1948
1949("<afile>:r" is the file name without the extension, see |:_%:|)
1950
1951The commands executed for the BufNewFile, BufRead/BufReadPost, BufWritePost,
1952FileAppendPost and VimLeave events do not set or reset the changed flag of the
1953buffer.  When you decompress the buffer with the BufReadPost autocommands, you
1954can still exit with ":q".  When you use ":undo" in BufWritePost to undo the
1955changes made by BufWritePre commands, you can still do ":q" (this also makes
1956"ZZ" work).  If you do want the buffer to be marked as modified, set the
1957'modified' option.
1958
1959To execute Normal mode commands from an autocommand, use the ":normal"
1960command.  Use with care!  If the Normal mode command is not finished, the user
1961needs to type characters (e.g., after ":normal m" you need to type a mark
1962name).
1963
1964If you want the buffer to be unmodified after changing it, reset the
1965'modified' option.  This makes it possible to exit the buffer with ":q"
1966instead of ":q!".
1967
1968							*autocmd-nested* *E218*
1969By default, autocommands do not nest.  For example, if you use ":e" or ":w" in
1970an autocommand, Vim does not execute the BufRead and BufWrite autocommands for
1971those commands.  If you do want this, use the "++nested" flag for those
1972commands in which you want nesting.  For example: >
1973  :autocmd FileChangedShell *.c ++nested e!
1974The nesting is limited to 10 levels to get out of recursive loops.
1975
1976It's possible to use the ":au" command in an autocommand.  This can be a
1977self-modifying command!  This can be useful for an autocommand that should
1978execute only once.
1979
1980If you want to skip autocommands for one command, use the |:noautocmd| command
1981modifier or the 'eventignore' option.
1982
1983Note: When reading a file (with ":read file" or with a filter command) and the
1984last line in the file does not have an <EOL>, Vim remembers this.  At the next
1985write (with ":write file" or with a filter command), if the same line is
1986written again as the last line in a file AND 'binary' is set, Vim does not
1987supply an <EOL>.  This makes a filter command on the just read lines write the
1988same file as was read, and makes a write command on just filtered lines write
1989the same file as was read from the filter.  For example, another way to write
1990a compressed file: >
1991
1992  :autocmd FileWritePre *.gz   set bin|'[,']!gzip
1993  :autocmd FileWritePost *.gz  undo|set nobin
1994<
1995							*autocommand-pattern*
1996You can specify multiple patterns, separated by commas.  Here are some
1997examples: >
1998
1999  :autocmd BufRead   *		set tw=79 nocin ic infercase fo=2croq
2000  :autocmd BufRead   .letter	set tw=72 fo=2tcrq
2001  :autocmd BufEnter  .letter	set dict=/usr/lib/dict/words
2002  :autocmd BufLeave  .letter	set dict=
2003  :autocmd BufRead,BufNewFile   *.c,*.h	set tw=0 cin noic
2004  :autocmd BufEnter  *.c,*.h	abbr FOR for (i = 0; i < 3; ++i)<CR>{<CR>}<Esc>O
2005  :autocmd BufLeave  *.c,*.h	unabbr FOR
2006
2007For makefiles (makefile, Makefile, imakefile, makefile.unix, etc.): >
2008
2009  :autocmd BufEnter  ?akefile*	set include=^s\=include
2010  :autocmd BufLeave  ?akefile*	set include&
2011
2012To always start editing C files at the first function: >
2013
2014  :autocmd BufRead   *.c,*.h	1;/^{
2015
2016Without the "1;" above, the search would start from wherever the file was
2017entered, rather than from the start of the file.
2018
2019						*skeleton* *template*
2020To read a skeleton (template) file when opening a new file: >
2021
2022  :autocmd BufNewFile  *.c	0r ~/vim/skeleton.c
2023  :autocmd BufNewFile  *.h	0r ~/vim/skeleton.h
2024  :autocmd BufNewFile  *.java	0r ~/vim/skeleton.java
2025
2026To insert the current date and time in a "*.html" file when writing it: >
2027
2028  :autocmd BufWritePre,FileWritePre *.html   ks|call LastMod()|'s
2029  :fun LastMod()
2030  :  if line("$") > 20
2031  :    let l = 20
2032  :  else
2033  :    let l = line("$")
2034  :  endif
2035  :  exe "1," .. l .. "g/Last modified: /s/Last modified: .*/Last modified: " ..
2036  :  \ strftime("%Y %b %d")
2037  :endfun
2038
2039You need to have a line "Last modified: <date time>" in the first 20 lines
2040of the file for this to work.  Vim replaces <date time> (and anything in the
2041same line after it) with the current date and time.  Explanation:
2042	ks		mark current position with mark 's'
2043	call LastMod()  call the LastMod() function to do the work
2044	's		return the cursor to the old position
2045The LastMod() function checks if the file is shorter than 20 lines, and then
2046uses the ":g" command to find lines that contain "Last modified: ".  For those
2047lines the ":s" command is executed to replace the existing date with the
2048current one.  The ":execute" command is used to be able to use an expression
2049for the ":g" and ":s" commands.  The date is obtained with the strftime()
2050function.  You can change its argument to get another date string.
2051
2052When entering :autocmd on the command-line, completion of events and command
2053names may be done (with <Tab>, CTRL-D, etc.) where appropriate.
2054
2055Vim executes all matching autocommands in the order that you specify them.
2056It is recommended that your first autocommand be used for all files by using
2057"*" as the file pattern.  This means that you can define defaults you like
2058here for any settings, and if there is another matching autocommand it will
2059override these.  But if there is no other matching autocommand, then at least
2060your default settings are recovered (if entering this file from another for
2061which autocommands did match).  Note that "*" will also match files starting
2062with ".", unlike Unix shells.
2063
2064						    *autocmd-searchpat*
2065Autocommands do not change the current search patterns.  Vim saves the current
2066search patterns before executing autocommands then restores them after the
2067autocommands finish.  This means that autocommands do not affect the strings
2068highlighted with the 'hlsearch' option.  Within autocommands, you can still
2069use search patterns normally, e.g., with the "n" command.
2070If you want an autocommand to set the search pattern, such that it is used
2071after the autocommand finishes, use the ":let @/ =" command.
2072The search-highlighting cannot be switched off with ":nohlsearch" in an
2073autocommand.  Use the 'h' flag in the 'shada' option to disable search-
2074highlighting when starting Vim.
2075
2076							*Cmd-event*
2077When using one of the "*Cmd" events, the matching autocommands are expected to
2078do the file reading, writing or sourcing.  This can be used when working with
2079a special kind of file, for example on a remote system.
2080CAREFUL: If you use these events in a wrong way, it may have the effect of
2081making it impossible to read or write the matching files!  Make sure you test
2082your autocommands properly.  Best is to use a pattern that will never match a
2083normal file name, for example "ftp://*".
2084
2085When defining a BufReadCmd it will be difficult for Vim to recover a crashed
2086editing session.  When recovering from the original file, Vim reads only those
2087parts of a file that are not found in the swap file.  Since that is not
2088possible with a BufReadCmd, use the |:preserve| command to make sure the
2089original file isn't needed for recovery.  You might want to do this only when
2090you expect the file to be modified.
2091
2092For file read and write commands the |v:cmdarg| variable holds the "++enc="
2093and "++ff=" argument that are effective.  These should be used for the command
2094that reads/writes the file.  The |v:cmdbang| variable is one when "!" was
2095used, zero otherwise.
2096
2097See $VIMRUNTIME/plugin/net.lua for examples.
2098
2099==============================================================================
210011. Disabling autocommands				*autocmd-disable*
2101
2102To disable autocommands for some time use the 'eventignore' option.  Note that
2103this may cause unexpected behavior, make sure you restore 'eventignore'
2104afterwards, using a |:try| block with |:finally|.
2105
2106To disable autocmds indefinitely in a specific window use the 'eventignorewin'
2107option.  This can only be used to ignore window and buffer related events.
2108
2109							*:noautocmd* *:noa*
2110To disable autocommands for just one command use the ":noautocmd" command
2111modifier.  This will set 'eventignore' to "all" for the duration of the
2112following command.  Example: >
2113
2114	:noautocmd w fname.gz
2115
2116This will write the file without triggering the autocommands defined by the
2117gzip plugin.
2118
2119Note that some autocommands are not triggered right away, but only later.
2120This specifically applies to |CursorMoved| and |TextChanged|.
2121
2122
2123 vim:tw=78:ts=8:noet:ft=help:norl: