Skip to content

Configuration scripts for enable secure encryption in VIM editor

License

Notifications You must be signed in to change notification settings

tomasperezv/vimcrypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

vimcrypt

Configuration scripts for enable secure encryption in VIM editor

Native encryption methods

Vim editor has 3 native modes of encryption

  • pkzip based (deprecated)
  • blowfish based (vim > 7.3)
  • blowfish2 (vim > 7.4.399)

It's recommended to use blowfish2 since the 2 first options have well known vulnerabilities[1].

In order to enable blowfish2, you must set the cryptmethod variable (cm)

set cm=blowfish2

Additional configuration

We also need to take into consideration other vim settings in order to avoid leaving traces of the encrypted files content, specially the swap and backup files.

set noswapfile
set nobackup
set nowritebackup
set viminfo=

GPG support

In addition to the native cryptmethod, vim can be easily integrated with external encryption engines, the most remarkable being GPG. This is more recommended due to obvious reasons.

The following script[2] by Wouter Hanegraaff provides transparent editing of GPG encrypted files.

  1. Avoid writing to ~/.viminfo while editing
  autocmd BufReadPre,FileReadPre *.gpg set viminfo=
  autocmd BufReadPre,FileReadPre *.gpg set noswapfile noundofile nobackup
  1. FileReadPre: switch to binary mode when reading
  " Switch to binary mode to read the encrypted file
  autocmd BufReadPre,FileReadPre *.gpg set bin
  autocmd BufReadPre,FileReadPre *.gpg let ch_save = &ch|set ch=2
  1. FileReadPost: switch to normal mode for editing
  autocmd BufReadPost,FileReadPost *.gpg '[,']!gpg --decrypt --no-use-agent 2> /dev/null
  autocmd BufReadPost,FileReadPost *.gpg set nobin
  autocmd BufReadPost,FileReadPost *.gpg let &ch = ch_save|unlet ch_save
  autocmd BufReadPost,FileReadPost *.gpg execute ":doautocmd BufReadPost " . expand("%:r")
  1. FileWritePre: encrypt text before writing
  autocmd BufWritePre,FileWritePre *.gpg '[,']!gpg --armor --symmetric --no-use-agent --yes --cipher-algo AES256 2>/dev/null
  autocmd BufWritePost,FileWritePost *.gpg u

Demo of Symmetric encryption with GPG + Vim

terminal demo

Reference

[1] https://dgl.cx/2014/10/vim-blowfish
[2] http://vim.wikia.com/wiki/Encryption

About

Configuration scripts for enable secure encryption in VIM editor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages