summaryrefslogtreecommitdiffstats
path: root/runtime/doc/autocmd.txt
blob: e723db5e81e6a40264d6a4d2d47fe0c8e51feb50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
*autocmd.txt*   For Vim version 7.0aa.  Last change: 2004 Jun 30


		  VIM REFERENCE MANUAL    by Bram Moolenaar


Automatic commands					*autocommand*

For a basic explanation, see section |40.3| in the user manual.

1.  Introduction		|autocmd-intro|
2.  Defining autocommands	|autocmd-define|
3.  Removing autocommands	|autocmd-remove|
4.  Listing autocommands	|autocmd-list|
5.  Events			|autocmd-events|
6.  Patterns			|autocmd-patterns|
7.  Groups			|autocmd-groups|
8.  Executing autocommands	|autocmd-execute|
9.  Using autocommands		|autocmd-use|

{Vi does not have any of these commands}
{only when the |+autocmd| feature has not been disabled at compile time}

==============================================================================
1. Introduction						*autocmd-intro*

You can specify commands to be executed automatically for when reading or
writing a file, when entering or leaving a buffer or window, and when exiting
Vim.  For example, you can create an autocommand to set the 'cindent' option
for files matching *.c.  You can also use autocommands to implement advanced
features, such as editing compressed files (see |gzip-example|).  The usual
place to put autocommands is in your .vimrc or .exrc file.

							*E203* *E204* *E143*
WARNING: Using autocommands is very powerful, and may lead to unexpected side
effects.  Be careful not to destroy your text.
- It's a good idea to do some testing on an expendable copy of a file first.
  For example: If you use autocommands to decompress a file when starting to
  edit it, make sure that the autocommands for compressing when writing work
  correctly.
- Be prepared for an error halfway through (e.g., disk full).  Vim will mostly
  be able to undo the changes to the buffer, but you may have to clean up the
  changes to other files by hand (e.g., compress a file that has been
  decompressed).
- If the BufRead* events allow you to edit a compressed file, the FileRead*
  events should do the same (this makes recovery possible in some rare cases).
  It's a good idea to use the same autocommands for the File* and Buf* events
  when possible.

==============================================================================
2. Defining autocommands				*autocmd-define*

Note: The ":autocmd" command cannot be followed by another command, since any
'|' is considered part of the command.

							*:au* *:autocmd*
:au[tocmd] [group] {event} {pat} [nested] {cmd}
			Add {cmd} to the list of commands that Vim will
			execute automatically on {event} for a file matching
			{pat}.  Vim always adds the {cmd} after existing
			autocommands, so that the autocommands execute in the
			order in which they were given.  See |autocmd-nested|
			for [nested].

Note that special characters (e.g., "%", "<cword>") in the ":autocmd"
arguments are not expanded when the autocommand is defined.  These will be
expanded when the Event is recognized, and the {cmd} is executed.  The only
exception is that "<sfile>" is expanded when the autocmd is defined.  Example:
>
	:au BufNewFile,BufRead *.html so <sfile>:h/html.vim

Here Vim expands <sfile> to the name of the file containing this line.

When your .vimrc file is sourced twice, the autocommands will appear twice.
To avoid this, put this command in your .vimrc file, before defining
autocommands: >

	:autocmd!	" Remove ALL autocommands for the current group.

If you don't want to remove all autocommands, you can instead use a variable
to ensure that Vim includes the autocommands only once: >

	:if !exists("autocommands_loaded")
	:  let autocommands_loaded = 1
	:  au ...
	:endif

When the [group] argument is not given, Vim uses the current group (as defined
with ":augroup"); otherwise, Vim uses the group defined with [group].  Note
that [group] must have been defined before.  You cannot define a new group
with ":au group ..."; use ":augroup" for that.

While testing autocommands, you might find the 'verbose' option to be useful: >
	:set verbose=9
This setting makes Vim echo the autocommands as it executes them.

When defining an autocommand in a script, it will be able to call functions
local to the script and use mappings local to the script.  When the event is
triggered and the command executed, it will run in the context of the script
it was defined in.  This matters if |<SID>| is used in a command.

When executing the commands, the messages from one command overwrites a
previous message.  This is different from when executing the commands
manually.  Mostly the screen will not scroll up, thus there is no hit-enter
prompt.  When one command outputs two messages this can happen anyway.

==============================================================================
3. Removing autocommands				*autocmd-remove*

:au[tocmd]! [group] {event} {pat} [nested] {cmd}
			Remove all autocommands associated with {event} and
			{pat}, and add the command {cmd}.  See
			|autocmd-nested| for [nested].

:au[tocmd]! [group] {event} {pat}
			Remove all autocommands associated with {event} and
			{pat}.

:au[tocmd]! [group] * {pat}
			Remove all autocommands associated with {pat} for all
			events.

:au[tocmd]! [group] {event}
			Remove ALL autocommands for {event}.

:au[tocmd]! [group]	Remove ALL autocommands.

When the [group] argument is not given, Vim uses the current group (as defined
with ":augroup"); otherwise, Vim uses the group defined with [group].

==============================================================================
4. Listing autocommands					*autocmd-list*

:au[tocmd] [group] {event} {pat}
			Show the autocommands associated with {event} and
			{pat}.

:au[tocmd] [group] * {pat}
			Show the autocommands associated with {pat} for all
			events.

:au[tocmd] [group] {event}
			Show all autocommands for {event}.

:au[tocmd] [group]	Show all autocommands.

If you provide the [group] argument, Vim lists only the autocommands for
[group]; otherwise, Vim lists the autocommands for ALL groups.  Note that this
argument behavior differs from that for defining and removing autocommands.

