Found a Swap File by the Name: Fix Vim .swp Warnings (E325)

Deepak Prasad
Tested on RHEL 10.2 (Coughlan) — vm1.lab.example
Package vim-enhanced 9.1 (Vim 9.1)
Applies to RHEL, Rocky Linux, AlmaLinux, Fedora, Ubuntu, Debian, and other Linux systems with Vim or Vi
Privilege Normal user (Vim writes swap files where permitted — usually alongside the edited file, or another directory from the directory option)
Scope Vim .swp / .swo editor recovery files and the E325 “Found a swap file by the name” prompt — not Linux swap space (mkswap, swapon, /etc/fstab). Does not cover Vim split windows or relative line numbers.
Related guides Show hidden files in Linux
ps command
Vim split windows
Vim relative line numbers
Delete files from the shell

Opening a file in Vim and seeing Found a swap file by the name usually means a .swp file already exists for that document — typically alongside the file, though Vim can place swap files elsewhere. That name sounds like memory paging, but it is not the swap space you configure with mkswap and swapon.

Vim writes .swp files to recover unsaved edits after a crash or network drop. The fix depends on what the prompt tells you: another editor still running, or a leftover file from a dead session.


Not Linux swap memory

Linux swap is disk or partition space the kernel uses when RAM is full. Vim .swp files are per-file editor backups (often hidden because the name starts with .). Vim normally stores them alongside the file you edit, but it can use another directory according to the directory option or when the original directory is not writable.

Confirm what the kernel is using for paging:

bash
swapon --show

Sample output on the lab host:

output
NAME      TYPE      SIZE USED PRIO
/dev/dm-1 partition   3G 268K   -2

That list shows a block swap device — not /tmp/.file.swp. If your search was about adding system swap, you need mkswap and swapon, not this guide.


What Vim .swp files do

When you open file with Vim, it normally creates a swap file such as .file.swp alongside the edited file unless swap is disabled. Vim can place swap files in another directory when the directory option says so or when the file’s directory is not writable. Vim updates the swap file while you edit so it can restore work if the session dies.

Typical behavior:

  • One primary swap file per edited file; if .swp already exists, Vim may use .swo, .swn, and so on
  • Vim removes the swap file on a normal exit when the buffer is written or discarded cleanly
  • A crash, kill -9, or lost SSH session can leave the .swp file behind

See the current swap path inside Vim with :swapname (or :sw). For full detail, run :help swap-file in Vim.


Read the E325 prompt before you act

When a swap file already exists, Vim stops with E325: ATTENTION and a block like this:

text
E325: ATTENTION
Found a swap file by the name "/tmp/vim-swap-lab/.file.swp"
          owned by: root   dated: Fri Aug 21 18:38:15 2026
         file name: /tmp/vim-swap-lab/file
          modified: YES
         user name: root   host name: vm1.lab.example
        process ID: 425015 (still running)
While opening file "/tmp/vim-swap-lab/file"
             dated: Fri Aug 21 18:38:10 2026

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /tmp/vim-swap-lab/file"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/tmp/vim-swap-lab/.file.swp"
    to avoid this message.

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

Read process ID and (still running) first. That line decides whether you recover, quit, or delete.

Prompt signal Likely cause Safer action
process ID: … (still running) Another Vim still has the file open Quit or Abort; do not delete .swp
No “still running”; old date; you crashed Stale swap from a dead session Recover, write to a temporary filename, compare, then remove that .swp
You already recovered and saved Leftover swap file Delete the verified stale .swp after confirming content

Another Vim still editing the file

If the prompt lists a live process ID, confirm it before you choose Edit anyway:

bash
ps -p 425015 -o pid,cmd

Sample output while the first session is open:

output
PID CMD
 425015 vim -es /tmp/vim-swap-lab/file

A matching vim line means the swap file is in use. Press Q (Quit) or A (Abort) and edit from the existing session, or close that session first.

While Vim holds the file, the swap file path shown in the E325 message should exist (here, alongside the edited file):

bash
ls -la /tmp/vim-swap-lab/.file.swp

Sample output:

output
-rw-r--r--. 1 root root 4096 Aug 21 18:38 /tmp/vim-swap-lab/.file.swp

Choosing Edit anyway creates a second swap file (for example .file.swo) and two buffers can diverge. Prefer Open Read-Only if you only need to view the file.


Recover after a crashed Vim session

When the process is gone but .swp remains, recover before you delete anything.

