On Monday, October 1, 2012 11:52:26 AM UTC-5, Art Scheel wrote:
> vim can read stdin with 'vim -' but there's currently no way to submit all edited changes to stdout (so far as I can find.) There are plenty of scripts and plugins that allow this kind of functionality, but they all require a file to be written to disk (even if it's a RAMDISK).
> Would it be worth pursuing a patch that would allow a saved file (:wq) to send the newly edited text to 'stdout'?
> My particular end goal is to handle the editing of encrypted text files, hence the necessity for the inbound and outbound files to never be written to disk except for the encrypted versions of this file.
I don't think you need a patch for this.
First, Vim allows you to use the :w command to invoke any shell command with stdin taken from the current Vim buffer. So, :%w !encrypt would pass all text in the current buffer to the "encrypt" program on stdin.
Second, Vim allows you to define a BufWriteCmd autocmd, which specifies what Vim should actually do to write a file. So you could use the above method inside an autocmd to make it transparent, if desired.
Finally, Vim has strong "Blowfish" encryption built in. If you want a specific encryption scheme which you already use, this doesn't matter, but if you're only interested in general in being able to use Vim to edit encrypted files, this may be a better solution.
Do these methods meet your needs?
Be aware that Vim's swapfile, viminfo file, backup file, and possibly undo file may all contain unencrypted text. Make sure to turn these off for your encrypted edit. When using Vim's built-in encryption, the swap file and undo file are encrypted with the file so those two can still be used.
:help encryption says that filtering with :!cmd or :w !cmd do not encrypt the text which "may reveal it to others". I'm not sure under what circumstances this can happen.