==============================================================================
5. Events					*autocmd-events* *E215* *E216*

					*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").

							*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
				executing the modelines.  See |BufWinEnter|
				for when you need to do something after
				processing the modelines.
				This does NOT work for ":r file".  Not used
				when the file doesn't exist.  Also used after
				successfully recovering a file.
							*BufReadCmd*
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.
							*FilterReadPost*
FilterReadPost			After reading a file from a filter command.
				Vim checks the pattern against the name of
				the current buffer as with FilterReadPre.
							*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.  The buffer contents
				should not be changed.  |Cmd-event|
							*FileWritePre*
FileWritePre			Before writing to a file, when not writing the
				whole buffer.
							*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.
				|Cmd-event|
							*FileAppendPre*
FileAppendPre			Before appending to a file.
							*FileAppendPost*
FileAppendPost			After appending to a file.
							*FileAppendCmd*
FileAppendCmd			Before appending to a file.  Should do the
				appending to the file. |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.
							*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.
							*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 Vim 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.
				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.
				WARNING: This event is triggered when making a
				change, just before the change is applied to
				the text.  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.
							*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.
							*BufWinEnter*
BufWinEnter			After a buffer is displayed in a window.  This
				can be when the buffer is loaded (after
				processing the modelines), when a hidden
				buffer is displayed in a window (and is no
				longer hidden) or a buffer already visible in
				a window is also displayed in another window.
							*BufWinLeave*
BufWinLeave			Before a buffer is removed from a window.
				Not when it's still visible in another window.
				Also triggered when exiting.  It's triggered
				before BufUnload or BufHidden.
				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
				first (if the buffer was loaded and was in the
				buffer list).  Also used just before a buffer
				is renamed (also when it's not in the buffer
				list).
				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.
							*CmdwinEnter*
CmdwinEnter			After entering the command-line window.
				Useful for setting options specifically for
				this special type of window.  This is
				triggered _instead_ of BufEnter and WinEnter.
				<afile> is set to a single character,
				indicating the type of command-line.
				|cmdwin-char|
							*CmdwinLeave*
CmdwinLeave			Before leaving the command-line window.
				Useful to clean up any global setting done
				with CmdwinEnter.  This is triggered _instead_
				of BufLeave and WinLeave.
				<afile> is set to a single character,
				indicating the type of command-line.
				|cmdwin-char|
							*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 when the 'encoding' option is
				changed.  Useful to set up fonts, for example.
							*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|.
							*FileEncoding*
FileEncoding			Obsolete.  It still works and is equivalent
				to |EncodingChanged|.
							*RemoteReply*
RemoteReply			When a reply from a Vim that functions as
				server was received |server2client()|.
				<amatch> is equal to the {serverid} from which
				the reply was sent, and <afile> is the actual
				reply string.
				Note that even if an autocommand is defined,
				the reply should be read with |remote_read()|
				to consume it.
							*TermChanged*
TermChanged			After the value of 'term' has changed.  Useful
				for re-loading the syntax file to update the
				colors, fonts and other terminal-dependent
				settings.  Executed for all loaded buffers.
							*TermResponse*
TermResponse			After the response to |t_RV| is received from
				the terminal.  The value of |v:termresponse|
				can be used to do things depending on the
				terminal version.
							*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.

==============================================================================
6. Patterns					*autocmd-patterns* *{pat}*

The file pattern {pat} is tested for a match against the file name in one of
two ways:
1. When there is no '/' in the pattern, Vim checks for a match against only
   the tail part of the file name (without its leading directory path).
2. When there is a '/' in the pattern,  Vim checks for a match against the
   both short file name (as you typed it) and the full file name (after
   expanding it to a full path and resolving symbolic links).

Examples: >
	:autocmd BufRead *.txt		set et
Set the 'et' option for all text files. >

	:autocmd BufRead /vim/src/*.c	set cindent
Set the 'cindent' option for C files in the /vim/src directory. >

	:autocmd BufRead /tmp/*.c	set ts=5
If you have a link from "/tmp/test.c" to "/home/nobody/vim/src/test.c", and
you start editing "/tmp/test.c", this autocommand will match.

Note:  To match part of a path, but not from the root directory, use a '*' as
the first character.  Example: >
	:autocmd BufRead */doc/*.txt	set tw=78
This autocommand will for example be executed for "/tmp/doc/xx.txt" and
"/usr/home/piet/doc/yy.txt".  The number of directories does not matter here.


The file name that the pattern is matched against is after expanding
wildcards.  Thus is you issue this command: >
	:e $ROOTDIR/main.$EXT
The argument is first expanded to: >
	/usr/root/main.py
Before it's matched with the pattern of the autocommand.  Careful with this
when using events like FileReadCmd, the value of <amatch> may not be what you
expect.


Environment variables can be used in a pattern: >
	:autocmd BufRead $VIMRUNTIME/doc/*.txt  set expandtab
And ~ can be used for the home directory (if $HOME is defined): >
	:autocmd BufWritePost ~/.vimrc   so ~/.vimrc
	:autocmd BufRead ~archive/*      set readonly
The environment variable is expanded when the autocommand is defined, not when
the autocommand is executed.  This is different from the command!

							*file-pattern*
The pattern is interpreted like mostly used in file names:
	*	matches any sequence of characters
	?	matches any single character
	\?	matches a '?'
	.	matches a '.'
	~	matches a '~'
	,	separates patterns
	\,	matches a ','
	{ }	like \( \) in a |pattern|
	,	inside { }: like \| in a |pattern|
	\	special meaning like in a |pattern|
	[ch]	matches 'c' or 'h'
	[^ch]   match any character but 'c' and 'h'

Note that for all systems the '/' character is used for path separator (even
MS-DOS and OS/2).  This was done because the backslash is difficult to use
in a pattern and to make the autocommands portable across different systems.


Matching with the pattern is done when an e