Describe the bug
With the directory option set to specify a directory to hold vim swap files, vim -r in a different directory misreports the original file name
To Reproduce
$ mkdir ~/vimswap ~/FOO ~/BAR
$ echo 'set directory=~/vimswap' > ~/.vimrc.test
$ echo 'This is FOO/tmp' > ~/FOO/tmp
$ cd FOO
$ vim -u ~/.vimrc.test tmp
(suspend with Ctrl-Z)
$ cd ~/BAR
$ vim -u ~/.vimrc.test -r tmp
Error message:
Using swap file "~/vimswap/tmp.swp"
Original file "~/BAR/tmp"
"~/BAR/tmp" [New File]
E309: Unable to read block 1 from /home/kst/vimswap/tmp.swp
Press ENTER or type command to continue
Expected behavior
The reported file name should be ~/FOO/tmp, not ~/BAR/tmp.
Note that the swap file does contain the correct information
Environment:
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
![]()
You apparently suspended the first Vim instance before it could write to the swap file. If you wait a bit, or use :preserve, then the recovery will actually work. But you get the contents of ~/FOO/tmp in ~/BAR/tmp. That is because the file name is not checked, it could be a symbolic link to the same file.
Although it's a bit strange, I don't see how this can be avoided without breaking something else (editing a file via a symlink).