Linux E325Medium

Vim E325 Error: Swap File Already Exists — Solutions

The article explains how to resolve the swap file error in Vim on Linux, including causes, solutions, and preventive measures.

Updated at February 17, 2026
5-10 minutes
Easy
FixPedia Team
Применимо к:Vim 7.4 and aboveLinux (Ubuntu, Debian, Fedora, CentOS)

E325: ATTENTION Found a swap file by the name ".file.txt.swp" ...


A swap file is a temporary file that Vim automatically creates when you open a file. Its primary purpose is to allow you to recover changes in case of an abnormal termination of Vim (for example, due to a system crash or forced terminal closure). Error E325 blocks further editing until you make a decision: recover the session from the swap file, delete it, or open the file as read-only.

## Causes

The "swap file already exists" error can be caused by the following:

1. **Unfinished previous Vim session**: If Vim was closed abnormally (e.g., via `kill` or a system crash), the swap file remains on disk, and Vim detects it the next time you open the file.
2. **Active session in another process or terminal**: The file is already being edited in another Vim instance (possibly in another terminal window or remotely via SSH), and the swap file was created by that process.
3. **Manual creation or copying of the swap file**: The swap file might have been copied from another directory or created manually by mistake.
4. **Permission issues**: Vim cannot delete or check an existing swap file due to insufficient permissions, leading to a false detection.
5. **Filesystem error**: In rare cases, filesystem metadata corruption can cause incorrect swap file detection.

## Solutions

There are several methods to resolve error E325, from simply deleting the swap file to configuring Vim to use a separate directory. It's recommended to start with the first method, as it solves the problem in most cases.

### Method 1: Delete the Swap File (Recommended)

This method is suitable when you are sure the swap file is left over from a completed session or does not contain needed changes.

1. **Locate the swap file path**. When the error appears, Vim displays the full path to the swap file, for example: `.file.txt.swp`. Remember this path or manually find the file in the directory of the file being edited. Swap files usually start with a dot and end with `.swp`.
2. **Check for active Vim sessions**. Run this command in the terminal to ensure no other Vim processes are working with the same file:
   ```bash
   ps aux | grep vim

If the output includes processes with your file's name, exit them properly (e.g., via :qa in Vim) or force-kill them (kill PID) only if you are certain. 3. Delete the swap file. Use the rm command with the specified path. For example:

rm .file.txt.swp

If a permission error occurs, add sudo (but be careful not to delete someone else's swap file):

sudo rm .file.txt.swp
  1. Open the file again in Vim:
    vim file.txt
    
    The E325 error should no longer appear.

⚠️ Important: Only delete swap files if you are absolutely sure they are not needed to recover changes. Otherwise, use Method 3.

Method 2: Open File in Read-Only Mode

If you want to view the file without risking loss of changes from the swap file, open it in read-only mode, ignoring the swap file.

  1. When the E325 error appears, press O (capital O) in response to Vim's prompt. This opens the file in read-only mode (read-only).
  2. Alternatively, launch Vim with the -R flag:
    vim -R file.txt
    
    The file will open, but you cannot make changes. To edit, switch to write mode with :w! (if you have permissions), but this is not recommended without checking the swap file first.

This method is useful for quick viewing but not for editing.

Method 3: Recover from the Swap File

If the swap file contains unfinished changes you want to keep, recover the session.

  1. When the E325 error appears, Vim will offer several options. Press R to recover (Recover).
  2. Vim will load the contents from the swap file. Check that all changes are present.
  3. After recovery, immediately save the file with :wq (write and quit). This automatically deletes the swap file.
  4. If recovery fails (e.g., the swap file is corrupted), press D to delete the swap file and reopen the file (see Method 1).

Method 4: Change the Swap File Directory

To avoid conflicts with swap files in working directories, configure Vim to store all swap files in a separate folder.

  1. Create a directory for swap files if it doesn't exist:
    mkdir -p ~/.vim/swap
    
  2. Open or create the Vim configuration file ~/.vimrc:
    vim ~/.vimrc
    
  3. Add the line:
    set directory=~/.vim/swap//
    
    The double slash // at the end allows Vim to create subdirectories if needed and avoid name conflicts.
  4. Save and close ~/.vimrc. Now all new swap files will be created in ~/.vim/swap, not in the directory of the edited file.
  5. For existing files where a swap file already exists in the working directory, manually delete the old swap file (Method 1).

This method prevents E325 errors due to swap file accumulation in projects.

If you are sure you don't need recovery capability (e.g., when editing temporary configs), you can disable swap file creation.

  1. Open ~/.vimrc:
    vim ~/.vimrc
    
  2. Add the line:
    set noswapfile
    
  3. Save and close the file. On the next Vim launch, swap files will not be created.

⚠️ Warning: Disabling swap files removes your protection against crashes. All unsaved changes will be lost. Use only in specific cases.

Prevention

To minimize future E325 errors, follow these practices:

  • Terminate Vim sessions properly. Always use :wq (save and quit) or :qa (quit all windows) instead of force-closing the terminal.
  • Configure a separate directory for swap files (Method 4). This isolates swap files from working files and simplifies management.
  • Regularly clean up old swap files. Periodically check the ~/.vim/swap directory and delete files associated with completed sessions (e.g., by modification date).
  • Ensure write permissions. The user must have write permissions in the directory of the file being edited; otherwise, Vim cannot manage the swap file correctly.
  • Avoid simultaneous editing of the same file in multiple Vim instances unless necessary. If required, use file locking or a version control system (like Git).

F.A.Q.

What is a swap file in Vim and what is it for?
Why does Vim show the error 'Swap file already exists'?
How to safely delete a swap file if I am sure it is not needed?
Can I completely disable swap file creation in Vim?

Hints

Check for the presence of a swap file
Ensure there are no active sessions
Delete the swap file
Open the file again
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community