For example, what's the difference between calling this command this way:
autocmd BufWritePre * call StripTrailingWhitespace()
vs. this way (with the bang after autocmd):
autocmd! BufWritePre * call StripTrailingWhitespace()
The command
autocmd! BufWritePre * call StripTrailingWhitespace()
Removes all autocmds for the event BufWritePre and the file pattern * from the default autocmd-group and sets a new autocmd for this event and pattern to call StripTrailingWhitespace().
Example:
autocmd BufWritePre * echomsg "First"
autocmd BufWritePre * echomsg "Second"
If you then enter :autocmd BufWritePre you will get the following (plus maybe other autocmds defined for this event):
--- Autocommands ---
BufWrite
* echomsg "First"
echomsg "Second"
Then you execute
autocmd! BufWritePre * echomsg "Third"
followed by :autocmd BufWritePre and you get:
--- Autocommands ---
BufWrite
* echomsg "Third"
So the autocmds echoing "First" and "Second" were removed and the new autocmd echoing "Third" was defined.
See :help autocmd-remove.
autocmd!command, you're fine withoutaugroups. Otherwise, shared eventautocmd!s will clear each other. So, wrapping yourautocmdcommands inside anaugroupis the safer option here. – aonemd May 05 '19 at 13:31vimrcand wrapped even this single cmd in a group calledmy_syntax_autocmds. – Ralf May 05 '19 at 14:36