Edit Multiple Files in VI

Here's what I have...

$ vi foo1

  • open foo1 and work around for a while. I yank a few lines into a buffer and then :w to save.

Next I :e foo2 to open foo2 and paste my buffer. I :w to save, but I would like to then be able to go directly back into foo1 where I was before I opened foo2. Is that possible?

When yanking, put the lines you want to copy into a named buffer, then edit the other file. E.g.,

$ vi foo1
"a3yy
:e foo2
3G
"ap
:wq

Use your favorite variation on "y" and "p" commands.

Correct, but that still exits all the way out of VI. I would like to save and close the second file (foo2) and then be directly back into the first file (foo1).

No problem. Change the final

:wq

to

:w
:e#

Sorry if I misread your original post.

Beauty. Thanks, criglerj.