Stupid Linux Tricks: gpg plugin for vim

Posted by Timothy O'Connell in General on October 17, 2008

If you're like me, your favorite passtimes include cracking condescending jokes about how the mouse is just another passing fad, startling your coworkers by laughing out loud at anti-emacs rants on bash.org and encrypting every plaintext file in your home directory within an inch of its life.

If, however, you're like me in the above respects and you don't yet know about the gpg plugin for vim, then the quality of your life is currently being severely diminished.

But we can fix that.

Assuming you're running Debian (or some variation thereof) and you've already got vim installed and your keypair properly set up in your ~/.gnupg directory, here's the how-to on getting the plugin to work for your user:

# apt-get install vim-scripts
$ mkdir ~/.vim/plugin
$ ln -s /usr/share/vim-scripts/plugin/gnupg.vim ~/.vim/plugin/gnupg.vim

And that's it: three commands and you're in business.

(It is worth mentioning at this point that there is a whole slew of awesome vim plugins in the "vim-scripts" package. Enabling them is as easy as creating a symlink to them in the above manner.)

Once you've got your gpg plugin set up, creating encrypted files is as easy as:

$ vi newFile.gpg

A buffer opens up, you enter recipients' key numbers or aliases (i.e. 759991EC or toconnell will get the job done), quit the buffer and edit the file as usual. You'll obviously want to remember to at least enter your own ID in the buffer so that you can decrypt the file in the future.

Editing files is just as simple: the next time you attempt to open your file, you'll be prompted by vim for your private key password and, upon entering it, your file will be decrypted and you'll be able to make changes and save it.

Finally, depending on whether or not the recipients you've specified in the buffer are "trusted", you may be manually prompted to sign the document with their public keys when you save it. Other than that, you're pretty much golden: with the exception of the password prompt you'll get when you try to open the file, you've eliminated most of the hassle that goes into decrypting, editing and encrypting shared files on the command line.

Substantial labor and time savings = demonstrably improved quality of life.

1 Comment

Leave a comment

WP_Big_City