What is the SWP file format?
.swp is a Vim swap file - a temporary binary file that Vim creates automatically when you open a file for editing. Its purpose is crash recovery: if Vim exits unexpectedly due to a power loss, terminal close, or system crash, the swap file preserves unsaved changes that can be recovered on the next launch.
Vim creates the swap file in the same directory as the edited file, naming it with a leading dot and .swp suffix - for example, editing config.py produces .config.py.swp. On Unix-like systems the leading dot makes it hidden by default. If multiple Vim sessions edit the same file, subsequent swap files use .swo, .swn, and so on.
The swap file has a binary block-based structure. The first 4 KB block (block 0) contains a b0VIM magic header, the Vim version string, the original file path, hostname, username, and process ID. Subsequent blocks store the buffer contents organized as a B-tree of 1 KB pages. File contents are stored in plaintext - the swap file is not encrypted.
When Vim opens a file and detects an existing .swp, it prompts you to Recover (r) the unsaved changes or Delete (d) the stale file. A leftover .swp with no running Vim process is safe to delete; run vim -r filename to attempt recovery explicitly. Neovim uses the same swap format.
One security consideration: .swp files left in web server directories can expose unencrypted source code if the server is configured to serve hidden files.
Security & safety
RISK: MEDIUMThe .swp file itself is not malware, but it poses an information-disclosure risk: (1) Left in a web-accessible directory, it exposes the full plaintext of the file being edited plus server hostname and username - a classic recon finding in pentests. (2) Accidentally committed to git: 'git rm --cached .*.swp' and add '*.swp' to .gitignore. Add '*.swp' to your global .gitignore (~/.config/git/ignore) to prevent accidental commits.
Format details
in a nutshell- Windows Virtual Memory Swap File - Windows uses pagefile.sys/swapfile.sys, not .swp extension; confusion with OS swap is unfounded but common.
- Oracle Forms .swp - Older Oracle Forms versions used .swp for a different swap buffer; very rare.
Programs that open SWP files
Technical details
deep spec| File purpose | Crash-recovery buffer for active Vim editing sessions; automatically deleted on clean exit |
| Magic bytes | `62 30 56 49 4D 20` ("b0VIM ") at offset 0 |
| Block structure | Block 0: 4 KB header; subsequent blocks: 1 KB pages in a B-tree; total size grows with buffer contents |
| Header contents | Vim version string, original file path, hostname, username, and PID stored in block 0 |
| Content encoding | Plaintext (no encryption); original file content is directly readable from the swap file |
| Byte order | Platform-dependent (matches host Vim build; typically little-endian on x86 and ARM) |
| Naming convention | `.filename.swp` (leading dot + `.swp` suffix); hidden on Unix systems by default |
| Overflow naming | When multiple sessions edit the same file: `.swo`, `.swn`, `.swm`, … allocated alphabetically |
| Stale detection | Vim cross-checks PID and hostname in block 0 header; warns if the recorded process is no longer running |
| Recovery command | `vim -r filename` or press `r` at the recovery prompt when reopening the file in Vim |
| Neovim compatibility | Neovim reads and writes Vim-compatible swap files using the same `b0VIM` header format |
| Security note | Swap files in web-accessible directories expose source code as plaintext if the server serves dotfiles |
| Released | 1991 (Vim 1.0); vi swap concept from 1970s ex/vi |
| Latest version | Vim 9.1 (2024) swap format; compatible block-based format since Vim 6 |
| Specification | github.com |
SWP conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about SWP files.