Vim and gpg

76 views
Skip to first unread message

ega...@gmail.com

unread,
May 14, 2016, 2:35:40 PM5/14/16
to vim_use

Hi,
it makes many years that I am using vim to open a text file which is encrypted by gpg. To this aim, in my .vimrc I have the following:

augroup encrypted
" Support for transparent editing of gpg (symmetric) encrypted files
au!
" Make sure nothing is written to ~/.viminfo while editing an encrypted file.
autocmd BufReadPre,FileReadPre *.asc,*.gpg set viminfo=
" We don't want a swap file, as it writes unencrypted data to disk
autocmd BufReadPre,FileReadPre *.asc,*.gpg set noswapfile
" Switch to binary mode to read the encrypted file
autocmd BufReadPre,FileReadPre *.asc,*.gpg set bin
autocmd BufReadPre,FileReadPre *.asc,*.gpg let ch_save = &ch|set ch=2
autocmd BufReadPost,FileReadPost *.asc,*.gpg '[,']!gpg --decrypt 2> /dev/null
" Switch to normal mode for editing
autocmd BufReadPost,FileReadPost *.asc,*.gpg set nobin
autocmd BufReadPost,FileReadPost *.asc,*.gpg set foldmethod=indent
autocmd BufReadPost,FileReadPost *.asc,*.gpg hi Folded term=standout ctermfg=2 ctermbg=0
autocmd BufReadPost,FileReadPost *.asc,*.gpg let &ch = ch_save|unlet ch_save
autocmd BufReadPost,FileReadPost *.asc,*.gpg execute ":doautocmd BufReadPost " . expand("%:r")
" Convert all text to encrypted text before writing
autocmd BufWritePre,FileWritePre *.asc %!gpg -a -c 2>/dev/null
autocmd BufWritePre,FileWritePre *.gpg %!gpg -c 2>/dev/null
" Undo the encryption so we are back in the normal text, directly after the file has been written.
autocmd BufWritePost,FileWritePost *.asc,*.gpg u
augroup END


All the above worked seamlessly throughout all the upgrades I made over the years to the underlying linux distribution.
Up to now... :(
Now I upgraded to Ubuntu 16.04 and there it does not work anymore.
To be more precise, using plain vim (my preferred), sometime it works, but most of the times it doesn't and to help debugging I can add the following: when I open my file (say: vim r.txt.asc) the prompt I get is:

"r.txt.asc" 100L, 6206C
Enter passphrase:

In this case, it doesn't work.
Sometimes I get a different prompt, which looks like an error, that is:

"r.txt.asc" 100L, 6206C
^[[2;2REnter passphrase:

In these cases, it works!

Does anybody have any hint?

Thanks



Christian Brabandt

unread,
May 14, 2016, 2:51:12 PM5/14/16
to vim_use
Hi egalua!
Yeah, it looks like those terminal ansi escape sequences are sent to the
gpg program, therefore breaking your password. You might try with a
different terminal or trying, if any of those settings circumvents this
problem

:set term=builtin_ansi
:set t_RV=
:set t_u7=


Best,
Christian
--
Frage an Radio Eriwan: "Stimmt es, daß in den USA jeder ein Auto hat?"
Antwort: "Im Prinzip ja, aber bei uns hat dafür jeder einen Parkplatz."

Mario D

unread,
May 15, 2016, 10:03:41 AM5/15/16
to vim_use

> You might try with a different terminal or trying, if any of those settings
> circumvents this problem
>
> :set term=builtin_ansi
> :set t_RV=
> :set t_u7=
>

Yes: the first setting seems to do the job.
I added the line

autocmd BufReadPre,FileReadPre *.asc,*.gpg set term=builtin_ansi

in my .vimrc and everything seems to work nicely. Sure, this way I am stick to a somewhat primitive set of colors for syntax highlighting while editing encrypted files, but I can cope with this.... :)

Many thanks

Eric Christopherson

unread,
May 15, 2016, 4:55:13 PM5/15/16
to vim...@googlegroups.com
As a workaround (without forcing term=builtin_ansi), do you have any
success if you hit backspace a bunch of times at the password prompt,
before you start typing the password?


--
Eric Christopherson

Mario D

unread,
May 16, 2016, 9:18:58 AM5/16/16
to vim_use
> As a workaround (without forcing term=builtin_ansi), do you have any
> success if you hit backspace a bunch of times at the password prompt,
> before you start typing the password?

Yes: this works. If I remove forcing the term and I hit backspace a few times, then I can edit the file properly.

I really would like to understand why this happens: it looks like there is a reason but I am not able to guess it.

It doesn't seem to depend on my settings: I created a brand new user without any prior custom setting and it is the same behaviour.

Eric Christopherson

unread,
May 18, 2016, 2:03:31 PM5/18/16
to vim_use
Does it happen when you run Vim in a terminal? Which terminal(s)? Try a few to narrow it down.

I'm guessing the 16.04 upgrade introduced a new behavior (bug) in the terminal you use. 
Reply all
Reply to author
Forward
0 new messages