![]() " Undo the encryption so we are back in the normal text, directlyĪutocmd BufWritePost,FileWritePost *.asc uĪutocmd BufReadPre,FileReadPre *.gpg set viminfo=Īutocmd BufReadPre,FileReadPre *.gpg set noswapfileĪutocmd BufReadPre,FileReadPre *.gpg set binĪutocmd BufReadPre,FileReadPre *.gpg let ch_save = &ch|set ch=2Īutocmd BufReadPost,FileReadPost *.gpg '!sh -c "gpg -decrypt 2> /dev/null"Īutocmd BufReadPost,FileReadPost *.gpg set nobinĪutocmd BufReadPost,FileReadPost *.gpg let &ch = ch_save|unlet ch_saveĪutocmd BufReadPost,FileReadPost *.gpg execute ":doautocmd BufReadPost ". " Convert all text to encrypted text before writingĪutocmd BufWritePre,FileWritePre *.asc '!sh -c "gpg -default-recipient-self -ae 2>/dev/null" " Switch to binary mode to read the encrypted fileĪutocmd BufReadPre,FileReadPre *.asc set binĪutocmd BufReadPre,FileReadPre *.asc let ch_save = &ch|set ch=2Īutocmd BufReadPost,FileReadPost *.asc '!sh -c "gpg -decrypt 2> /dev/null"Īutocmd BufReadPost,FileReadPost *.asc set nobinĪutocmd BufReadPost,FileReadPost *.asc let &ch = ch_save|unlet ch_saveĪutocmd BufReadPost,FileReadPost *.asc execute ":doautocmd BufReadPost ". " We don't want a swap file, as it writes unencrypted data to diskĪutocmd BufReadPre,FileReadPre *.asc set noswapfile " First make sure nothing is written to ~/.viminfo while editingĪutocmd BufReadPre,FileReadPre *.asc set viminfo= " (asc support and sh -c"." added by Osamu Aoki) " Placed Public Domain by Wouter Hanegraaff " Transparent editing of gpg encrypted files. Set runtimepath+=/usr/share/vim/vimfiles/after,~/.vim/after Set runtimepath+=/usr/share/vim/addons,/usr/share/vim/vim61 Set runtimepath=~/.vim,/etc/vim,/usr/share/vim/vimfiles ![]() (~/.vimrc of my machine) which uses Wooter's code.Ī bit more consideration to back up files etc. Here is a bit more complicated script for this GPG integration. By adding '2> /dev/null' to the 'au BufReadPost *.asc :%!gpg -q -d' line, those error messages won't show up. So no viminfo will be read/written and no swap file plaintext copy will be made.Ī small addition - If you type your password wrong, you'll get the "incorrect password" message in the buffer. If gpg fails, your encrypted file is gone. When I do a :w the cursor position is reset to the beginning of the buffer. I wrote the vimcrypt functionality in vim5.7 when I was in India, it's not strong, but keeps the grandmons and admin at bay. Specify -n option, so that Vim doesn't use swap file and save the plain text to disk. One should be aware of leaving pieces of the plaintext inside registers in. ![]() This isn't perfect - in particular, you occasionally have to tell Vim to redraw with ctrl-L to get rid of gnupg crud - but it works pretty well for me. To edit, just Vim it again and you'll be prompted for your passphrase. When you save and quit, gnupg may prompt for gnupg ids to encrypt for (if you don't have default-recipient-self set). Now Vim a new file, the name of which ends with. ![]() You might also want to add these options to your ~/.gnupg/options file to decrease the messages that gnupg outputs:ĭefault-recipient-self #to always encrypt for yourself. Then put this into your vimrc (don't duplicate the 'if has("autocmd")' part if it is already there): The method below lets Vim take care of some of the dirty work.įirst, be sure you have gnupg setup to the point where you can ascii-armor encrypt a file using your own public key, and decrypt it again. It can be somewhat laborious to edit a file which you have encrypted: first you have to decrypt to plaintext, then use Vim and save then encrypt again. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |