Mercurial > vim
annotate runtime/doc/autocmd.txt @ 9830:6049c1f01391 v7.4.2190
commit https://github.com/vim/vim/commit/50fa8dd00c241fa0786fe92ecc02fee4e5d28e06
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 9 22:58:21 2016 +0200
patch 7.4.2190
Problem: When startup test fails it's not easy to find out why.
GUI test fails with Gnome.
Solution: Add the help entry matches to a list an assert that.
Set $HOME for Gnome to create .gnome2 directory.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 09 Aug 2016 23:00:08 +0200 |
parents | 35ce559b8553 |
children | b11ceef7116e |
rev | line source |
---|---|
9737
35ce559b8553
commit https://github.com/vim/vim/commit/bc8801c9317eb721a2ee91322669f2dd5d136380
Christian Brabandt <cb@256bit.org>
parents:
9653
diff
changeset
|
1 *autocmd.txt* For Vim version 7.4. Last change: 2016 Jul 29 |
7 | 2 |
3 | |
4 VIM REFERENCE MANUAL by Bram Moolenaar | |
5 | |
6 | |
7 Automatic commands *autocommand* | |
8 | |
9 For a basic explanation, see section |40.3| in the user manual. | |
10 | |
11 1. Introduction |autocmd-intro| | |
12 2. Defining autocommands |autocmd-define| | |
13 3. Removing autocommands |autocmd-remove| | |
14 4. Listing autocommands |autocmd-list| | |
15 5. Events |autocmd-events| | |
16 6. Patterns |autocmd-patterns| | |
40 | 17 7. Buffer-local autocommands |autocmd-buflocal| |
18 8. Groups |autocmd-groups| | |
19 9. Executing autocommands |autocmd-execute| | |
20 10. Using autocommands |autocmd-use| | |
590 | 21 11. Disabling autocommands |autocmd-disable| |
7 | 22 |
23 {Vi does not have any of these commands} | |
24 {only when the |+autocmd| feature has not been disabled at compile time} | |
25 | |
26 ============================================================================== | |
27 1. Introduction *autocmd-intro* | |
28 | |
22 | 29 You can specify commands to be executed automatically when reading or writing |
30 a file, when entering or leaving a buffer or window, and when exiting Vim. | |
31 For example, you can create an autocommand to set the 'cindent' option for | |
32 files matching *.c. You can also use autocommands to implement advanced | |
7 | 33 features, such as editing compressed files (see |gzip-example|). The usual |
34 place to put autocommands is in your .vimrc or .exrc file. | |
35 | |
3371 | 36 *E203* *E204* *E143* *E855* |
7 | 37 WARNING: Using autocommands is very powerful, and may lead to unexpected side |
38 effects. Be careful not to destroy your text. | |
39 - It's a good idea to do some testing on an expendable copy of a file first. | |
40 For example: If you use autocommands to decompress a file when starting to | |
41 edit it, make sure that the autocommands for compressing when writing work | |
42 correctly. | |
43 - Be prepared for an error halfway through (e.g., disk full). Vim will mostly | |
44 be able to undo the changes to the buffer, but you may have to clean up the | |
45 changes to other files by hand (e.g., compress a file that has been | |
46 decompressed). | |
47 - If the BufRead* events allow you to edit a compressed file, the FileRead* | |
48 events should do the same (this makes recovery possible in some rare cases). | |
49 It's a good idea to use the same autocommands for the File* and Buf* events | |
50 when possible. | |
51 | |
52 ============================================================================== | |
53 2. Defining autocommands *autocmd-define* | |
54 | |
55 *:au* *:autocmd* | |
56 :au[tocmd] [group] {event} {pat} [nested] {cmd} | |
57 Add {cmd} to the list of commands that Vim will | |
58 execute automatically on {event} for a file matching | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1919
diff
changeset
|
59 {pat} |autocmd-patterns|. |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1919
diff
changeset
|
60 Vim always adds the {cmd} after existing autocommands, |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1919
diff
changeset
|
61 so that the autocommands execute in the order in which |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1919
diff
changeset
|
62 they were given. See |autocmd-nested| for [nested]. |
7 | 63 |
40 | 64 The special pattern <buffer> or <buffer=N> defines a buffer-local autocommand. |
65 See |autocmd-buflocal|. | |
66 | |
9653
01c9630e80e0
commit https://github.com/vim/vim/commit/e99e84497b89e5f91df519790802770920ecf4fe
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
67 Note: The ":autocmd" command can only be followed by another command when the |
01c9630e80e0
commit https://github.com/vim/vim/commit/e99e84497b89e5f91df519790802770920ecf4fe
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
68 '|' appears before {cmd}. This works: > |
01c9630e80e0
commit https://github.com/vim/vim/commit/e99e84497b89e5f91df519790802770920ecf4fe
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
69 :augroup mine | au! BufRead | augroup END |
01c9630e80e0
commit https://github.com/vim/vim/commit/e99e84497b89e5f91df519790802770920ecf4fe
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
70 But this sees "augroup" as part of the defined command: > |
01c9630e80e0
commit https://github.com/vim/vim/commit/e99e84497b89e5f91df519790802770920ecf4fe
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
71 :augroup mine | au BufRead * set tw=70 | augroup END |
01c9630e80e0
commit https://github.com/vim/vim/commit/e99e84497b89e5f91df519790802770920ecf4fe
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
72 |
7 | 73 Note that special characters (e.g., "%", "<cword>") in the ":autocmd" |
74 arguments are not expanded when the autocommand is defined. These will be | |
75 expanded when the Event is recognized, and the {cmd} is executed. The only | |
76 exception is that "<sfile>" is expanded when the autocmd is defined. Example: | |
77 > | |
78 :au BufNewFile,BufRead *.html so <sfile>:h/html.vim | |
79 | |
80 Here Vim expands <sfile> to the name of the file containing this line. | |
81 | |
82 When your .vimrc file is sourced twice, the autocommands will appear twice. | |
83 To avoid this, put this command in your .vimrc file, before defining | |
84 autocommands: > | |
85 | |
86 :autocmd! " Remove ALL autocommands for the current group. | |
87 | |
88 If you don't want to remove all autocommands, you can instead use a variable | |
89 to ensure that Vim includes the autocommands only once: > | |
90 | |
91 :if !exists("autocommands_loaded") | |
92 : let autocommands_loaded = 1 | |
93 : au ... | |
94 :endif | |
95 | |
96 When the [group] argument is not given, Vim uses the current group (as defined | |
97 with ":augroup"); otherwise, Vim uses the group defined with [group]. Note | |
98 that [group] must have been defined before. You cannot define a new group | |
99 with ":au group ..."; use ":augroup" for that. | |
100 | |
101 While testing autocommands, you might find the 'verbose' option to be useful: > | |
102 :set verbose=9 | |
103 This setting makes Vim echo the autocommands as it executes them. | |
104 | |
105 When defining an autocommand in a script, it will be able to call functions | |
106 local to the script and use mappings local to the script. When the event is | |
107 triggered and the command executed, it will run in the context of the script | |
108 it was defined in. This matters if |<SID>| is used in a command. | |
109 | |
1621 | 110 When executing the commands, the message from one command overwrites a |
7 | 111 previous message. This is different from when executing the commands |
112 manually. Mostly the screen will not scroll up, thus there is no hit-enter | |
113 prompt. When one command outputs two messages this can happen anyway. | |
114 | |
115 ============================================================================== | |
116 3. Removing autocommands *autocmd-remove* | |
117 | |
118 :au[tocmd]! [group] {event} {pat} [nested] {cmd} | |
119 Remove all autocommands associated with {event} and | |
120 {pat}, and add the command {cmd}. See | |
121 |autocmd-nested| for [nested]. | |
122 | |
123 :au[tocmd]! [group] {event} {pat} | |
124 Remove all autocommands associated with {event} and | |
125 {pat}. | |
126 | |
127 :au[tocmd]! [group] * {pat} | |
128 Remove all autocommands associated with {pat} for all | |
129 events. | |
130 | |
131 :au[tocmd]! [group] {event} | |
132 Remove ALL autocommands for {event}. | |
133 | |
134 :au[tocmd]! [group] Remove ALL autocommands. | |
135 | |
136 When the [group] argument is not given, Vim uses the current group (as defined | |
137 with ":augroup"); otherwise, Vim uses the group defined with [group]. | |
138 | |
139 ============================================================================== | |
140 4. Listing autocommands *autocmd-list* | |
141 | |
142 :au[tocmd] [group] {event} {pat} | |
143 Show the autocommands associated with {event} and | |
144 {pat}. | |
145 | |
146 :au[tocmd] [group] * {pat} | |
147 Show the autocommands associated with {pat} for all | |
148 events. | |
149 | |
150 :au[tocmd] [group] {event} | |
151 Show all autocommands for {event}. | |
152 | |
153 :au[tocmd] [group] Show all autocommands. | |
154 | |
155 If you provide the [group] argument, Vim lists only the autocommands for | |
156 [group]; otherwise, Vim lists the autocommands for ALL groups. Note that this | |
157 argument behavior differs from that for defining and removing autocommands. | |
158 | |
40 | 159 In order to list buffer-local autocommands, use a pattern in the form <buffer> |
160 or <buffer=N>. See |autocmd-buflocal|. | |
161 | |
500 | 162 *:autocmd-verbose* |
163 When 'verbose' is non-zero, listing an autocommand will also display where it | |
164 was last defined. Example: > | |
165 | |
166 :verbose autocmd BufEnter | |
167 FileExplorer BufEnter | |
856 | 168 * call s:LocalBrowse(expand("<amatch>")) |
500 | 169 Last set from /usr/share/vim/vim-7.0/plugin/NetrwPlugin.vim |
170 < | |
171 See |:verbose-cmd| for more information. | |
172 | |
7 | 173 ============================================================================== |
174 5. Events *autocmd-events* *E215* *E216* | |
175 | |
579 | 176 You can specify a comma-separated list of event names. No white space can be |
177 used in this list. The command applies to all the events in the list. | |
178 | |
179 For READING FILES there are four kinds of events possible: | |
180 BufNewFile starting to edit a non-existent file | |
181 BufReadPre BufReadPost starting to edit an existing file | |
182 FilterReadPre FilterReadPost read the temp file with filter output | |
183 FileReadPre FileReadPost any other file read | |
184 Vim uses only one of these four kinds when reading a file. The "Pre" and | |
185 "Post" events are both triggered, before and after reading the file. | |
186 | |
187 Note that the autocommands for the *ReadPre events and all the Filter events | |
188 are not allowed to change the current buffer (you will get an error message if | |
189 this happens). This is to prevent the file to be read into the wrong buffer. | |
190 | |
191 Note that the 'modified' flag is reset AFTER executing the BufReadPost | |
192 and BufNewFile autocommands. But when the 'modified' option was set by the | |
193 autocommands, this doesn't happen. | |
194 | |
195 You can use the 'eventignore' option to ignore a number of events or all | |
196 events. | |
7 | 197 *autocommand-events* *{event}* |
198 Vim recognizes the following events. Vim ignores the case of event names | |
199 (e.g., you can use "BUFread" or "bufread" instead of "BufRead"). | |
200 | |
579 | 201 First an overview by function with a short explanation. Then the list |
843 | 202 alphabetically with full explanations |autocmd-events-abc|. |
579 | 203 |
204 Name triggered by ~ | |
205 | |
206 Reading | |
207 |BufNewFile| starting to edit a file that doesn't exist | |
208 |BufReadPre| starting to edit a new buffer, before reading the file | |
209 |BufRead| starting to edit a new buffer, after reading the file | |
210 |BufReadPost| starting to edit a new buffer, after reading the file | |
211 |BufReadCmd| before starting to edit a new buffer |Cmd-event| | |
212 | |
213 |FileReadPre| before reading a file with a ":read" command | |
214 |FileReadPost| after reading a file with a ":read" command | |
843 | 215 |FileReadCmd| before reading a file with a ":read" command |Cmd-event| |
579 | 216 |
217 |FilterReadPre| before reading a file from a filter command | |
218 |FilterReadPost| after reading a file from a filter command | |
219 | |
220 |StdinReadPre| before reading from stdin into the buffer | |
221 |StdinReadPost| After reading from the stdin into the buffer | |
222 | |
223 Writing | |
224 |BufWrite| starting to write the whole buffer to a file | |
225 |BufWritePre| starting to write the whole buffer to a file | |
226 |BufWritePost| after writing the whole buffer to a file | |
227 |BufWriteCmd| before writing the whole buffer to a file |Cmd-event| | |
228 | |
229 |FileWritePre| starting to write part of a buffer to a file | |
230 |FileWritePost| after writing part of a buffer to a file | |
231 |FileWriteCmd| before writing part of a buffer to a file |Cmd-event| | |
232 | |
233 |FileAppendPre| starting to append to a file | |
234 |FileAppendPost| after appending to a file | |
235 |FileAppendCmd| before appending to a file |Cmd-event| | |
236 | |
237 |FilterWritePre| starting to write a file for a filter command or diff | |
238 |FilterWritePost| after writing a file for a filter command or diff | |
239 | |
240 Buffers | |
241 |BufAdd| just after adding a buffer to the buffer list | |
242 |BufCreate| just after adding a buffer to the buffer list | |
243 |BufDelete| before deleting a buffer from the buffer list | |
244 |BufWipeout| before completely deleting a buffer | |
245 | |
246 |BufFilePre| before changing the name of the current buffer | |
247 |BufFilePost| after changing the name of the current buffer | |
248 | |
249 |BufEnter| after entering a buffer | |
250 |BufLeave| before leaving to another buffer | |
251 |BufWinEnter| after a buffer is displayed in a window | |
252 |BufWinLeave| before a buffer is removed from a window | |
253 | |
254 |BufUnload| before unloading a buffer | |
255 |BufHidden| just after a buffer has become hidden | |
256 |BufNew| just after creating a new buffer | |
257 | |
258 |SwapExists| detected an existing swap file | |
259 | |
260 Options | |
261 |FileType| when the 'filetype' option has been set | |
262 |Syntax| when the 'syntax' option has been set | |
263 |EncodingChanged| after the 'encoding' option has been changed | |
264 |TermChanged| after the value of 'term' has changed | |
6935 | 265 |OptionSet| after setting any option |
579 | 266 |
267 Startup and exit | |
268 |VimEnter| after doing all the startup stuff | |
269 |GUIEnter| after starting the GUI successfully | |
3830 | 270 |GUIFailed| after starting the GUI failed |
1154 | 271 |TermResponse| after the terminal response to |t_RV| is received |
579 | 272 |
4119 | 273 |QuitPre| when using `:quit`, before deciding whether to quit |
579 | 274 |VimLeavePre| before exiting Vim, before writing the viminfo file |
275 |VimLeave| before exiting Vim, after writing the viminfo file | |
276 | |
277 Various | |
278 |FileChangedShell| Vim notices that a file changed since editing started | |
766 | 279 |FileChangedShellPost| After handling a file changed since editing started |
579 | 280 |FileChangedRO| before making the first change to a read-only file |
281 | |
724 | 282 |ShellCmdPost| after executing a shell command |
283 |ShellFilterPost| after filtering with a shell command | |
284 | |
6154 | 285 |CmdUndefined| a user command is used but it isn't defined |
579 | 286 |FuncUndefined| a user function is used but it isn't defined |
650 | 287 |SpellFileMissing| a spell file is used but it can't be found |
716 | 288 |SourcePre| before sourcing a Vim script |
1061 | 289 |SourceCmd| before sourcing a Vim script |Cmd-event| |
579 | 290 |
766 | 291 |VimResized| after the Vim window size changed |
579 | 292 |FocusGained| Vim got input focus |
293 |FocusLost| Vim lost input focus | |
294 |CursorHold| the user doesn't press a key for a while | |
661 | 295 |CursorHoldI| the user doesn't press a key for a while in Insert mode |
296 |CursorMoved| the cursor was moved in Normal mode | |
297 |CursorMovedI| the cursor was moved in Insert mode | |
579 | 298 |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
299 |WinNew| after creating a new window |
9599
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
300 |TabNew| after creating a new tab page |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
301 |TabClosed| after closing a tab page |
579 | 302 |WinEnter| after entering another window |
303 |WinLeave| before leaving a window | |
677 | 304 |TabEnter| after entering another tab page |
305 |TabLeave| before leaving a tab page | |
579 | 306 |CmdwinEnter| after entering the command-line window |
307 |CmdwinLeave| before leaving the command-line window | |
308 | |
309 |InsertEnter| starting Insert mode | |
310 |InsertChange| when typing <Insert> while in Insert or Replace mode | |
311 |InsertLeave| when leaving Insert mode | |
2845 | 312 |InsertCharPre| when a character was typed in Insert mode, before |
313 inserting it | |
579 | 314 |
5555 | 315 |TextChanged| after a change was made to the text in Normal mode |
316 |TextChangedI| after a change was made to the text in Insert mode | |
317 | |
579 | 318 |ColorScheme| after loading a color scheme |
319 | |
320 |RemoteReply| a reply from a server Vim was received | |
321 | |
322 |QuickFixCmdPre| before a quickfix command is run | |
323 |QuickFixCmdPost| after a quickfix command is run | |
324 | |
325 |SessionLoadPost| after loading a session file | |
326 | |
327 |MenuPopup| just before showing the popup menu | |
3830 | 328 |CompleteDone| after Insert mode completion is done |
579 | 329 |
330 |User| to be used in combination with ":doautocmd" | |
331 | |
332 | |
333 The alphabetical list of autocommand events: *autocmd-events-abc* | |
334 | |
335 *BufCreate* *BufAdd* | |
336 BufAdd or BufCreate Just after creating a new buffer which is | |
337 added to the buffer list, or adding a buffer | |
338 to the buffer list. | |
339 Also used just after a buffer in the buffer | |
340 list has been renamed. | |
341 The BufCreate event is for historic reasons. | |
342 NOTE: When this autocommand is executed, the | |
343 current buffer "%" may be different from the | |
344 buffer being created "<afile>". | |
345 *BufDelete* | |
346 BufDelete Before deleting a buffer from the buffer list. | |
347 The BufUnload may be called first (if the | |
348 buffer was loaded). | |
349 Also used just before a buffer in the buffer | |
350 list is renamed. | |
351 NOTE: When this autocommand is executed, the | |
352 current buffer "%" may be different from the | |
1621 | 353 buffer being deleted "<afile>" and "<abuf>". |
1919 | 354 Don't change to another buffer, it will cause |
355 problems. | |
579 | 356 *BufEnter* |
357 BufEnter After entering a buffer. Useful for setting | |
358 options for a file type. Also executed when | |
359 starting to edit a buffer, after the | |
360 BufReadPost autocommands. | |
361 *BufFilePost* | |
362 BufFilePost After changing the name of the current buffer | |
363 with the ":file" or ":saveas" command. | |
625 | 364 *BufFilePre* |
579 | 365 BufFilePre Before changing the name of the current buffer |
366 with the ":file" or ":saveas" command. | |
367 *BufHidden* | |
368 BufHidden Just after a buffer has become hidden. That | |
369 is, when there are no longer windows that show | |
370 the buffer, but the buffer is not unloaded or | |
371 deleted. Not used for ":qa" or ":q" when | |
372 exiting Vim. | |
373 NOTE: When this autocommand is executed, the | |
374 current buffer "%" may be different from the | |
375 buffer being unloaded "<afile>". | |
376 *BufLeave* | |
377 BufLeave Before leaving to another buffer. Also when | |
378 leaving or closing the current window and the | |
379 new current window is not for the same buffer. | |
380 Not used for ":qa" or ":q" when exiting Vim. | |
381 *BufNew* | |
382 BufNew Just after creating a new buffer. Also used | |
383 just after a buffer has been renamed. When | |
384 the buffer is added to the buffer list BufAdd | |
385 will be triggered too. | |
386 NOTE: When this autocommand is executed, the | |
387 current buffer "%" may be different from the | |
388 buffer being created "<afile>". | |
7 | 389 *BufNewFile* |
390 BufNewFile When starting to edit a file that doesn't | |
391 exist. Can be used to read in a skeleton | |
392 file. | |
393 *BufRead* *BufReadPost* | |
394 BufRead or BufReadPost When starting to edit a new buffer, after | |
395 reading the file into the buffer, before | |
396 executing the modelines. See |BufWinEnter| | |
397 for when you need to do something after | |
398 processing the modelines. | |
399 This does NOT work for ":r file". Not used | |
400 when the file doesn't exist. Also used after | |
401 successfully recovering a file. | |
3682 | 402 Also triggered for the filetypedetect group |
403 when executing ":filetype detect" and when | |
404 writing an unnamed buffer in a way that the | |
405 buffer gets a name. | |
625 | 406 *BufReadCmd* |
7 | 407 BufReadCmd Before starting to edit a new buffer. Should |
408 read the file into the buffer. |Cmd-event| | |
625 | 409 *BufReadPre* *E200* *E201* |
579 | 410 BufReadPre When starting to edit a new buffer, before |
411 reading the file into the buffer. Not used | |
412 if the file doesn't exist. | |
413 *BufUnload* | |
414 BufUnload Before unloading a buffer. This is when the | |
415 text in the buffer is going to be freed. This | |
416 may be after a BufWritePost and before a | |
417 BufDelete. Also used for all buffers that are | |
418 loaded when Vim is going to exit. | |
419 NOTE: When this autocommand is executed, the | |
420 current buffer "%" may be different from the | |
421 buffer being unloaded "<afile>". | |
1919 | 422 Don't change to another buffer, it will cause |
423 problems. | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
424 When exiting and v:dying is 2 or more this |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
425 event is not triggered. |
579 | 426 *BufWinEnter* |
427 BufWinEnter After a buffer is displayed in a window. This | |
428 can be when the buffer is loaded (after | |
1621 | 429 processing the modelines) or when a hidden |
579 | 430 buffer is displayed in a window (and is no |
1621 | 431 longer hidden). |
432 Does not happen for |:split| without | |
433 arguments, since you keep editing the same | |
434 buffer, or ":split" with a file that's already | |
1668 | 435 open in a window, because it re-uses an |
436 existing buffer. But it does happen for a | |
437 ":split" with the name of the current buffer, | |
438 since it reloads that buffer. | |
579 | 439 *BufWinLeave* |
440 BufWinLeave Before a buffer is removed from a window. | |
441 Not when it's still visible in another window. | |
442 Also triggered when exiting. It's triggered | |
443 before BufUnload or BufHidden. | |
444 NOTE: When this autocommand is executed, the | |
445 current buffer "%" may be different from the | |
446 buffer being unloaded "<afile>". | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
447 When exiting and v:dying is 2 or more this |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
448 event is not triggered. |
579 | 449 *BufWipeout* |
450 BufWipeout Before completely deleting a buffer. The | |
451 BufUnload and BufDelete events may be called | |
452 first (if the buffer was loaded and was in the | |
453 buffer list). Also used just before a buffer | |
454 is renamed (also when it's not in the buffer | |
455 list). | |
456 NOTE: When this autocommand is executed, the | |
457 current buffer "%" may be different from the | |
458 buffer being deleted "<afile>". | |
1919 | 459 Don't change to another buffer, it will cause |
460 problems. | |
7 | 461 *BufWrite* *BufWritePre* |
462 BufWrite or BufWritePre Before writing the whole buffer to a file. | |
463 *BufWriteCmd* | |
464 BufWriteCmd Before writing the whole buffer to a file. | |
465 Should do the writing of the file and reset | |
39 | 466 'modified' if successful, unless '+' is in |
467 'cpo' and writing to another file |cpo-+|. | |
468 The buffer contents should not be changed. | |
3082 | 469 When the command resets 'modified' the undo |
470 information is adjusted to mark older undo | |
471 states as 'modified', like |:write| does. | |
39 | 472 |Cmd-event| |
579 | 473 *BufWritePost* |
474 BufWritePost After writing the whole buffer to a file | |
475 (should undo the commands for BufWritePre). | |
6154 | 476 *CmdUndefined* |
477 CmdUndefined When a user command is used but it isn't | |
478 defined. Useful for defining a command only | |
479 when it's used. The pattern is matched | |
480 against the command name. Both <amatch> and | |
481 <afile> are set to the name of the command. | |
482 NOTE: Autocompletion won't work until the | |
483 command is defined. An alternative is to | |
484 always define the user command and have it | |
485 invoke an autoloaded function. See |autoload|. | |
579 | 486 *CmdwinEnter* |
487 CmdwinEnter After entering the command-line window. | |
488 Useful for setting options specifically for | |
489 this special type of window. This is | |
490 triggered _instead_ of BufEnter and WinEnter. | |
491 <afile> is set to a single character, | |
492 indicating the type of command-line. | |
493 |cmdwin-char| | |
494 *CmdwinLeave* | |
495 CmdwinLeave Before leaving the command-line window. | |
496 Useful to clean up any global setting done | |
497 with CmdwinEnter. This is triggered _instead_ | |
498 of BufLeave and WinLeave. | |
499 <afile> is set to a single character, | |
500 indicating the type of command-line. | |
501 |cmdwin-char| | |
502 *ColorScheme* | |
503 ColorScheme After loading a color scheme. |:colorscheme| | |
5521 | 504 The pattern is matched against the |
505 colorscheme name. <afile> can be used for the | |
506 name of the actual file where this option was | |
507 set, and <amatch> for the new colorscheme | |
508 name. | |
509 | |
661 | 510 |
3682 | 511 *CompleteDone* |
512 CompleteDone After Insert mode completion is done. Either | |
513 when something was completed or abandoning | |
514 completion. |ins-completion| | |
6909 | 515 The |v:completed_item| variable contains |
516 information about the completed item. | |
3682 | 517 |
579 | 518 *CursorHold* |
519 CursorHold When the user doesn't press a key for the time | |
520 specified with 'updatetime'. Not re-triggered | |
521 until the user has pressed a key (i.e. doesn't | |
522 fire every 'updatetime' ms if you leave Vim to | |
523 make some coffee. :) See |CursorHold-example| | |
524 for previewing tags. | |
525 This event is only triggered in Normal mode. | |
1154 | 526 It is not triggered when waiting for a command |
527 argument to be typed, or a movement after an | |
528 operator. | |
610 | 529 While recording the CursorHold event is not |
530 triggered. |q| | |
6259 | 531 *<CursorHold>* |
532 Internally the autocommand is triggered by the | |
533 <CursorHold> key. In an expression mapping | |
534 |getchar()| may see this character. | |
535 | |
579 | 536 Note: Interactive commands cannot be used for |
537 this event. There is no hit-enter prompt, | |
538 the screen is updated directly (when needed). | |
539 Note: In the future there will probably be | |
540 another option to set the time. | |
541 Hint: to force an update of the status lines | |
542 use: > | |
543 :let &ro = &ro | |
544 < {only on Amiga, Unix, Win32, MSDOS and all GUI | |
545 versions} | |
661 | 546 *CursorHoldI* |
547 CursorHoldI Just like CursorHold, but in Insert mode. | |
8951
0bdeaf7092bc
commit https://github.com/vim/vim/commit/aa3b15dbebf333282503d6031e2f9ba6ee4398ed
Christian Brabandt <cb@256bit.org>
parents:
8748
diff
changeset
|
548 Not triggered when waiting for another key, |
0bdeaf7092bc
commit https://github.com/vim/vim/commit/aa3b15dbebf333282503d6031e2f9ba6ee4398ed
Christian Brabandt <cb@256bit.org>
parents:
8748
diff
changeset
|
549 e.g. after CTRL-V, and not when in CTRL-X mode |
0bdeaf7092bc
commit https://github.com/vim/vim/commit/aa3b15dbebf333282503d6031e2f9ba6ee4398ed
Christian Brabandt <cb@256bit.org>
parents:
8748
diff
changeset
|
550 |insert_expand|. |
661 | 551 |
552 *CursorMoved* | |
4911 | 553 CursorMoved After the cursor was moved in Normal or Visual |
554 mode. Also when the text of the cursor line | |
555 has been changed, e.g., with "x", "rx" or "p". | |
661 | 556 Not triggered when there is typeahead or when |
557 an operator is pending. | |
667 | 558 For an example see |match-parens|. |
4264 | 559 Careful: This is triggered very often, don't |
560 do anything that the user does not expect or | |
561 that is slow. | |
661 | 562 *CursorMovedI* |
563 CursorMovedI After the cursor was moved in Insert mode. | |
3082 | 564 Not triggered when the popup menu is visible. |
661 | 565 Otherwise the same as CursorMoved. |
579 | 566 *EncodingChanged* |
567 EncodingChanged Fires off after the 'encoding' option has been | |
568 changed. Useful to set up fonts, for example. | |
7 | 569 *FileAppendCmd* |
570 FileAppendCmd Before appending to a file. Should do the | |
26 | 571 appending to the file. Use the '[ and '] |
572 marks for the range of lines.|Cmd-event| | |
579 | 573 *FileAppendPost* |
574 FileAppendPost After appending to a file. | |
575 *FileAppendPre* | |
576 FileAppendPre Before appending to a file. Use the '[ and '] | |
577 marks for the range of lines. | |
578 *FileChangedRO* | |
579 FileChangedRO Before making the first change to a read-only | |
580 file. Can be used to check-out the file from | |
581 a source control system. Not triggered when | |
582 the change was caused by an autocommand. | |
583 This event is triggered when making the first | |
584 change in a buffer or the first change after | |
823 | 585 'readonly' was set, just before the change is |
586 applied to the text. | |
579 | 587 WARNING: If the autocommand moves the cursor |
588 the effect of the change is undefined. | |
819 | 589 *E788* |
590 It is not allowed to change to another buffer | |
591 here. You can reload the buffer but not edit | |
592 another one. | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5555
diff
changeset
|
593 *E881* |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5555
diff
changeset
|
594 If the number of lines changes saving for undo |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5555
diff
changeset
|
595 may fail and the change will be aborted. |
7 | 596 *FileChangedShell* |
597 FileChangedShell When Vim notices that the modification time of | |
598 a file has changed since editing started. | |
599 Also when the file attributes of the file | |
5908 | 600 change or when the size of the file changes. |
601 |timestamp| | |
7 | 602 Mostly triggered after executing a shell |
603 command, but also with a |:checktime| command | |
179 | 604 or when Gvim regains input focus. |
7 | 605 This autocommand is triggered for each changed |
606 file. It is not used when 'autoread' is set | |
607 and the buffer was not changed. If a | |
608 FileChangedShell autocommand is present the | |
609 warning message and prompt is not given. | |
179 | 610 The |v:fcs_reason| variable is set to indicate |
611 what happened and |v:fcs_choice| can be used | |
612 to tell Vim what to do next. | |
7 | 613 NOTE: When this autocommand is executed, the |
614 current buffer "%" may be different from the | |
615 buffer that was changed "<afile>". | |
616 NOTE: The commands must not change the current | |
617 buffer, jump to another buffer or delete a | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1919
diff
changeset
|
618 buffer. *E246* *E811* |
7 | 619 NOTE: This event never nests, to avoid an |
620 endless loop. This means that while executing | |
621 commands for the FileChangedShell event no | |
622 other FileChangedShell event will be | |
623 triggered. | |
766 | 624 *FileChangedShellPost* |
625 FileChangedShellPost After handling a file that was changed outside | |
626 of Vim. Can be used to update the statusline. | |
579 | 627 *FileEncoding* |
628 FileEncoding Obsolete. It still works and is equivalent | |
629 to |EncodingChanged|. | |
630 *FileReadCmd* | |
631 FileReadCmd Before reading a file with a ":read" command. | |
632 Should do the reading of the file. |Cmd-event| | |
633 *FileReadPost* | |
634 FileReadPost After reading a file with a ":read" command. | |
635 Note that Vim sets the '[ and '] marks to the | |
636 first and last line of the read. This can be | |
637 used to operate on the lines just read. | |
638 *FileReadPre* | |
639 FileReadPre Before reading a file with a ":read" command. | |
640 *FileType* | |
1154 | 641 FileType When the 'filetype' option has been set. The |
642 pattern is matched against the filetype. | |
579 | 643 <afile> can be used for the name of the file |
644 where this option was set, and <amatch> for | |
645 the new value of 'filetype'. | |
646 See |filetypes|. | |
647 *FileWriteCmd* | |
648 FileWriteCmd Before writing to a file, when not writing the | |
649 whole buffer. Should do the writing to the | |
650 file. Should not change the buffer. Use the | |
651 '[ and '] marks for the range of lines. | |
652 |Cmd-event| | |
653 *FileWritePost* | |
654 FileWritePost After writing to a file, when not writing the | |
655 whole buffer. | |
656 *FileWritePre* | |
657 FileWritePre Before writing to a file, when not writing the | |
658 whole buffer. Use the '[ and '] marks for the | |
659 range of lines. | |
660 *FilterReadPost* | |
661 FilterReadPost After reading a file from a filter command. | |
662 Vim checks the pattern against the name of | |
663 the current buffer as with FilterReadPre. | |
664 Not triggered when 'shelltemp' is off. | |
665 *FilterReadPre* *E135* | |
666 FilterReadPre Before reading a file from a filter command. | |
667 Vim checks the pattern against the name of | |
668 the current buffer, not the name of the | |
669 temporary file that is the output of the | |
670 filter command. | |
671 Not triggered when 'shelltemp' is off. | |
672 *FilterWritePost* | |
673 FilterWritePost After writing a file for a filter command or | |
674 making a diff. | |
675 Vim checks the pattern against the name of | |
676 the current buffer as with FilterWritePre. | |
677 Not triggered when 'shelltemp' is off. | |
678 *FilterWritePre* | |
679 FilterWritePre Before writing a file for a filter command or | |
680 making a diff. | |
681 Vim checks the pattern against the name of | |
682 the current buffer, not the name of the | |
683 temporary file that is the output of the | |
684 filter command. | |
685 Not triggered when 'shelltemp' is off. | |
7 | 686 *FocusGained* |
687 FocusGained When Vim got input focus. Only for the GUI | |
688 version and a few console versions where this | |
689 can be detected. | |
690 *FocusLost* | |
691 FocusLost When Vim lost input focus. Only for the GUI | |
692 version and a few console versions where this | |
11 | 693 can be detected. May also happen when a |
694 dialog pops up. | |
7 | 695 *FuncUndefined* |
696 FuncUndefined When a user function is used but it isn't | |
697 defined. Useful for defining a function only | |
1154 | 698 when it's used. The pattern is matched |
699 against the function name. Both <amatch> and | |
700 <afile> are set to the name of the function. | |
6154 | 701 NOTE: When writing Vim scripts a better |
702 alternative is to use an autoloaded function. | |
161 | 703 See |autoload-functions|. |
579 | 704 *GUIEnter* |
705 GUIEnter After starting the GUI successfully, and after | |
706 opening the window. It is triggered before | |
707 VimEnter when using gvim. Can be used to | |
708 position the window from a .gvimrc file: > | |
709 :autocmd GUIEnter * winpos 100 50 | |
1154 | 710 < *GUIFailed* |
711 GUIFailed After starting the GUI failed. Vim may | |
712 continue to run in the terminal, if possible | |
713 (only on Unix and alikes, when connecting the | |
714 X server fails). You may want to quit Vim: > | |
715 :autocmd GUIFailed * qall | |
579 | 716 < *InsertChange* |
717 InsertChange When typing <Insert> while in Insert or | |
718 Replace mode. The |v:insertmode| variable | |
719 indicates the new mode. | |
720 Be careful not to move the cursor or do | |
721 anything else that the user does not expect. | |
2845 | 722 *InsertCharPre* |
723 InsertCharPre When a character is typed in Insert mode, | |
724 before inserting the char. | |
725 The |v:char| variable indicates the char typed | |
726 and can be changed during the event to insert | |
727 a different character. When |v:char| is set | |
728 to more than one character this text is | |
729 inserted literally. | |
730 It is not allowed to change the text |textlock|. | |
731 The event is not triggered when 'paste' is | |
732 set. | |
579 | 733 *InsertEnter* |
1154 | 734 InsertEnter Just before starting Insert mode. Also for |
735 Replace mode and Virtual Replace mode. The | |
579 | 736 |v:insertmode| variable indicates the mode. |
4448 | 737 Be careful not to do anything else that the |
738 user does not expect. | |
739 The cursor is restored afterwards. If you do | |
740 not want that set |v:char| to a non-empty | |
741 string. | |
579 | 742 *InsertLeave* |
743 InsertLeave When leaving Insert mode. Also when using | |
744 CTRL-O |i_CTRL-O|. But not for |i_CTRL-C|. | |
745 *MenuPopup* | |
746 MenuPopup Just before showing the popup menu (under the | |
747 right mouse button). Useful for adjusting the | |
748 menu for what is under the cursor or mouse | |
749 pointer. | |
750 The pattern is matched against a single | |
751 character representing the mode: | |
752 n Normal | |
753 v Visual | |
754 o Operator-pending | |
755 i Insert | |
843 | 756 c Command line |
6935 | 757 *OptionSet* |
758 OptionSet After setting an option. The pattern is | |
759 matched against the long option name. | |
760 The |v:option_old| variable indicates the | |
761 old option value, |v:option_new| variable | |
762 indicates the newly set value, the | |
763 |v:option_type| variable indicates whether | |
764 it's global or local scoped and |<amatch>| | |
765 indicates what option has been set. | |
766 | |
767 Is not triggered on startup and for the 'key' | |
768 option for obvious reasons. | |
769 | |
6951
b2673982c625
Updated and new runtime files.
Bram Moolenaar <bram@vim.org>
parents:
6935
diff
changeset
|
770 Usage example: Check for the existence of the |
b2673982c625
Updated and new runtime files.
Bram Moolenaar <bram@vim.org>
parents:
6935
diff
changeset
|
771 directory in the 'backupdir' and 'undodir' |
b2673982c625
Updated and new runtime files.
Bram Moolenaar <bram@vim.org>
parents:
6935
diff
changeset
|
772 options, create the directory if it doesn't |
b2673982c625
Updated and new runtime files.
Bram Moolenaar <bram@vim.org>
parents:
6935
diff
changeset
|
773 exist yet. |
b2673982c625
Updated and new runtime files.
Bram Moolenaar <bram@vim.org>
parents:
6935
diff
changeset
|
774 |
b2673982c625
Updated and new runtime files.
Bram Moolenaar <bram@vim.org>
parents:
6935
diff
changeset
|
775 Note: It's a bad idea to reset an option |
b2673982c625
Updated and new runtime files.
Bram Moolenaar <bram@vim.org>
parents:
6935
diff
changeset
|
776 during this autocommand, this may break a |
b2673982c625
Updated and new runtime files.
Bram Moolenaar <bram@vim.org>
parents:
6935
diff
changeset
|
777 plugin. You can always use `:noa` to prevent |
b2673982c625
Updated and new runtime files.
Bram Moolenaar <bram@vim.org>
parents:
6935
diff
changeset
|
778 triggering this autocommand. |
6935 | 779 |
579 | 780 *QuickFixCmdPre* |
781 QuickFixCmdPre Before a quickfix command is run (|:make|, | |
657 | 782 |:lmake|, |:grep|, |:lgrep|, |:grepadd|, |
783 |:lgrepadd|, |:vimgrep|, |:lvimgrep|, | |
3281 | 784 |:vimgrepadd|, |:lvimgrepadd|, |:cscope|, |
3410
94601b379f38
Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents:
3404
diff
changeset
|
785 |:cfile|, |:cgetfile|, |:caddfile|, |:lfile|, |
94601b379f38
Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents:
3404
diff
changeset
|
786 |:lgetfile|, |:laddfile|, |:helpgrep|, |
94601b379f38
Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents:
3404
diff
changeset
|
787 |:lhelpgrep|). |
2151
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2033
diff
changeset
|
788 The pattern is matched against the command |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2033
diff
changeset
|
789 being run. When |:grep| is used but 'grepprg' |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2033
diff
changeset
|
790 is set to "internal" it still matches "grep". |
579 | 791 This command cannot be used to set the |
792 'makeprg' and 'grepprg' variables. | |
793 If this command causes an error, the quickfix | |
794 command is not executed. | |
795 *QuickFixCmdPost* | |
796 QuickFixCmdPost Like QuickFixCmdPre, but after a quickfix | |
842 | 797 command is run, before jumping to the first |
3404 | 798 location. For |:cfile| and |:lfile| commands |
799 it is run after error file is read and before | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5555
diff
changeset
|
800 moving to the first error. |
3404 | 801 See |QuickFixCmdPost-example|. |
3682 | 802 *QuitPre* |
4229 | 803 QuitPre When using `:quit`, `:wq` or `:qall`, before |
804 deciding whether it closes the current window | |
805 or quits Vim. Can be used to close any | |
806 non-essential window if the current window is | |
807 the last ordinary window. | |
579 | 808 *RemoteReply* |
809 RemoteReply When a reply from a Vim that functions as | |
1154 | 810 server was received |server2client()|. The |
811 pattern is matched against the {serverid}. | |
579 | 812 <amatch> is equal to the {serverid} from which |
813 the reply was sent, and <afile> is the actual | |
814 reply string. | |
815 Note that even if an autocommand is defined, | |
816 the reply should be read with |remote_read()| | |
817 to consume it. | |
818 *SessionLoadPost* | |
819 SessionLoadPost After loading the session file created using | |
820 the |:mksession| command. | |
724 | 821 *ShellCmdPost* |
822 ShellCmdPost After executing a shell command with |:!cmd|, | |
823 |:shell|, |:make| and |:grep|. Can be used to | |
824 check for any changed files. | |
825 *ShellFilterPost* | |
826 ShellFilterPost After executing a shell command with | |
827 ":{range}!cmd", ":w !cmd" or ":r !cmd". | |
828 Can be used to check for any changed files. | |
716 | 829 *SourcePre* |
830 SourcePre Before sourcing a Vim script. |:source| | |
1061 | 831 <afile> is the name of the file being sourced. |
832 *SourceCmd* | |
833 SourceCmd When sourcing a Vim script. |:source| | |
834 <afile> is the name of the file being sourced. | |
835 The autocommand must source this file. | |
836 |Cmd-event| | |
650 | 837 *SpellFileMissing* |
838 SpellFileMissing When trying to load a spell checking file and | |
1061 | 839 it can't be found. The pattern is matched |
840 against the language. <amatch> is the | |
841 language, 'encoding' also matters. See | |
650 | 842 |spell-SpellFileMissing|. |
579 | 843 *StdinReadPost* |
844 StdinReadPost After reading from the stdin into the buffer, | |
845 before executing the modelines. Only used | |
846 when the "-" argument was used when Vim was | |
847 started |--|. | |
848 *StdinReadPre* | |
849 StdinReadPre Before reading from stdin into the buffer. | |
850 Only used when the "-" argument was used when | |
851 Vim was started |--|. | |
852 *SwapExists* | |
853 SwapExists Detected an existing swap file when starting | |
854 to edit a file. Only when it is possible to | |
855 select a way to handle the situation, when Vim | |
856 would ask the user what to do. | |
857 The |v:swapname| variable holds the name of | |
590 | 858 the swap file found, <afile> the file being |
859 edited. |v:swapcommand| may contain a command | |
860 to be executed in the opened file. | |
861 The commands should set the |v:swapchoice| | |
862 variable to a string with one character to | |
863 tell Vim what should be done next: | |
579 | 864 'o' open read-only |
865 'e' edit the file anyway | |
866 'r' recover | |
867 'd' delete the swap file | |
868 'q' quit, don't edit the file | |
869 'a' abort, like hitting CTRL-C | |
870 When set to an empty string the user will be | |
871 asked, as if there was no SwapExists autocmd. | |
1919 | 872 *E812* |
873 It is not allowed to change to another buffer, | |
874 change a buffer name or change directory | |
875 here. | |
579 | 876 *Syntax* |
1154 | 877 Syntax When the 'syntax' option has been set. The |
878 pattern is matched against the syntax name. | |
579 | 879 <afile> can be used for the name of the file |
880 where this option was set, and <amatch> for | |
881 the new value of 'syntax'. | |
882 See |:syn-on|. | |
9599
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
883 *TabClosed* |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
884 TabClosed After closing a tab page. |
677 | 885 *TabEnter* |
886 TabEnter Just after entering a tab page. |tab-page| | |
872 | 887 After triggering the WinEnter and before |
888 triggering the BufEnter event. | |
677 | 889 *TabLeave* |
890 TabLeave Just before leaving a tab page. |tab-page| | |
891 A WinLeave event will have been triggered | |
892 first. | |
9595
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
893 *TabNew* |
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
894 TabNew When a tab page was created. |tab-page| |
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
895 A WinEnter event will have been triggered |
0190d5de215f
commit https://github.com/vim/vim/commit/c917da4b3e8801a255dbefea8e4ed19c1c716dd8
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
896 first, TabEnter follows. |
579 | 897 *TermChanged* |
898 TermChanged After the value of 'term' has changed. Useful | |
899 for re-loading the syntax file to update the | |
900 colors, fonts and other terminal-dependent | |
901 settings. Executed for all loaded buffers. | |
902 *TermResponse* | |
903 TermResponse After the response to |t_RV| is received from | |
904 the terminal. The value of |v:termresponse| | |
905 can be used to do things depending on the | |
2788 | 906 terminal version. Note that this event may be |
907 triggered halfway executing another event, | |
908 especially if file I/O, a shell command or | |
909 anything else that takes time is involved. | |
4264 | 910 *TextChanged* |
911 TextChanged After a change was made to the text in the | |
912 current buffer in Normal mode. That is when | |
913 |b:changedtick| has changed. | |
914 Not triggered when there is typeahead or when | |
915 an operator is pending. | |
916 Careful: This is triggered very often, don't | |
917 do anything that the user does not expect or | |
918 that is slow. | |
919 *TextChangedI* | |
920 TextChangedI After a change was made to the text in the | |
921 current buffer in Insert mode. | |
922 Not triggered when the popup menu is visible. | |
923 Otherwise the same as TextChanged. | |
579 | 924 *User* |
925 User Never executed automatically. To be used for | |
926 autocommands that are only executed with | |
927 ":doautocmd". | |
928 *UserGettingBored* | |
4264 | 929 UserGettingBored When the user presses the same key 42 times. |
930 Just kidding! :-) | |
579 | 931 *VimEnter* |
932 VimEnter After doing all the startup stuff, including | |
933 loading .vimrc files, executing the "-c cmd" | |
934 arguments, creating all windows and loading | |
935 the buffers in them. | |
8738
e770986c855a
commit https://github.com/vim/vim/commit/1473551a4457d4920b235eeeb9f279e196ee7225
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
936 Just before this event is triggered the |
e770986c855a
commit https://github.com/vim/vim/commit/1473551a4457d4920b235eeeb9f279e196ee7225
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
937 |v:vim_did_enter| variable is set, so that you |
e770986c855a
commit https://github.com/vim/vim/commit/1473551a4457d4920b235eeeb9f279e196ee7225
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
938 can do: > |
e770986c855a
commit https://github.com/vim/vim/commit/1473551a4457d4920b235eeeb9f279e196ee7225
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
939 if v:vim_did_enter |
e770986c855a
commit https://github.com/vim/vim/commit/1473551a4457d4920b235eeeb9f279e196ee7225
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
940 call s:init() |
e770986c855a
commit https://github.com/vim/vim/commit/1473551a4457d4920b235eeeb9f279e196ee7225
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
941 else |
e770986c855a
commit https://github.com/vim/vim/commit/1473551a4457d4920b235eeeb9f279e196ee7225
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
942 au VimEnter * call s:init() |
e770986c855a
commit https://github.com/vim/vim/commit/1473551a4457d4920b235eeeb9f279e196ee7225
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
943 endif |
e770986c855a
commit https://github.com/vim/vim/commit/1473551a4457d4920b235eeeb9f279e196ee7225
Christian Brabandt <cb@256bit.org>
parents:
7384
diff
changeset
|
944 < *VimLeave* |
579 | 945 VimLeave Before exiting Vim, just after writing the |
946 .viminfo file. Executed only once, like | |
947 VimLeavePre. | |
948 To detect an abnormal exit use |v:dying|. | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
949 When v:dying is 2 or more this event is not |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
950 triggered. |
579 | 951 *VimLeavePre* |
952 VimLeavePre Before exiting Vim, just before writing the | |
953 .viminfo file. This is executed only once, | |
954 if there is a match with the name of what | |
955 happens to be the current buffer when exiting. | |
956 Mostly useful with a "*" pattern. > | |
957 :autocmd VimLeavePre * call CleanupStuff() | |
958 < To detect an abnormal exit use |v:dying|. | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
959 When v:dying is 2 or more this event is not |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
960 triggered. |
766 | 961 *VimResized* |
962 VimResized After the Vim window was resized, thus 'lines' | |
963 and/or 'columns' changed. Not when starting | |
964 up though. | |
7 | 965 *WinEnter* |
966 WinEnter After entering another window. Not done for | |
967 the first window, when Vim has just started. | |
968 Useful for setting the window height. | |
969 If the window is for another buffer, Vim | |
970 executes the BufEnter autocommands after the | |
971 WinEnter autocommands. | |
972 Note: When using ":split fname" the WinEnter | |
973 event is triggered after the split but before | |
974 the file "fname" is loaded. | |
975 *WinLeave* | |
976 WinLeave Before leaving a window. If the window to be | |
977 entered next is for a different buffer, Vim | |
978 executes the BufLeave autocommands before the | |
979 WinLeave autocommands (but not for ":new"). | |
980 Not used for ":qa" or ":q" when exiting Vim. | |
981 | |
9599
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
982 *WinNew* |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
983 WinNew When a new window was created. Not done for |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
984 the fist window, when Vim has just started. |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
985 Before a WinEnter event. |
42a8a81decdf
commit https://github.com/vim/vim/commit/12c11d553053f5a9eae9eb3c518279b12fa928c2
Christian Brabandt <cb@256bit.org>
parents:
9595
diff
changeset
|
986 |
7 | 987 ============================================================================== |
988 6. Patterns *autocmd-patterns* *{pat}* | |
989 | |
6741 | 990 The {pat} argument can be a comma separated list. This works as if the |
991 command was given with each pattern separately. Thus this command: > | |
992 :autocmd BufRead *.txt,*.info set et | |
993 Is equivalent to: > | |
994 :autocmd BufRead *.txt set et | |
995 :autocmd BufRead *.info set et | |
996 | |
7 | 997 The file pattern {pat} is tested for a match against the file name in one of |
998 two ways: | |
999 1. When there is no '/' in the pattern, Vim checks for a match against only | |
1000 the tail part of the file name (without its leading directory path). | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1919
diff
changeset
|
1001 2. When there is a '/' in the pattern, Vim checks for a match against both the |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1919
diff
changeset
|
1002 short file name (as you typed it) and the full file name (after expanding |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1919
diff
changeset
|
1003 it to a full path and resolving symbolic links). |
7 | 1004 |
40 | 1005 The special pattern <buffer> or <buffer=N> is used for buffer-local |
1006 autocommands |autocmd-buflocal|. This pattern is not matched against the name | |
1007 of a buffer. | |
1008 | |
7 | 1009 Examples: > |
1010 :autocmd BufRead *.txt set et | |
1011 Set the 'et' option for all text files. > | |
1012 | |
1013 :autocmd BufRead /vim/src/*.c set cindent | |
1014 Set the 'cindent' option for C files in the /vim/src directory. > | |
1015 | |
1016 :autocmd BufRead /tmp/*.c set ts=5 | |
1017 If you have a link from "/tmp/test.c" to "/home/nobody/vim/src/test.c", and | |
1018 you start editing "/tmp/test.c", this autocommand will match. | |
1019 | |
1020 Note: To match part of a path, but not from the root directory, use a '*' as | |
1021 the first character. Example: > | |
1022 :autocmd BufRead */doc/*.txt set tw=78 | |
1023 This autocommand will for example be executed for "/tmp/doc/xx.txt" and | |
1024 "/usr/home/piet/doc/yy.txt". The number of directories does not matter here. | |
1025 | |
1026 | |
1027 The file name that the pattern is matched against is after expanding | |
1621 | 1028 wildcards. Thus if you issue this command: > |
7 | 1029 :e $ROOTDIR/main.$EXT |
1030 The argument is first expanded to: > | |
1031 /usr/root/main.py | |
1032 Before it's matched with the pattern of the autocommand. Careful with this | |
1033 when using events like FileReadCmd, the value of <amatch> may not be what you | |
1034 expect. | |
1035 | |
1036 | |
1037 Environment variables can be used in a pattern: > | |
1038 :autocmd BufRead $VIMRUNTIME/doc/*.txt set expandtab | |
1039 And ~ can be used for the home directory (if $HOME is defined): > | |
1040 :autocmd BufWritePost ~/.vimrc so ~/.vimrc | |
1041 :autocmd BufRead ~archive/* set readonly | |
1042 The environment variable is expanded when the autocommand is defined, not when | |
1043 the autocommand is executed. This is different from the command! | |
1044 | |
1045 *file-pattern* | |
1046 The pattern is interpreted like mostly used in file names: | |
5294 | 1047 * matches any sequence of characters; Unusual: includes path |
5277 | 1048 separators |
7 | 1049 ? matches any single character |
1050 \? matches a '?' | |
1051 . matches a '.' | |
1052 ~ matches a '~' | |
1053 , separates patterns | |
1054 \, matches a ',' | |
1055 { } like \( \) in a |pattern| | |
1056 , inside { }: like \| in a |pattern| | |
5259
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5247
diff
changeset
|
1057 \} literal } |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5247
diff
changeset
|
1058 \{ literal { |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5247
diff
changeset
|
1059 \\\{n,m\} like \{n,m} in a |pattern| |
7 | 1060 \ special meaning like in a |pattern| |
1061 [ch] matches 'c' or 'h' | |
1062 [^ch] match any character but 'c' and 'h' | |
1063 | |
1064 Note that for all systems the '/' character is used for path separator (even | |
1065 MS-DOS and OS/2). This was done because the backslash is difficult to use | |
1066 in a pattern and to make the autocommands portable across different systems. | |
1067 | |
40 | 1068 *autocmd-changes* |
7 | 1069 Matching with the pattern is done when an event is triggered. Changing the |
1070 buffer name in one of the autocommands, or even deleting the buffer, does not | |
1071 change which autocommands will be executed. Example: > | |
1072 | |
1073 au BufEnter *.foo bdel | |
1074 au BufEnter *.foo set modified | |
1075 | |
1076 This will delete the current buffer and then set 'modified' in what has become | |
1077 the current buffer instead. Vim doesn't take into account that "*.foo" | |
1078 doesn't match with that buffer name. It matches "*.foo" with the name of the | |
1079 buffer at the moment the event was triggered. | |
1080 | |
40 | 1081 However, buffer-local autocommands will not be executed for a buffer that has |
1082 been wiped out with |:bwipe|. After deleting the buffer with |:bdel| the | |
1083 buffer actually still exists (it becomes unlisted), thus the autocommands are | |
1084 still executed. | |
1085 | |
7 | 1086 ============================================================================== |
856 | 1087 7. Buffer-local autocommands *autocmd-buflocal* *autocmd-buffer-local* |
1088 *<buffer=N>* *<buffer=abuf>* *E680* | |
40 | 1089 |
1090 Buffer-local autocommands are attached to a specific buffer. They are useful | |
1091 if the buffer does not have a name and when the name does not match a specific | |
1092 pattern. But it also means they must be explicitly added to each buffer. | |
1093 | |
1094 Instead of a pattern buffer-local autocommands use one of these forms: | |
1095 <buffer> current buffer | |
1096 <buffer=99> buffer number 99 | |
1097 <buffer=abuf> using <abuf> (only when executing autocommands) | |
1098 |<abuf>| | |
1099 | |
1100 Examples: > | |
1101 :au CursorHold <buffer> echo 'hold' | |
1102 :au CursorHold <buffer=33> echo 'hold' | |
7051
eff26a8620ce
commit https://github.com/vim/vim/commit/88774fdd23f08355297bb8cda78856859051d3c7
Christian Brabandt <cb@256bit.org>
parents:
7013
diff
changeset
|
1103 :au BufNewFile * au CursorHold <buffer=abuf> echo 'hold' |
40 | 1104 |
1105 All the commands for autocommands also work with buffer-local autocommands, | |
1106 simply use the special string instead of the pattern. Examples: > | |
856 | 1107 :au! * <buffer> " remove buffer-local autocommands for |
1108 " current buffer | |
1109 :au! * <buffer=33> " remove buffer-local autocommands for | |
1110 " buffer #33 | |
1621 | 1111 :bufdo :au! CursorHold <buffer> " remove autocmd for given event for all |
856 | 1112 " buffers |
1113 :au * <buffer> " list buffer-local autocommands for | |
1114 " current buffer | |
40 | 1115 |
1116 Note that when an autocommand is defined for the current buffer, it is stored | |
1117 with the buffer number. Thus it uses the form "<buffer=12>", where 12 is the | |
1118 number of the current buffer. You will see this when listing autocommands, | |
1119 for example. | |
1120 | |
1121 To test for presence of buffer-local autocommands use the |exists()| function | |
1122 as follows: > | |
1123 :if exists("#CursorHold#<buffer=12>") | ... | endif | |
1124 :if exists("#CursorHold#<buffer>") | ... | endif " for current buffer | |
1125 | |
1126 When a buffer is wiped out its buffer-local autocommands are also gone, of | |
1127 course. Note that when deleting a buffer, e.g., with ":bdel", it is only | |
1128 unlisted, the autocommands are still present. In order to see the removal of | |
1129 buffer-local autocommands: > | |
1130 :set verbose=6 | |
1131 | |
1132 It is not possible to define buffer-local autocommands for a non-existent | |
1133 buffer. | |
1134 | |
1135 ============================================================================== | |
1136 8. Groups *autocmd-groups* | |
7 | 1137 |
1138 Autocommands can be put together in a group. This is useful for removing or | |
1139 executing a group of autocommands. For example, all the autocommands for | |
1140 syntax highlighting are put in the "highlight" group, to be able to execute | |
1141 ":doautoall highlight BufRead" when the GUI starts. | |
1142 | |
1143 When no specific group is selected, Vim uses the default group. The default | |
1144 group does not have a name. You cannot execute the autocommands from the | |
1145 default group separately; you can execute them only by executing autocommands | |
1146 for all groups. | |
1147 | |
1148 Normally, when executing autocommands automatically, Vim uses the autocommands | |
1149 for all groups. The group only matters when executing autocommands with | |
1150 ":doautocmd" or ":doautoall", or when defining or deleting autocommands. | |
1151 | |
1152 The group name can contain any characters except white space. The group name | |
1153 "end" is reserved (also in uppercase). | |
1154 | |
1155 The group name is case sensitive. Note that this is different from the event | |
1156 name! | |
1157 | |
1158 *:aug* *:augroup* | |
1159 :aug[roup] {name} Define the autocmd group name for the | |
1160 following ":autocmd" commands. The name "end" | |
1161 or "END" selects the default group. | |
7384
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
7051
diff
changeset
|
1162 To avoid confusion, the name should be |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
7051
diff
changeset
|
1163 different from existing {event} names, as this |
aea5ebf352c4
commit https://github.com/vim/vim/commit/256972a9849b5d575b62a6a71be5b6934b5b0e8b
Christian Brabandt <cb@256bit.org>
parents:
7051
diff
changeset
|
1164 most likely will not do what you intended. |
7 | 1165 |
9737
35ce559b8553
commit https://github.com/vim/vim/commit/bc8801c9317eb721a2ee91322669f2dd5d136380
Christian Brabandt <cb@256bit.org>
parents:
9653
diff
changeset
|
1166 *:augroup-delete* *E367* *W19* |
7 | 1167 :aug[roup]! {name} Delete the autocmd group {name}. Don't use |
1168 this if there is still an autocommand using | |
9737
35ce559b8553
commit https://github.com/vim/vim/commit/bc8801c9317eb721a2ee91322669f2dd5d136380
Christian Brabandt <cb@256bit.org>
parents:
9653
diff
changeset
|
1169 this group! You will get a warning if doing |
35ce559b8553
commit https://github.com/vim/vim/commit/bc8801c9317eb721a2ee91322669f2dd5d136380
Christian Brabandt <cb@256bit.org>
parents:
9653
diff
changeset
|
1170 it anyway. |
7 | 1171 |
1172 To enter autocommands for a specific group, use this method: | |
1173 1. Select the group with ":augroup {name}". | |
1174 2. Delete any old autocommands with ":au!". | |
1175 3. Define the autocommands. | |
1176 4. Go back to the default group with "augroup END". | |
1177 | |
1178 Example: > | |
1179 :augroup uncompress | |
1180 : au! | |
1181 : au BufEnter *.gz %!gunzip | |
1182 :augroup END | |
1183 | |
1184 This prevents having the autocommands defined twice (e.g., after sourcing the | |
1185 .vimrc file again). | |
1186 | |
1187 ============================================================================== | |
40 | 1188 9. Executing autocommands *autocmd-execute* |
7 | 1189 |
1190 Vim can also execute Autocommands non-automatically. This is useful if you | |
1191 have changed autocommands, or when Vim has executed the wrong autocommands | |
1192 (e.g., the file pattern match was wrong). | |
1193 | |
1194 Note that the 'eventignore' option applies here too. Events listed in this | |
1195 option will not cause any commands to be executed. | |
1196 | |
1197 *:do* *:doau* *:doautocmd* *E217* | |
3356 | 1198 :do[autocmd] [<nomodeline>] [group] {event} [fname] |
7 | 1199 Apply the autocommands matching [fname] (default: |
1200 current file name) for {event} to the current buffer. | |
1201 You can use this when the current file name does not | |
1202 match the right pattern, after changing settings, or | |
1203 to execute autocommands for a certain event. | |
1204 It's possible to use this inside an autocommand too, | |
1205 so you can base the autocommands for one extension on | |
1206 another extension. Example: > | |
3224 | 1207 :au BufEnter *.cpp so ~/.vimrc_cpp |
1208 :au BufEnter *.cpp doau BufEnter x.c | |
7 | 1209 < Be careful to avoid endless loops. See |
1210 |autocmd-nested|. | |
1211 | |
1212 When the [group] argument is not given, Vim executes | |
1213 the autocommands for all groups. When the [group] | |
1214 argument is included, Vim executes only the matching | |
1215 autocommands for that group. Note: if you use an | |
1216 undefined group name, Vim gives you an error message. | |
3350 | 1217 *<nomodeline>* |
1218 After applying the autocommands the modelines are | |
1219 processed, so that their settings overrule the | |
1220 settings from autocommands, like what happens when | |
1221 editing a file. This is skipped when the <nomodeline> | |
1222 argument is present. You probably want to use | |
1223 <nomodeline> for events that are not used when loading | |
1224 a buffer, such as |User|. | |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
8951
diff
changeset
|
1225 Processing modelines is also skipped when no |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
8951
diff
changeset
|
1226 matching autocommands were executed. |
7 | 1227 |
1228 *:doautoa* *:doautoall* | |
3342 | 1229 :doautoa[ll] [<nomodeline>] [group] {event} [fname] |
7 | 1230 Like ":doautocmd", but apply the autocommands to each |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1919
diff
changeset
|
1231 loaded buffer. Note that [fname] is used to select |
7 | 1232 the autocommands, not the buffers to which they are |
1233 applied. | |
1234 Careful: Don't use this for autocommands that delete a | |
1235 buffer, change to another buffer or change the | |
1236 contents of a buffer; the result is unpredictable. | |
1237 This command is intended for autocommands that set | |
1238 options, change highlighting, and things like that. | |
1239 | |
1240 ============================================================================== | |
40 | 1241 10. Using autocommands *autocmd-use* |
7 | 1242 |
1243 For WRITING FILES there are four possible sets of events. Vim uses only one | |
1244 of these sets for a write command: | |
1245 | |
1246 BufWriteCmd BufWritePre BufWritePost writing the whole buffer | |
1247 FilterWritePre FilterWritePost writing to filter temp file | |
1248 FileAppendCmd FileAppendPre FileAppendPost appending to a file | |
1249 FileWriteCmd FileWritePre FileWritePost any other file write | |
1250 | |
1251 When there is a matching "*Cmd" autocommand, it is assumed it will do the | |
1252 writing. No further writing is done and the other events are not triggered. | |
1253 |Cmd-event| | |
1254 | |
1255 Note that the *WritePost commands should undo any changes to the buffer that | |
1256 were caused by the *WritePre commands; otherwise, writing the file will have | |
1257 the side effect of changing the buffer. | |
1258 | |
1259 Before executing the autocommands, the buffer from which the lines are to be | |
1260 written temporarily becomes the current buffer. Unless the autocommands | |
1261 change the current buffer or delete the previously current buffer, the | |
1262 previously current buffer is made the current buffer again. | |
1263 | |
1264 The *WritePre and *AppendPre autocommands must not delete the buffer from | |
1265 which the lines are to be written. | |
1266 | |
1267 The '[ and '] marks have a special position: | |
1268 - Before the *ReadPre event the '[ mark is set to the line just above where | |
1269 the new lines will be inserted. | |
1270 - Before the *ReadPost event the '[ mark is set to the first line that was | |
1271 just read, the '] mark to the last line. | |
26 | 1272 - Before executing the *WriteCmd, *WritePre and *AppendPre autocommands the '[ |
1273 mark is set to the first line that will be written, the '] mark to the last | |
1274 line. | |
7 | 1275 Careful: '[ and '] change when using commands that change the buffer. |
1276 | |
1277 In commands which expect a file name, you can use "<afile>" for the file name | |
1278 that is being read |:<afile>| (you can also use "%" for the current file | |
1279 name). "<abuf>" can be used for the buffer number of the currently effective | |
1280 buffer. This also works for buffers that doesn't have a name. But it doesn't | |
1281 work for files without a buffer (e.g., with ":r file"). | |
1282 | |
1283 *gzip-example* | |
1284 Examples for reading and writing compressed files: > | |
1285 :augroup gzip | |
1286 : autocmd! | |
1287 : autocmd BufReadPre,FileReadPre *.gz set bin | |
1288 : autocmd BufReadPost,FileReadPost *.gz '[,']!gunzip | |
1289 : autocmd BufReadPost,FileReadPost *.gz set nobin | |
1290 : autocmd BufReadPost,FileReadPost *.gz execute ":doautocmd BufReadPost " . expand("%:r") | |
1291 : autocmd BufWritePost,FileWritePost *.gz !mv <afile> <afile>:r | |
1292 : autocmd BufWritePost,FileWritePost *.gz !gzip <afile>:r | |
1293 | |
1294 : autocmd FileAppendPre *.gz !gunzip <afile> | |
1295 : autocmd FileAppendPre *.gz !mv <afile>:r <afile> | |
1296 : autocmd FileAppendPost *.gz !mv <afile> <afile>:r | |
1297 : autocmd FileAppendPost *.gz !gzip <afile>:r | |
1298 :augroup END | |
1299 | |
1300 The "gzip" group is used to be able to delete any existing autocommands with | |
1301 ":autocmd!", for when the file is sourced twice. | |
1302 | |
1303 ("<afile>:r" is the file name without the extension, see |:_%:|) | |
1304 | |
1305 The commands executed for the BufNewFile, BufRead/BufReadPost, BufWritePost, | |
1306 FileAppendPost and VimLeave events do not set or reset the changed flag of the | |
1307 buffer. When you decompress the buffer with the BufReadPost autocommands, you | |
1308 can still exit with ":q". When you use ":undo" in BufWritePost to undo the | |
1309 changes made by BufWritePre commands, you can still do ":q" (this also makes | |
1310 "ZZ" work). If you do want the buffer to be marked as modified, set the | |
1311 'modified' option. | |
1312 | |
1313 To execute Normal mode commands from an autocommand, use the ":normal" | |
1314 command. Use with care! If the Normal mode command is not finished, the user | |
1315 needs to type characters (e.g., after ":normal m" you need to type a mark | |
1316 name). | |
1317 | |
1318 If you want the buffer to be unmodified after changing it, reset the | |
1319 'modified' option. This makes it possible to exit the buffer with ":q" | |
1320 instead of ":q!". | |
1321 | |
1322 *autocmd-nested* *E218* | |
1323 By default, autocommands do not nest. If you use ":e" or ":w" in an | |
1324 autocommand, Vim does not execute the BufRead and BufWrite autocommands for | |
1325 those commands. If you do want this, use the "nested" flag for those commands | |
1326 in which you want nesting. For example: > | |
1327 :autocmd FileChangedShell *.c nested e! | |
1328 The nesting is limited to 10 levels to get out of recursive loops. | |
1329 | |
1330 It's possible to use the ":au" command in an autocommand. This can be a | |
1331 self-modifying command! This can be useful for an autocommand that should | |
1332 execute only once. | |
1333 | |
590 | 1334 If you want to skip autocommands for one command, use the |:noautocmd| command |
1335 modifier or the 'eventignore' option. | |
7 | 1336 |
1337 Note: When reading a file (with ":read file" or with a filter command) and the | |
1338 last line in the file does not have an <EOL>, Vim remembers this. At the next | |
1339 write (with ":write file" or with a filter command), if the same line is | |
1340 written again as the last line in a file AND 'binary' is set, Vim does not | |
1341 supply an <EOL>. This makes a filter command on the just read lines write the | |
1342 same file as was read, and makes a write command on just filtered lines write | |
1343 the same file as was read from the filter. For example, another way to write | |
1344 a compressed file: > | |
1345 | |
1346 :autocmd FileWritePre *.gz set bin|'[,']!gzip | |
1347 :autocmd FileWritePost *.gz undo|set nobin | |
1348 < | |
1349 *autocommand-pattern* | |
1350 You can specify multiple patterns, separated by commas. Here are some | |
1351 examples: > | |
1352 | |
1353 :autocmd BufRead * set tw=79 nocin ic infercase fo=2croq | |
1354 :autocmd BufRead .letter set tw=72 fo=2tcrq | |
1355 :autocmd BufEnter .letter set dict=/usr/lib/dict/words | |
1356 :autocmd BufLeave .letter set dict= | |
1357 :autocmd BufRead,BufNewFile *.c,*.h set tw=0 cin noic | |
1358 :autocmd BufEnter *.c,*.h abbr FOR for (i = 0; i < 3; ++i)<CR>{<CR>}<Esc>O | |
1359 :autocmd BufLeave *.c,*.h unabbr FOR | |
1360 | |
1361 For makefiles (makefile, Makefile, imakefile, makefile.unix, etc.): > | |
1362 | |
1363 :autocmd BufEnter ?akefile* set include=^s\=include | |
1364 :autocmd BufLeave ?akefile* set include& | |
1365 | |
1366 To always start editing C files at the first function: > | |
1367 | |
1368 :autocmd BufRead *.c,*.h 1;/^{ | |
1369 | |
1370 Without the "1;" above, the search would start from wherever the file was | |
1371 entered, rather than from the start of the file. | |
1372 | |
1373 *skeleton* *template* | |
1374 To read a skeleton (template) file when opening a new file: > | |
1375 | |
1376 :autocmd BufNewFile *.c 0r ~/vim/skeleton.c | |
1377 :autocmd BufNewFile *.h 0r ~/vim/skeleton.h | |
1378 :autocmd BufNewFile *.java 0r ~/vim/skeleton.java | |
1379 | |
1380 To insert the current date and time in a *.html file when writing it: > | |
1381 | |
1382 :autocmd BufWritePre,FileWritePre *.html ks|call LastMod()|'s | |
1383 :fun LastMod() | |
1384 : if line("$") > 20 | |
1385 : let l = 20 | |
1386 : else | |
1387 : let l = line("$") | |
1388 : endif | |
1389 : exe "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " . | |
1390 : \ strftime("%Y %b %d") | |
1391 :endfun | |
1392 | |
1393 You need to have a line "Last modified: <date time>" in the first 20 lines | |
1394 of the file for this to work. Vim replaces <date time> (and anything in the | |
1395 same line after it) with the current date and time. Explanation: | |
1396 ks mark current position with mark 's' | |
1397 call LastMod() call the LastMod() function to do the work | |
1398 's return the cursor to the old position | |
1399 The LastMod() function checks if the file is shorter than 20 lines, and then | |
1400 uses the ":g" command to find lines that contain "Last modified: ". For those | |
1401 lines the ":s" command is executed to replace the existing date with the | |
1402 current one. The ":execute" command is used to be able to use an expression | |
1403 for the ":g" and ":s" commands. The date is obtained with the strftime() | |
1404 function. You can change its argument to get another date string. | |
1405 | |
1406 When entering :autocmd on the command-line, completion of events and command | |
1407 names may be done (with <Tab>, CTRL-D, etc.) where appropriate. | |
1408 | |
1409 Vim executes all matching autocommands in the order that you specify them. | |
1410 It is recommended that your first autocommand be used for all files by using | |
1411 "*" as the file pattern. This means that you can define defaults you like | |
1412 here for any settings, and if there is another matching autocommand it will | |
1413 override these. But if there is no other matching autocommand, then at least | |
1414 your default settings are recovered (if entering this file from another for | |
1415 which autocommands did match). Note that "*" will also match files starting | |
1416 with ".", unlike Unix shells. | |
1417 | |
1418 *autocmd-searchpat* | |
1419 Autocommands do not change the current search patterns. Vim saves the current | |
1420 search patterns before executing autocommands then restores them after the | |
1421 autocommands finish. This means that autocommands do not affect the strings | |
1422 highlighted with the 'hlsearch' option. Within autocommands, you can still | |
1423 use search patterns normally, e.g., with the "n" command. | |
1424 If you want an autocommand to set the search pattern, such that it is used | |
1425 after the autocommand finishes, use the ":let @/ =" command. | |
1426 The search-highlighting cannot be switched off with ":nohlsearch" in an | |
1427 autocommand. Use the 'h' flag in the 'viminfo' option to disable search- | |
1428 highlighting when starting Vim. | |
1429 | |
1430 *Cmd-event* | |
1431 When using one of the "*Cmd" events, the matching autocommands are expected to | |
1061 | 1432 do the file reading, writing or sourcing. This can be used when working with |
1433 a special kind of file, for example on a remote system. | |
7 | 1434 CAREFUL: If you use these events in a wrong way, it may have the effect of |
1435 making it impossible to read or write the matching files! Make sure you test | |
1436 your autocommands properly. Best is to use a pattern that will never match a | |
1437 normal file name, for example "ftp://*". | |
1438 | |
1439 When defining a BufReadCmd it will be difficult for Vim to recover a crashed | |
1440 editing session. When recovering from the original file, Vim reads only those | |
1441 parts of a file that are not found in the swap file. Since that is not | |
1442 possible with a BufReadCmd, use the |:preserve| command to make sure the | |
1443 original file isn't needed for recovery. You might want to do this only when | |
1444 you expect the file to be modified. | |
1445 | |
1061 | 1446 For file read and write commands the |v:cmdarg| variable holds the "++enc=" |
1447 and "++ff=" argument that are effective. These should be used for the command | |
1448 that reads/writes the file. The |v:cmdbang| variable is one when "!" was | |
1449 used, zero otherwise. | |
7 | 1450 |
2377
878562053ba3
Update Fortran indent and syntax file. (Ajit Thakkar)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
1451 See the $VIMRUNTIME/plugin/netrwPlugin.vim for examples. |
7 | 1452 |
590 | 1453 ============================================================================== |
1454 11. Disabling autocommands *autocmd-disable* | |
1455 | |
1456 To disable autocommands for some time use the 'eventignore' option. Note that | |
1457 this may cause unexpected behavior, make sure you restore 'eventignore' | |
1458 afterwards, using a |:try| block with |:finally|. | |
1459 | |
1460 *:noautocmd* *:noa* | |
1461 To disable autocommands for just one command use the ":noautocmd" command | |
1462 modifier. This will set 'eventignore' to "all" for the duration of the | |
1463 following command. Example: > | |
1464 | |
1465 :noautocmd w fname.gz | |
1466 | |
1467 This will write the file without triggering the autocommands defined by the | |
1468 gzip plugin. | |
1469 | |
40 | 1470 |
7 | 1471 vim:tw=78:ts=8:ft=help:norl: |