patch 8.1.1113: making an autocommand trigger once is not so easy
Problem: Making an autocommand trigger once is not so easy.
Solution: Add the ++once argument. Also add ++nested as an alias for
"nested". (Justin M. Keyes, closes #4100)
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 6480d72..5eb1936 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -1,4 +1,4 @@
-*autocmd.txt* For Vim version 8.1. Last change: 2019 Mar 13
+*autocmd.txt* For Vim version 8.1. Last change: 2019 Apr 04
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -52,7 +52,7 @@
2. Defining autocommands *autocmd-define*
*:au* *:autocmd*
-:au[tocmd] [group] {event} {pat} [nested] {cmd}
+:au[tocmd] [group] {event} {pat} [++once] [++nested] {cmd}
Add {cmd} to the list of commands that Vim will
execute automatically on {event} for a file matching
{pat} |autocmd-patterns|.
@@ -60,7 +60,13 @@
:autocmd and won't start a comment.
Vim always adds the {cmd} after existing autocommands,
so that the autocommands execute in the order in which
- they were given. See |autocmd-nested| for [nested].
+ they were given.
+ See |autocmd-nested| for [++nested]. "nested"
+ (without the ++) can also be used, for backwards
+ compatibility.
+ *autocmd-once*
+ If [++once] is supplied the command is executed once,
+ then removed ("one shot").
The special pattern <buffer> or <buffer=N> defines a buffer-local autocommand.
See |autocmd-buflocal|.
@@ -128,10 +134,11 @@
==============================================================================
3. Removing autocommands *autocmd-remove*
-:au[tocmd]! [group] {event} {pat} [nested] {cmd}
+:au[tocmd]! [group] {event} {pat} [++once] [++nested] {cmd}
Remove all autocommands associated with {event} and
- {pat}, and add the command {cmd}. See
- |autocmd-nested| for [nested].
+ {pat}, and add the command {cmd}.
+ See |autocmd-once| for [++once].
+ See |autocmd-nested| for [++nested].
:au[tocmd]! [group] {event} {pat}
Remove all autocommands associated with {event} and
@@ -1473,7 +1480,7 @@
an autocommand, Vim does not execute the BufRead and BufWrite autocommands for
those commands. If you do want this, use the "nested" flag for those commands
in which you want nesting. For example: >
- :autocmd FileChangedShell *.c nested e!
+ :autocmd FileChangedShell *.c ++nested e!
The nesting is limited to 10 levels to get out of recursive loops.
It's possible to use the ":au" command in an autocommand. This can be a