Hi,
I found the following auto commands somewhere for using gnupg:
" 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 various options which write unencrypted data to disk
autocmd BufReadPre,FileReadPre *.gpg set noswapfile noundofile nobackup
" 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
This is very similar to the script at http://vim.wikia.com/wiki/Edit_gpg_encrypted_files
where, in the discussion, someone comments that they don't understand why '[,']!gpg
was used instead of %!gpg.
Can anyone explain this? '[,'] refers to the previously changed or yanked
text whereas % refers to the entire file (which is what is wanted).
Will '[,'] always refer to the entire file in the autocommands above?
If so, how so? Would it be better with % or identical?
I can see that it would refer to the entire file in the BufReadPost,FileReadPost
state because the entire file has just been read so the last "change" is the entire
file but what about the BufWritePre,FileWritePre state?
I should say that saving works even if I have changed or yanked part of the
file immediately before saving. I just don't know why it works.
cheers,
raf
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Monday, December 21, 2015
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment