GPG with Vim solves this in seconds. It lets you encrypt and decrypt files on demand, right inside the editor. No extra steps. No unprotected temp files.
What is GPG Vim?
GPG (GNU Privacy Guard) is a tool for encryption and signing. Vim is a fast, scriptable text editor. Together, they give you a secure editing workflow. You can store sensitive configs, credentials, or notes as .gpg files, and Vim will decrypt them when you open, then re-encrypt when saving.
Installing the Integration
- Ensure
gpgis installed on your system. - Add the Vim plugin
vim-gnupg(available via GitHub or your plugin manager). - Reload Vim and verify with
:echo has("gnupg").
Workflow
- Create a file with
vim secret.txt.gpg. - Vim detects the
.gpgextension and calls GPG to decrypt. - Edit as normal.
- On save, the file is encrypted again using your key.
Security Advantages
- No plaintext stored on disk.
- Relies on GPG’s well-tested crypto.
- Eliminates the risk of manual encrypt/decrypt steps.
Common Commands
- Encrypt existing files:
gpg -c file.txt - View keys:
gpg --list-keys - Set key in Vim: add
let g:GPGDefaultRecipients = ['you@example.com']to.vimrc.
Tips for Stability
Use temporary files in RAM by setting :set directory=/dev/shm. Test integration in a sandbox with dummy keys before using production secrets. Keep GPG keys protected with strong passphrases and exclusive permissions.