I have noticed that, while using Vim in tmux over an SSH session, when I write a buffer to disk (i.e., :w
) occasionally, while Vim says it's been written, the file remains unchanged. In fact, often when this happens, Vim will complain about the file already having changed because, presumably, the .swp
version of the file is further ahead than expected.
To sometimes get around this problem, I save to a new file, exit, delete the old one, then rename the new one. More often than not, however, the affect goes unnoticed and I end up losing work... It's very frustrating!
Any idea what's happening here? It only happens while in tmux and I'm the only user attaching to the session. If I close the tmux session (rather than detach), Vim no longer complains about the swap file when I log back in.
I can consistently replicate this (or similar, at least) by doing the following:
- Start a new tmux session
vim foo.txt
- Write something and write
- Detatch from tmux session
- Reattach to tmux session
- Quit vim
vim foo.txt
Vim will now complain that a swap file exists for foo.txt
(e.g., .foo.txt.swp
), even though there doesn't seem to be one in the current directory.