Daily Quick Tip : Vim Encryption

Have a sensitive file that you want to encrypt, but you don’t need to encrypt the whole drive? Maybe a password file because you’re too lazy or morally opposed to putting passwords under someone else’s supervision? Are you a Vim user?

(if you’re not a Vim user — sayonara)

You’re still here? Great. Reach for Vim Encryption.

First, you need to be running Vim 7.4.399 or later. (Earlier versions supported encryption, but didn’t do a very good job it. See this article.)

Next, add this to your .vimrc. It will set the encryption method to the much improved Blowfish2 method.

:set cryptmethod=blowfish2

Now, in Vim type “:X”. You’ll be asked for an encryption key (twice).

Et voilá. Now every time you edit that file in Vim you’ll first be asked for an encryption key to decrypt the file. If you don’t give it the right key, the Vim buffer will open, but all you’ll see is a “bunch o’ junk”.

You’ll probably also want to consider these .vimrc updates so that you don’t leak information to your temporary Vim files:

set noswapfile
set nobackup
set nowritebackup
set viminfo=