diff options
author | Matthew Lemon <y@yulqen.org> | 2023-10-01 08:58:01 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2023-10-01 08:58:01 +0100 |
commit | 09fc9c22f1b16ded2b6f6414d1cc83bf2dd44218 (patch) | |
tree | 671ae641d71028e5877c76702fcc43047ab22596 /vim/vimrc | |
parent | 7cf448dd6e49cdf2f4d71fce2992dbfb574e743e (diff) |
Allow vim to open, read and write GPG-encrypted files
Diffstat (limited to 'vim/vimrc')
-rw-r--r-- | vim/vimrc | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -314,3 +314,34 @@ let g:gruvbox_invert_signs = 0 " colorscheme ayu colorscheme sitruuna " }}} +" GPG files {{{ +" from https://vim.fandom.com/wiki/Edit_gpg_encrypted_files +" Don't save backups of *.gpg files +set backupskip+=*.gpg +" To avoid that parts of the file is saved to .viminfo when yanking or +" deleting, empty the 'viminfo' option. +set viminfo= + +augroup encrypted + au! + " Disable swap files, and set binary file format before reading the file + autocmd BufReadPre,FileReadPre *.gpg + \ setlocal noswapfile bin + " Decrypt the contents after reading the file, reset binary file format + " and run any BufReadPost autocmds matching the file name without the .gpg + " extension + autocmd BufReadPost,FileReadPost *.gpg + \ execute "'[,']!gpg --decrypt --default-recipient-self" | + \ setlocal nobin | + \ execute "doautocmd BufReadPost " . expand("%:r") + " Set binary file format and encrypt the contents before writing the file + autocmd BufWritePre,FileWritePre *.gpg + \ setlocal bin | + \ '[,']!gpg --encrypt --default-recipient-self + " After writing the file, do an :undo to revert the encryption in the + " buffer, and reset binary file format + autocmd BufWritePost,FileWritePost *.gpg + \ silent u | + \ setlocal nobin +augroup END +" }}} |