From d7a43660b7d322fece0b27c0c56f4572962a0043 Mon Sep 17 00:00:00 2001 From: Craige McWhirter Date: Mon, 4 Apr 2016 14:04:59 +1000 Subject: [PATCH] Added support for editing GPG files --- .vimrc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.vimrc b/.vimrc index 816361b..2a8acd2 100644 --- a/.vimrc +++ b/.vimrc @@ -25,6 +25,32 @@ autocmd FileAppendPre * :call TrimWhiteSpace() autocmd FilterWritePre * :call TrimWhiteSpace() autocmd BufWritePre * :call TrimWhiteSpace() +" 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 + 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 + autocmd BufWritePre,FileWritePre *.gpg '[,']!gpg --default-key=04CE4B93 --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 + " Add files ending in md to the list of files recognised as markdown: autocmd BufNewFile,BufFilePre,BufRead *.md set filetype=markdown