Question: I'm using NeoVim and trying to understand why the need of creating `augroup`. Then I realized that I don't know the two related commands `doautoall`, `doautocmd`. Can anyone help me point out the important part I should care?

To be more specific, under `:h doautocmd`, I cannot understand this paragraph:

> 
> 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.
> 
> 
> 

What does it mean "executes the autocommands for all groups" when these groups are `autocmd`s to execute?

---

As this is an important topic to me, I will also try to answer myself after I would figure it out.

Answer: 
> 
> why the need of creating augroup.
> 
> 
> 

Groups are used, well, for grouping autocmds. This is essential for managing them. If none was specified then the next autocmd will get into the default augroup.

> 
> I don't know the two related commands doautoall, doautocmd
> 
> 
> 

Basically, "doautoall" loops over all loaded buffers/windows and calls "doautocmd" repeatedly. There are several nuances, of course. E.g. no other autocmd (BufEnter, BufLeave, WinEnter, WinLeave etc.etc.) will be triggered during the loop; if a buffer has no window (not in the current tab or no window at all) then the special "autocmd" window will be used instead and so on.

> 
> What does it mean "executes the autocommands for all groups"
> 
> 
> 

If a group was specified then only autocmds from that group may be executed (the ones that match all other attributes, of course). Otherwise, it works "as normal".
Q: *What does it mean "executes the autocommands for all groups" when these groups are `autocmd`s to execute?*

You can read it as "executes the autocommands **from** all groups".

---

For `doau`, it will run all matched(the optional `[fname]` argument you provided) autocmds of the specified augroup. I will show you an example.

First, open any file (in my case `git.lua`) and run the following commands:

```lua
:aug FRANK -- this creates an augroup
:au FRANK BufEnter * echo "Hi, *"
:au FRANK BufEnter *.lua echo "Hi, *.lua"
:au FRANK BufEnter git.lua echo "Hi, git.lua"

```

Then call `:h doau`, this will move your cursor to the help-docs. Now call `:doau FRANK BufEnter`, you will see:

```
hi *

```

then move your cursor to your "any file" (`git.lua` in my case) and run `:doau FRANK BufEnter` again. You will see (something similar to):

```
hi *
hi *.lua
hi git.lua

```

This proves that this line of the docs is correct (see `:h doau`):

```
Apply the autocommands matching [fname] (default:
            current file name) for {event} to the current buffer.

```

Finally, `:doautoa` will do `:doau` many times.