On 8/31/06, Elliot Shank <[EMAIL PROTECTED]> wrote:
I've got a situation similar to the following:
augroup A
autocmd BufWritePre <buffer> [stuff that changes the buffer before writing]
augroup END
augroup B
autocmd BufWritePre <buffer> [stuff that changes the buffer before writing]
autocmd BufWritePost <buffer> undo
augroup END
Obviously, in group A I'm trying to make a change in the buffer as well as on
disk. In group B, I'm trying to only make a change to disk.
The command handlers are invoked in the order seen. First Pre A, then Pre B,
then Post B.
The problem is that the post command in group B is undoing
the changes from group A, as well from itself. The problem is
that it isn't easy to reverse the modifications in Pre B, other
than by invoking :undo.
1. What happens here is that edits from sequential noninteractive
commands are considered as one undo block. You want
to insert "undo break" at the beginning of Pre B (or at the
and of Pre B).
There is a method of inserting "undo break" from a script.
I forgot exactly how it is done, but maybe it is
|i_CTRL-G_u| CTRL-G u start new undoable edit
, thus something like :exe ":normal i\<c-G>u\<esc>"
(untested), see
:help i_CTRL-G_u
2. However, if you do this, you'll break recommendation
which is described in autocmds.txt line 1045:
Note that the *WritePost commands should undo any changes to the buffer that
were caused by the *WritePre commands; otherwise, writing the file will have
the side effect of changing the buffer.
Yakov