From 7710bf2da6b7dcb40a173c474e8412c827f6bbfc Mon Sep 17 00:00:00 2001 From: Adam Lamers Date: Mon, 21 Nov 2016 17:22:09 -0600 Subject: [PATCH] Add transparent gpg editing to vimrc --- vimrc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/vimrc b/vimrc index 002a34f..6494bb5 100644 --- a/vimrc +++ b/vimrc @@ -128,3 +128,32 @@ inoremap k ((pumvisible())?("\"):("k")) inoremap :compl-filename +" Transparent editing of gpg encrypted files. +" By Wouter Hanegraaff +augroup encrypted + au! + + " First make sure nothing is written to ~/.viminfo while editing + " an encrypted file. + autocmd BufReadPre,FileReadPre *.gpg set viminfo= + " We don't want a swap file, as it writes unencrypted data to disk + autocmd BufReadPre,FileReadPre *.gpg set noswapfile + + " Switch to binary mode to read the encrypted file + autocmd BufReadPre,FileReadPre *.gpg set bin + autocmd BufReadPre,FileReadPre *.gpg let ch_save = &ch|set ch=2 + " (If you use tcsh, you may need to alter this line.) + autocmd BufReadPost,FileReadPost *.gpg '[,']!gpg --decrypt 2> /dev/null + + " Switch to normal mode for editing + autocmd BufReadPost,FileReadPost *.gpg set nobin + autocmd BufReadPost,FileReadPost *.gpg let &ch = ch_save|unlet ch_save + autocmd BufReadPost,FileReadPost *.gpg execute ":doautocmd BufReadPost " . expand("%:r") + + " Convert all text to encrypted text before writing + " (If you use tcsh, you may need to alter this line.) + autocmd BufWritePre,FileWritePre *.gpg '[,']!gpg --default-recipient-self -ae 2>/dev/null + " Undo the encryption so we are back in the normal text, directly + " after the file has been written. + autocmd BufWritePost,FileWritePost *.gpg u +augroup END