-
Notifications
You must be signed in to change notification settings - Fork 0
/
cryptrc.vim
61 lines (53 loc) · 1.39 KB
/
cryptrc.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"
" cvimrc
" gpg-based, safe encrypted edits with vim (uses aes256+pass)
"
" usage:
" vim -S thisfile encrypted_file
"
" desc:
" puts vim in a special mode for editing encrypted data
" files with the support of an external encryption filter,
" trying to make sure no data ever hits the disk in its
" unencrypted state, including temporary files created by
" vim to pass data to an external program
"
" todo:
" we may need to use autocommands to make sure these are set
" for all buffers we enter; however, our usual pattern is to
" just cvim one file
"
" scott@smemsh.net
" https://github.com/smemsh/.vim/
" https://spdx.org/licenses/GPL-2.0
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" global
"
set secure
set nobackup
set nowritebackup
set noshelltemp
set viminfo=
set history=0
" local
"
set noswapfile
set noundofile
"""
function! BackupBeforeEncrypt()
let l:origpath = expand('%:p')
let l:nowdate = system('date +%Y%m%d%H%M%S')
let l:bakpath = l:origpath . '.' . l:nowdate
call system("cp -ia " . l:origpath . " " . l:bakpath)
endfunction
function! Encrypt()
call BackupBeforeEncrypt()
%!gpg -q --cipher-algo aes256 --symmetric --armor 2>/dev/null
endfunction
function! Unencrypt()
%!gpg -q --cipher-algo aes256 --decrypt --armor 2>/dev/null
endfunction
"""
nmap <silent> ZX :call Encrypt()<return>
nmap <silent> Zx :call Unencrypt()<return>