I think I observe a weird behaviour in Vim autocommands, in which opening a new buffer changes the result of past commands (!).
Here is a simple example (VIM 7.3 2010 Aug 15). I just created a file test
containing only the line 'disk version', then save this file to disk. Keeping this file test
open in Vim, I change the text to "SWAP VERSION", without saving: now the file test
has an associated swap file.
Null case:
Instead of a .vimrc
, I write a init.vim
file containing a single autocommand, typing out the content of a file at time of BufRead
invocation:
au BufRead * %p
When I then load vim -u init.vim test
and hit the r key to accept swap recovery, the autocommand prints out 'SWAP VERSION' as expected.
Strange case:
I change the autocommand in init.vim
in the following way:
au BufRead * %p | new
The same procedure (vim -u init.vim test
, r) now prints out 'disk version'. In other words, the new
command has modified the content of the buffer at the time when the previous command was executed. Replacing the new
command by an inoffensive echo
returns to the "null" case.
Does any Vim wizard know what, exactly, is happening here?
(Edit) Context:
I am trying to build a (very simplified) version of recover.vim
.
- Why not use the existing plugin
recover.vim
? Because I'm trying to do something that is both (probably) simpler and different from what it does. Plus, this plugin uses lots of shell escapes, which is bad in my context. I would happily sacrifice functionality to get rid of these escapes. - I should at least look at how
recover.vim
does: Probably. But since it is rather complex to follow, I thought that working up from the documentation would be easier... (I will, however, have a go at older github revisions ofrecover.vim
). - I'm using an old Vim version: I have no choice here (not admin and not even compile rights in this environment).