At the E325 menu, press R (Recover). Vim loads swap contents into the buffer. Inspect the text, then write it to a temporary filename before you touch the original:

text
:write /tmp/vim-swap-lab/file.recovered

Compare file.recovered with the original on disk. Replace the original only when you are satisfied — recovery can occasionally be incomplete or corrupt. When the recovered content is correct, copy or save it over the original file.

From the shell you can also start with:

bash
vim -r /tmp/vim-swap-lab/file

Vim lists swap files it finds for that path. Follow the on-screen recovery prompt, write to a temporary recovered filename, compare with the original, then remove the stale swap file so the warning does not return.


Delete a stale .swp file

Delete the swap file only when:

  • No Vim process is editing that file (ps shows no owner, or the PID is gone)
  • You recovered and saved (or copied) the content you need, or you accept losing whatever was only in the swap buffer

If .swo, .swn, or other swap variants exist, inspect each path and confirm the corresponding Vim process is gone and its recovery data is no longer needed before deleting it. Do not bulk-remove numbered swap files just because more than one name appears.

Once one stale swap file is verified, remove only that file:

bash
rm -f /tmp/vim-swap-lab/.file.swp

Reopen the file with Vim — the E325 message should not appear for that swap path.


Disable swap files for one session

vim -n turns off swap files for that invocation:

bash
vim -n /tmp/vim-swap-lab/file

In another terminal, confirm no swap file appeared:

bash
ls /tmp/vim-swap-lab/.file.swp 2>&1

Sample output:

output
ls: cannot access '/tmp/vim-swap-lab/.file.swp': No such file or directory

Without a swap file, a crash or disconnect loses unsaved edits that Vim would otherwise recover. Use -n only when you accept that trade-off.


Troubleshooting

Symptom Likely cause Fix
E325 every time you open the file Stale .swp after crash or incomplete recovery R or vim -r; write file.recovered; compare; rm the verified stale .swp
process ID … (still running) Second terminal or SSH session still in Vim ps -p PID; quit the other session; do not delete .swp yet
.file.swp and .file.swo both present Opened with Edit anyway while swap existed Pick one session to keep; merge manually; delete each stale swap only after its process is gone and data is not needed
Recovery shows empty or wrong text Swap truncated or disk file already saved over Restore from backup; treat swap as best-effort
Confused with RAM swap Name collision only Use swapon --show for kernel swap; .swp is Vim-only

References


Summary

Found a swap file by the name is Vim’s E325 warning about an editor .swp file, not Linux swap memory. Check swapon --show if you meant paging space; otherwise read the prompt.

If process ID (still running) appears, another Vim owns the file — quit and avoid deleting the swap file. If the editor crashed, press R or use vim -r, write the buffer to a temporary recovered filename, compare it with the original, and replace the original only when you are satisfied. Then delete the verified stale .swp so the message stops.

Do not rm a swap file blindly: you may discard recoverable work. After a clean exit, Vim normally removes its swap file itself; leftovers mean an abnormal exit or a second edit session worth resolving first.


Frequently Asked Questions

1. Is a Vim .swp file the same as Linux swap memory?

No. A .swp file is Vim editor recovery data for one text file. Linux swap space comes from a swap partition or swap file prepared with mkswap and enabled with swapon, which shows up in swapon --show — not as a hidden .filename.swp next to your document.

2. Is it safe to delete a .swp file?

Only when no Vim session is editing that file and you do not need recovery. If the prompt shows process ID still running, another editor owns the file — quit and do not delete the swap file. After a crash, recover first or confirm you do not need the buffer, then rm the stale .swp file.

3. What should I press when Vim shows Open Read-Only, Edit anyway, Recover, Quit, Abort?

Choose Quit or Abort when another live Vim process is editing the file. Choose Recover when the swap is from your crashed session and you want unsaved changes back. Edit anyway creates a second swap file and risks two conflicting versions.

4. How do I recover after a Vim crash?

Open the file again and press R for Recover at the E325 prompt, or run vim -r /path/to/file from the shell. After recovery, inspect the buffer and write it to a temporary filename such as file.recovered before comparing with the original. Replace the original only when satisfied, then delete the stale .swp file.

5. How do I stop Vim from creating .swp files?

Start Vim with -n to disable swap files for that session. That removes crash recovery for unsaved work, so it is rarely a good default for important edits.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware.

  • Debian
  • Ubuntu
  • Linux
  • Red Hat Enterprise Linux
  • Shell Script
  • System Administration