# Vim and GPG


This info can also be found on the Internet, but I thought I compile it
here too.

# Problem
You want to save something (say passwords) in a file and protect the
file with a master password (say with your PGP/GPG key). This can be
cumbersome unless you have [vim](http://www.vim.org).

The following examples will handle `*.gpg` files differently, `vim` will
decrypt the file when opening it and encrypt the file when writing it.
Also the use of a swap file is disabled.

 vim config

The following config will make `vim` behave like described above manner:

    augroup gpg
    au!
    au BufReadPre,FileReadPre *.gpg set viminfo=
    au BufReadPre,FileReadPre *.gpg set noswapfile
    au BufReadPost *.gpg :%!gpg -q -d
    au BufReadPost *.gpg | redraw!
    au BufWritePre *.gpg :%!gpg --default-recipient-self -q -e -a
    au BufWritePost *.gpg u
    au VimLeave *.gpg :!clear
    augroup END

Just add it to your `~/.vimrc` and your are set. 

> I've found this config somewhere on the Internet (lost the reference),
> so it's not my idea.

