When I left work yesterday I left vim open with the files I was working on. I'm working from home today, so I VPN'ed in, and when I go to edit those same files, I get the warning that there's another current vim session open with those files.

I know I could just force logout my other user, but that would kill the existing vim session. I think my changes would all be saved in the .swp file.

Instead, is it possible for me to take that existing vim session and open it with my second login? That way it would for sure preserve all my changes, and I wouldn't have to open all the same tabs again.


5 Answers 5


You can kill vim (but don't use -9) and all your changes will be saved in the .swp files. Then you start a new vim and use Recover.


How about using screen or tmux as an alternative? That way you can disconnect your screen session when you are done and then login later (possibly from another machine) and reconnect.


reptyr: Utility for taking an existing running program and attaching it to a new terminal

From the man page: "reptyr is a utility for taking an existing running program and attaching it to a new terminal. Started a long-running process over ssh, but have to leave and don't want to interrupt it? Just start a screen, use reptyr to grab it, and then kill the ssh session and head on home."


You are correct that a forced logout / kill of your other vim process will allow you to pickup the ".swp" file left behind and start working with it. Just tested this theory and it worked on Ubuntu anyway. Just make sure you select the "Recover" option when it tells you a swap file already exists.

That should get any modifications that have not been saved, but I'm not sure about other session info like command history.

  • ...and obviously, it only works when you do in fact have swap files - if you're editing a file in a directory where you can't create new files, vim won't be able to create the swap file (and tell you so). Things will still work, but unsaved changes will be lost when you kill vim.
    – tdammers
    Sep 14, 2011 at 5:06

You can't take over processes that have been started from another terminal. Had you started vim inside screen, you would have been able to detach the screen session and then reattach from a different terminal (including an external one over ssh).

Then there's retty, but it's not available for all hardware platforms, and it's in an experiental stage - basically, use at your own risk.

Another option is to do :mks (make session) every now and then; if you then kill vim and start it from a different terminal, you can simply source the Session.vim file that the mks command has created (or start vim with vim -S Session.vim) and resume your session (you may have to respond to a few restore prompts though).

You must log in to answer this question.

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