1

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:

  1. Start a new tmux session
  2. vim foo.txt
  3. Write something and write
  4. Detatch from tmux session
  5. Reattach to tmux session
  6. Quit vim
  7. 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.

1
  • This sounds peculiar. When I edit Vim files on e.g. remote media, what happens is that the Vim interface waits until it can verify that the file has been written. I do this often, and I have never experienced what you describe. I would say that more information is needed, such as file system on the partition, versions of programs, etc., and it is probably subject to an upstream bug report of Vim/tmux/both if you are able to reproduce it. Vim should not proceed until the writing is verified, and tmux should not (can not?) interfere with any such operations. tmux is probably not to blame. Jul 18, 2013 at 18:41

1 Answer 1

0

Writing a file in vim doesn't change any files. The old file is replaced by a new file, leaving the old file unmodified. So if you have the old file opened somewhere else, you won't see any changes. Vim is not designed to modify a file while some other program is using it.

2
  • I think therefore, maybe, that something dodgy maybe going on with attaching to my tmux session which ends up invoking multiple instances of Vim... Let me investigate and see if I can consistently replicate the problem. Jul 19, 2013 at 9:42
  • See edit for steps to replicate Aug 5, 2013 at 15:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .