autocommands from the
default group separately; you can execute them only by executing autocommands
for all groups.
Normally, when executing autocommands automatically, Vim uses the autocommands
for all groups. The group only matters when executing autocommands with
":doautocmd" or ":doautoall", or when defining or deleting autocommands.
The group name can contain any characters except white space. The group name
"end" is reserved (also in uppercase).
The group name is case sensitive. Note that this is different from the event
name!
*:aug* *:augroup*
:aug[roup] {name} Define the autocmd group name for the
following ":autocmd" commands. The name "end"
or "END" selects the default group.
To avoid confusion, the name should be
different from existing {event} names, as this
most likely will not do what you intended.
*:augroup-delete* *E367* *W19* *E936*
:aug[roup]! {name} Delete the autocmd group {name}. Don't use
this if there is still an autocommand using
this group! You will get a warning if doing
it anyway. When the group is the current
group you will get error E936.
To enter autocommands for a specific group, use this method:
1. Select the group with ":augroup {name}".
2. Delete any old autocommands with ":au!".
3. Define the autocommands.
4. Go back to the default group with "augroup END".
Example: >
:augroup uncompress
: au!
: au BufEnter *.gz %!gunzip
:augroup END
This prevents having the autocommands defined twice (e.g., after sourcing the
vimrc file again).
*FileExplorer*
There is one group that is recognized by Vim: FileExplorer. If this group
exists Vim assumes that editing a directory is possible and will trigger a
plugin that lists the files in that directory. This is used by directory
browser plugins. This allows you to do: >
browse edit
==============================================================================
9. Executing autocommands *autocmd-execute*
Vim can also execute Autocommands non-automatically. This is useful if you
have changed autocommands, or when Vim has executed the wrong autocommands
(e.g., the file pattern match was wrong).
Note that the 'eventignore' option applies here too. Events listed in this
option will not cause any commands to be executed.
*:do* *:doau* *:doaut* *:doautocmd* *E217*
:do[autocmd] [<nomodeline>] [group] {event} [fname]
Apply the autocommands matching [fname] (default:
current file name) for {event} to the current buffer.
You can use this when the current file name does not
match the right pattern, after changing settings, or
to execute autocommands for a certain event.
It's possible to use this inside an autocommand too,
so you can base the autocommands for one extension on
another extension. Example: >
:au BufEnter *.cpp so ~/.config/nvim/init_cpp.vim
:au BufEnter *.cpp doau BufEnter x.c
< Be careful to avoid endless loops. |autocmd-nested|
When the [group] argument is not given, Vim executes
the autocommands for all groups. When the [group]
argument is included, Vim executes only the matching
autocommands for that group. Undefined group is an
error.
*<nomodeline>*
After applying the autocommands the modelines are
processed, so that their settings overrule the
settings from autocommands when editing a file. This
is skipped if <nomodeline> is specified. You probably
want to use <nomodeline> for events not used when
loading a buffer, such as |User|.
Modelines are also skipped when no matching
autocommands were executed.
*:doautoa* *:doautoall*
:doautoa[ll] [<nomodeline>] [group] {event} [fname]
Like ":doautocmd", but apply the autocommands to each
loaded buffer. The current buffer is done last.
Note that [fname] is used to select the autocommands,
not the buffers to which they are applied. Example: >
augroup mine
autocmd!
autocmd FileType * echo expand('<amatch>')