| 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:
swapon --showSample output on the lab host:
NAME TYPE SIZE USED PRIO
/dev/dm-1 partition 3G 268K -2That 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
.swpalready 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.swpfile 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:
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:
ps -p 425015 -o pid,cmdSample output while the first session is open:
PID CMD
425015 vim -es /tmp/vim-swap-lab/fileA 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):
ls -la /tmp/vim-swap-lab/.file.swpSample output:
-rw-r--r--. 1 root root 4096 Aug 21 18:38 /tmp/vim-swap-lab/.file.swpChoosing 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:
:write /tmp/vim-swap-lab/file.recoveredCompare 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:
vim -r /tmp/vim-swap-lab/fileVim 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 (
psshows 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:
rm -f /tmp/vim-swap-lab/.file.swpReopen 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:
vim -n /tmp/vim-swap-lab/fileIn another terminal, confirm no swap file appeared:
ls /tmp/vim-swap-lab/.file.swp 2>&1Sample output:
ls: cannot access '/tmp/vim-swap-lab/.file.swp': No such file or directoryWithout 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
- Vim recovery (
:help recovery) —:recover,vim -r, and E325 behavior - Vim crash recovery (User manual §11) — write recovered content under another filename before overwriting the original
- swapon(8) — Linux kernel swap (unrelated to Vim
.swp)
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.

