|
1 | | -*autocmd.txt* For Vim version 8.0. Last change: 2016 Sep 21 |
| 1 | +*autocmd.txt* For Vim version 8.0. Last change: 2016 Sep 27 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -79,11 +79,15 @@ exception is that "<sfile>" is expanded when the autocmd is defined. Example: |
79 | 79 |
|
80 | 80 | Here Vim expands <sfile> to the name of the file containing this line. |
81 | 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: > |
| 82 | +`:autocmd` adds to the list of autocommands regardless of whether they are |
| 83 | +already present. When your .vimrc file is sourced twice, the autocommands |
| 84 | +will appear twice. To avoid this, define your autocommands in a group, so |
| 85 | +that you can easily clear them: > |
85 | 86 |
|
86 | | - :autocmd! " Remove ALL autocommands for the current group. |
| 87 | + augroup vimrc |
| 88 | + autocmd! " Remove all vimrc autocommands |
| 89 | + au BufNewFile,BufRead *.html so <sfile>:h/html.vim |
| 90 | + augroup END |
87 | 91 |
|
88 | 92 | If you don't want to remove all autocommands, you can instead use a variable |
89 | 93 | to ensure that Vim includes the autocommands only once: > |
@@ -130,8 +134,13 @@ prompt. When one command outputs two messages this can happen anyway. |
130 | 134 |
|
131 | 135 | :au[tocmd]! [group] {event} |
132 | 136 | Remove ALL autocommands for {event}. |
| 137 | + Warning: You should not do this without a group for |
| 138 | + |BufRead| and other common events, it can break |
| 139 | + plugins, syntax highlighting, etc. |
133 | 140 |
|
134 | 141 | :au[tocmd]! [group] Remove ALL autocommands. |
| 142 | + Warning: You should normally not do this without a |
| 143 | + group, it breaks plugins, syntax highlighting, etc. |
135 | 144 |
|
136 | 145 | When the [group] argument is not given, Vim uses the current group (as defined |
137 | 146 | with ":augroup"); otherwise, Vim uses the group defined with [group]. |
|
0 commit comments