Setting up autmatic encrypt and decrypt in vim.

Sebastian Wiesinger sebastian@karotte.org
Mon May 27 11:31:01 2002


--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* Dani Gleser <gleser@cips.nokia.com> [2002-05-24 13:04]:
> Please CC me on this.
>=20
> Is there a way to setup vim, (i.e. with a .vimrc file) to atomaticaly=20
> run gpg when opeing and saveing an encrypted file.  If so do you have a=
=20
> sample config?

This works for me:

#v+
if has("autocmd")

" Support editing of gpg-encrypted files
augroup gnupg
  " Remove all gnupg autocommands
  au!

  " Enable editing of gpg-encrypted files
  "	  read:	set binary mode before reading the file
  "		decrypt text in buffer after reading
  "	 write:	encrypt file after writing
  "	append:	decrypt file, append, encrypt file

  autocmd BufReadPre,FileReadPre	*.gpg set bin
  autocmd BufReadPre,FileReadPre	*.gpg let ch_save =3D &ch|set ch=3D2
  autocmd BufReadPost,FileReadPost	*.gpg '[,']!gpg -d 2>/dev/null
  autocmd BufReadPost,FileReadPost	*.gpg set nobin
  autocmd BufReadPost,FileReadPost	*.gpg let &ch =3D ch_save|unlet ch_save
  autocmd BufReadPost,FileReadPost	*.gpg execute ":doautocmd BufReadPost " =
. expand("%:r")

  autocmd BufWritePost,FileWritePost	*.gpg !mv <afile> <afile>:r
  autocmd BufWritePost,FileWritePost	*.gpg !gpg --default-recipient-self -e=
 <afile>:r
  autocmd BufWritePost,FileWritePost	*.gpg !rm <afile>:r

  autocmd FileAppendPre			*.gpg !gpg -d 2>/dev/null <afile>
  autocmd FileAppendPre			*.gpg !mv <afile>:r <afile>
  autocmd FileAppendPost		*.gpg !mv <afile> <afile>:r
  autocmd FileAppendPost		*.gpg !gpg --default-recipient-self -e <afile>:r
  autocmd FileAppendPost		*.gpg !rm <afile>:r

  " Same as above, but for ASCII-armored files
  autocmd BufRead			*.asc GiFULLDATE<CR><ESC>
  autocmd BufReadPre,FileReadPre	*.asc set bin
  autocmd BufReadPre,FileReadPre	*.asc let ch_save =3D &ch|set ch=3D2
  autocmd BufReadPost,FileReadPost	*.asc '[,']!gpg -d 2>/dev/null
  autocmd BufReadPost,FileReadPost	*.asc set nobin
  autocmd BufReadPost,FileReadPost	*.asc let &ch =3D ch_save|unlet ch_save
  autocmd BufReadPost,FileReadPost	*.asc execute ":doautocmd BufReadPost " =
. expand("%:r")

  autocmd BufWritePost,FileWritePost	*.asc !mv <afile> <afile>:r
  autocmd BufWritePost,FileWritePost	*.asc !gpg --default-recipient-self -a=
 -e <afile>:r
  autocmd BufWritePost,FileWritePost	*.asc !rm <afile>:r

  autocmd FileAppendPre			*.asc !gpg -d 2>/dev/null <afile>
  autocmd FileAppendPre			*.asc !mv <afile>:r <afile>
  autocmd FileAppendPost		*.asc !mv <afile> <afile>:r
  autocmd FileAppendPost		*.asc !gpg --default-recipient-self -a -e <afile>=
:r
  autocmd FileAppendPost		*.asc !rm <afile>:r
augroup END

endif
#v-

Sebastian
--=20
Sebastian Wiesinger <sebastian@karotte.org>
GPG Key-ID: 0x76B79F20
Gegen Zensur: http://odem.org/informationsfreiheit/
A bash poem: time for echo in canyon; do echo $echo $echo; done

--yrj/dFKFPuw6o+aM
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE87iKrG2A09Ha3nyARAsI3AJkBO9vSZ4buiBSzWm+ByXlhIh23yACfcsuk
fQrM/St3OgsvVGar0ezrhJU=
=vmDm
-----END PGP SIGNATURE-----

--yrj/dFKFPuw6o+aM--