Vim

From WTFwiki
Revision as of 22:19, 15 September 2006 by Andrew (talk | contribs) (Editing encrypted files with vim moved to Vim: Do the intellectual shuffle!)
Jump to navigation Jump to search

Ever wanted to edit some files you've encrypted with mcrypt(1), but didn't want nasty unencrypted files lying around? With Vim and a little autocommands magic you can:

 " ###### LOADING ######
 autocmd BufReadPre,FileReadPre *.nc set bin "binary mode
 autocmd BufReadPre,FileReadPre *.nc set noshelltemp "force the use of pipes
 autocmd BufReadPre,FileReadPre *.nc set noswapfile "disable swapfiles
 "decrypt the file
 autocmd BufReadPost,FileReadPost *.nc '[,']!mcrypt -d
 autocmd BufReadPost,FileReadPost *.nc set nobin "turn off binary mode
 " ###### SAVING ######
 autocmd BufWritePre,FileWritePre *.nc set bin "binary mode
 "encrypt the data
 autocmd BufWritePre,FileWritePre *.nc '[,']!mcrypt
 "decrypt the buffer again
 autocmd BufWritePost,FileWritePost *.nc '[,']!mcrypt -d
 autocmd BufWritePost,FileWritePost *.nc set nobin "turn off binary
 "trigger a screen redraw cuz things are fucked up
 autocmd BufWritePost,FileWritePost *.nc normal ^L

NOTE: this may not be entirely secure, this is just something I pulled out of my ass while offline and browsing the vim documentation. It seems to work as desired, but you never know.

TODO: make the save part suck less (currently you need to type the passphrase *3* times, and vim gets all screwed up (hence the ctrl-l as the last step which forces a redraw). I'm not sure exactly how to do this though.

--Andrew 22:17, 15 September 2006 (EDT)