Open, Edit & Save Encrypted Files with Vim and GPG
If you’ve ever want to save sensitive text on your computer - encrypting it is the only way to ensure it is secure. Using vim and gpg we can open, edit, and save only the encrypted file and leave nothing in plain text on the hard drive.
Note: In order to run gpg on OS X, you’ll need to first install MacGPG2.
To Open an Encrypted File (from shell)
gpg -d myfile.mkdn.gpg | vim - -n -i "NONE" "+set filetype=markdown"
-dto decrypt|pipe stdout of gpg into vim-to accept stdin instead of file-nturns off swap file - important!-iturns off.viminfo- important!+set filetypeset the file type (for syntax highlighting, etc) since there is no file name for vim to detect
Bonus: Add a function (and easy alias) to your ~/.bash_profile file:
vimdecrypt() { gpg -d "$1" | vim - -n -i "NONE" "+set filetype=$2"; }
alias vd="vimdecrypt"
You can now simply type (2nd argument optional):
$ vd myfile.mkdn.gpg markdown
To Encrypt and Save a File (from vim)
:w !gpg -c -o myfile.mkdn.gpg
:wto write buffer!gpgescape to shell and run gpg, accepts vim buffer as stdin-cto set symetric encryption-oto set file name
Bonus: Add a command to your ~/.vimrc file:
command -nargs=1 WriteEncrypted w !gpg -c -o <q-args>
Now, from within vim you type
WriteEncrypted myfile.txt.gpg
-
bernardb reblogged this from jasonseney and added:
A really nice way to encrypt a simple text file on the fly.
-
v1j likes this
-
bitcoin likes this
-
bitcoinnews likes this
-
bjoernwibben likes this
-
chvnx likes this
-
iphoneyou likes this
-
hackedy likes this
-
invaderxir reblogged this from jasonseney and added:
awesooooooome
-
invaderxir likes this
-
jasonseney posted this