Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Sep 14 '11 at 4:05

This question came from our site for professional and enthusiast programmers.

5 Answers 5

up vote 2 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
...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 '11 at 5:06

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.

share|improve this answer

There is this small program called retty, but I have absolutely no idea how reliable it is.

share|improve this answer

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.