sponsor Vim development Vim logo Vim Book Ad

gnupg : Plugin for transparent editing of gpg encrypted files.

 script karma  Rating 1446/550, Downloaded by 19223  Comments, bugs, improvements  Vim wiki

created by
Markus Braun
 
script type
utility
 
description
Due to the lack of time I'm not able to continue the development of this script.
James McCoy took over development. New versions can be found at vimscript #3645.

This script implements transparent editing of gpg encrypted files. The filename must have a ".gpg", ".pgp" or ".asc" suffix. When opening such a file the content is decrypted, when opening a new file the script will ask for the recipients of the encrypted file. The file content will be encrypted to all recipients before it is written. The script turns off viminfo and swapfile to increase security.

Commands:

  :GPGEditRecipients
    Opens a scratch buffer to change the list of recipients. Recipients that
    are unknown (not in your public key) are highlighted and have
    a prepended "!". Closing the buffer makes the changes permanent.

  :GPGViewRecipients
    Prints the list of recipients.

  :GPGEditOptions
    Opens a scratch buffer to change the options for encryption (symmetric,
    asymmetric, signing). Closing the buffer makes the changes permanent.
    WARNING: There is no check of the entered options, so you need to know
    what you are doing.

  :GPGViewOptions
    Prints the list of options.

Variables:

  g:GPGExecutable
    If set used as gpg executable, otherwise the system chooses what is run
    when "gpg" is called. Defaults to "gpg".

  g:GPGUseAgent
    If set to 0 a possible available gpg-agent won't be used. Defaults to 1.

  g:GPGPreferSymmetric
    If set to 1 symmetric encryption is preferred for new files. Defaults to 0.

  g:GPGPreferArmor
    If set to 1 armored data is preferred for new files. Defaults to 0.

  g:GPGPreferSign
    If set to 1 signed data is preferred for new files. Defaults to 0.

  g:GPGDefaultRecipients
    If set, these recipients are used as defaults when no other recipient is
    defined. This variable is a Vim list. Default is unset.

Known Issues:

  In some cases gvim can't decryt files

  This is caused by the fact that a running gvim has no TTY and thus gpg is
  not able to ask for the passphrase by itself. This is a problem for Windows
  and Linux versions of gvim and could not be solved unless a "terminal
  emulation" is implemented for gvim. To circumvent this you have to use any
  combination of gpg-agent and a graphical pinentry program:

    - gpg-agent only:
        you need to provide the passphrase for the needed key to gpg-agent
        in a terminal before you open files with gvim which require this key.

    - pinentry only:
        you will get a popup window every time you open a file that needs to
        be decrypted.

    - gpgagent and pinentry:
        you will get a popup window the first time you open a file that
        needs to be decrypted.
 
install details
Copy the gnupg.vim file to the $HOME/.vim/plugin directory. Refer to ':help add-plugin', ':help add-global-plugin' and ':help runtimepath' for more details about Vim plugins.

From "man 1 gpg-agent":
...
You should always add the following lines to your .bashrc or whatever initialization file is used for all shell invocations:

     GPG_TTY=`tty`
     export GPG_TTY

It is important that this environment variable always reflects the output of the tty command. For W32 systems this option is not required.
...

Most distributions provide software to ease handling of gpg and gpg-agent. Examples are keychain or seahorse.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
gnupg.vim 3026 2010-01-27 7.0 Markus Braun - fix a bug by using a sh compatible setting for 'shellredir' on unix systems. when 'shell' was set to csh or tcsh by the user and the system has /bin/sh linked to dash the plugin didn't work.
gnupg.vim 2782 2009-06-15 7.0 Markus Braun - show more information (key id and creation time) of keys in GPGEditRecipients, GPGViewRecipients and during selecting in case of a ambiguous key.
gnupg.vim 2773 2009-05-27 7.0 Markus Braun - fix a bug in detecting windows platforms
- added g:GPGPreferSign to sign encrypted files by default (thanks to Tim Swast).
gnupg.vim 2276 2008-08-18 7.0 Markus Braun - added support for default recipients via the variable g:GPGDefaultRecipients.
- fixed an wrong error message with symmetric encryption and set recipients (thanks to Sebastian Luettich).
- create a empty new buffer on leaving vim to wipe out sensitive data on console.
- make sure senisitive data is never written unencrypted to disk.
gnupg.vim 2249 2008-07-31 7.0 Markus Braun - rewritten lots of code to use lists feature of vim 7 instead of my own implementation
- added a n option to change the name and location of GPG executable
- try to get GPG_TTY dynamically.
gnupg.vim 1933 2008-01-23 6.0 Markus Braun - changed parsin to work with gpg2 correctly
- save/restore view of saved window
- fix a bug when encoding and fileencoding is different
- restructured autocommand triggers
- added a debug command and debug messages
gnupg.vim 1605 2007-04-05 6.0 Markus Braun - new plugin options to set preferences for symmetric/asymmetric and armor/binary files
- fix for use with gvim. !! plugin works only in gvim if gpg-agent is available !!
gnupg.vim 1472 2006-12-15 6.0 Markus Braun - support for symmetric encrypted files.
- detection of various encryption options.
- possibility to change gpg options using new commands GPGEditOptions and GPGViewOptions commands.
- support editing files with '.gpg', '.pgp' and '.asc' suffixes (tanks to Richard Bronosky).
- detection of unencrypted files.
- support for windows systems (thanks to Erik Remmelzwaal).
gnupg.vim 1.27 2003-06-24 6.0 Markus Braun updated documentation, that gnupg.vim only works for public/private-key encrypted files.
gnupg.vim 1.26 2003-05-30 6.0 Markus Braun Initial upload
ip used for rating: 142.132.191.50

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github