|
1 |
| -*autocmd.txt* For Vim version 9.0. Last change: 2022 Apr 17 |
| 1 | +*autocmd.txt* For Vim version 9.0. Last change: 2022 May 24 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar
|
@@ -47,6 +47,28 @@ effects. Be careful not to destroy your text.
|
47 | 47 | It's a good idea to use the same autocommands for the File* and Buf* events
|
48 | 48 | when possible.
|
49 | 49 |
|
| 50 | +Recommended use: |
| 51 | +- Always use a group, so that it's easy to delete the autocommand. |
| 52 | +- Keep the command itself short, call a function to do more work. |
| 53 | +- Make it so that the script it is defined in can be sourced several times |
| 54 | + without the autocommand being repeated. |
| 55 | + |
| 56 | +Example in Vim9 script: > |
| 57 | + autocmd_add({replace: true, |
| 58 | + group: 'DemoGroup', |
| 59 | + event: 'BufEnter', |
| 60 | + pattern: '*.txt', |
| 61 | + cmd: 'call DemoBufEnter()' |
| 62 | + }) |
| 63 | +
|
| 64 | +In legacy script: > |
| 65 | + call autocmd_add(#{replace: v:true, |
| 66 | + \ group: 'DemoGroup', |
| 67 | + \ event: 'BufEnter', |
| 68 | + \ pattern: '*.txt', |
| 69 | + \ cmd: 'call DemoBufEnter()' |
| 70 | + \ }) |
| 71 | +
|
50 | 72 | ==============================================================================
|
51 | 73 | 2. Defining autocommands *autocmd-define*
|
52 | 74 |
|
@@ -82,6 +104,10 @@ triggered.
|
82 | 104 | /<start
|
83 | 105 | }
|
84 | 106 |
|
| 107 | +The |autocmd_add()| function can be used to add a list of autocmds and autocmd |
| 108 | +groups from a Vim script. It is preferred if you have anything that would |
| 109 | +require using `:execute` with `:autocmd`. |
| 110 | + |
85 | 111 | Note: The ":autocmd" command can only be followed by another command when the
|
86 | 112 | '|' appears where the pattern is expected. This works: >
|
87 | 113 | :augroup mine | au! BufRead | augroup END
|
@@ -146,6 +172,9 @@ prompt. When one command outputs two messages this can happen anyway.
|
146 | 172 | ==============================================================================
|
147 | 173 | 3. Removing autocommands *autocmd-remove*
|
148 | 174 |
|
| 175 | +In addition to the below described commands, the |autocmd_delete()| function can |
| 176 | +be used to remove a list of autocmds and autocmd groups from a Vim script. |
| 177 | + |
149 | 178 | :au[tocmd]! [group] {event} {aupat} [++once] [++nested] {cmd}
|
150 | 179 | Remove all autocommands associated with {event} and
|
151 | 180 | {aupat}, and add the command {cmd}.
|
@@ -198,6 +227,9 @@ argument behavior differs from that for defining and removing autocommands.
|
198 | 227 | In order to list buffer-local autocommands, use a pattern in the form <buffer>
|
199 | 228 | or <buffer=N>. See |autocmd-buflocal|.
|
200 | 229 |
|
| 230 | +The |autocmd_get()| function can be used from a Vim script to get a list of |
| 231 | +autocmds. |
| 232 | + |
201 | 233 | *:autocmd-verbose*
|
202 | 234 | When 'verbose' is non-zero, listing an autocommand will also display where it
|
203 | 235 | was last defined. Example: >
|
|
0 commit comments