Q: I am unable to edit my file in vim. There is an error message about some "swap file". What is that?

When you see the message about some "swap file", it is likely that you have done something wrong in you vim session, or exited from vim in the wrong manner. As a result, vim created a swap file for you, and prevents you from editing the file again.

For example, if something went wrong while you were editing prog1.c, a swap file called .prog1.c.swp would be created. A message like this would appear:

Swap file ".prog1.c.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: 

To rectify the problem, enter 'q' to quit or 'a' to abort. Then delete the swap file:

       rm .prog1.c.swp

This will fix the problem. Then edit the file as per normal:

       vim prog1.c

Pressing ctrl-z instead of ZZ

Another possible reason is the wrong manner you exited vim. Sometimes students want to enter ZZ to save the file and exit from vim, but instead of pressing the <shift> key, they press the <ctrl> key instead. As a result, ctrl-z was pressed.

In UNIX, pressing ctrl-z puts a job into background. In this case, it appears that you have exited from vim, but actually vim is still running in the background.

(If you have a background job running, when you try to log out from your sunfire account by entering exit or logout, you will get the message "There are stopped jobs." and you still remain in your sunfire account. What your exit or logout command did was to kill your job in the background. You need to enter exit or logout again to truly log out from your sunfire account.)

If you realise that you have just entered ctrl-z by mistake and put your vim session into the background, you may bring it back to the foreground by typing:

       fg

Aaron