Encrypted files with vim
May 22, 2014
Remember the old adage that tools like emacs and vi expand until they can read email? It turns out they do encryption really well.
Creating an Encrypted File
In vim, if you create a file with the -x option:
$ vim -x test.txt
You'll be prompted for a passphrase. Enter it twice, and vim then lets you edit the file as normal. When you save, it'll be saved encrypted.
You don't need to subsequently edit the file with the -x
switch, just open it with vim
, and it'll prompt for the passphrase before showing the contents.
$ vim test.txt
Simple, and an excellent user experience.
Encrypting an existing file
Open the file as normal, then issue the following command to change to blowfish
(strong!) encryption:
:setlocal cm=blowfish
Then use the :X
command. This will prompt for a passphrase twice. If you then write the file it will be written encrypted.
References
http://www.techrepublic.com/blog/it-security/vim-offers-strong-file-encryption-with-blowfish/#. http://vim.wikia.com/wiki/Encryption