"

Level 2 Linux Exercises

Linux Exercise #2.8 – Unexpected Situations (Swap Files)

Background Information

IMPORTANT:

If you like to use background/foreground modes with editors, please read this section careful. Use with caution!

  1. Backgrounding/Foregrounding Vim: Use care when working with files in the background. If your changes are not saved, when re-compiling programs the changes will not be in effect. You also have a higher risk of having left over swap files which can be problematic. Only use background mode if you are an advanced vim user:
    1. Send current session to the background control  z
    2. Return to the most recent background session fg
  2. Temporary swap files are created for files that have been opened. If vim is exited or killed without using the typical quit command, a swap file will be left over from that session. To resolve use the following:
    1. When opening a file that has a swap file, you should first try to determine if your file is still open but in the background. To do this, first abort the request to pen a file: Type “a” to abort. Now you are back at the command line.
    2. To determine if your file is still open (but in the background), type “fg
      • If this opens your file, then just continue editing and next time use “fg” if you used ctrl z.
      • If you commonly receive swap files, avoid using the background mode. It is not necessary to program!
    3. If there were no files in the background, then determine if there are swap files in your directory. Type “ls -a” to see if a .swp file exists for the file you were trying to open. The -a flag shows what hidden files are in the directory
      • If it exists, you will need to see which file has your newest changes
      • Check both the .swp and the regular file
    4. Examine the swap file
      • If the .swp file is not current, remove the swap file  (use the rm command)
      • If the .swp file is current, you will need to recover the file by typing “r” when first opening it. This will merge the files and remove the .swp file from your directory and you can just use the file as normal.

Handling Unexpected Situations

 

License

CS Linux & Vim Manual Copyright © by Karla Fant. All Rights Reserved.

Share This Book