# autocmd
[toc]
## usage使用
:::success
:au[tocmd] [group] {event} {aupat} [++once] [++nested] {cmd}
```
Add {cmd} to the list of commands that Vim will
execute automatically on {event} for a file matching {aupat} autocmd-pattern.
A quote character is seen as argument to the :autocmd and won't start a comment.
Nvim always adds {cmd} after existing autocommands so they execute in the order in which they were defined.See autocmd-nested for [++nested].
autocmd-once
If [++once] is supplied the command is executed once, then removed ("one shot").
```
:::
### augroup
:::success
augroup vimrc
" Remove all vimrc autocommands
autocmd!
au BufNewFile,BufRead *.html so <sfile>:h/html.vim
augroup END
:::
### usage
:::success
:au[tocmd]! [group] {event} {aupat} [++once] [++nested] {cmd}
```
Remove all autocommands associated with {event} and
{aupat}, and add the command {cmd}.
See autocmd-once for [++once].
See autocmd-nested for [++nested].
```
:au[tocmd]! [group] {event} {aupat}
```Remove all autocommands associated with {event} and
{aupat}.
:au[tocmd]! [group] * {aupat} #Remove all autocommands associated with {aupat} for all events.
:au[tocmd]! [group] {event} # Remove ALL autocommands for {event}. You should not do this without a group for
BufRead and other common events, it can break
plugins, syntax highlighting, etc.
:au[tocmd]! [group] Remove ALL autocommands.
a quote will be seen as argument to the :autocmd
and won't start a comment.
Warning: You should normally not do this without a group, it breaks plugins, syntax highlighting, etc.
When the [group] argument is not given, Vim uses the current group (as defined
with ":augroup"); otherwise, Vim uses the group defined with [group].
:::