jamessan / vim-gnupg

This script implements transparent editing of gpg encrypted files.
http://www.vim.org/scripts/script.php?script_id=3645
727 stars 73 forks source link

Cannot move the cursor with arrow keys #17

Closed samuel-phan closed 9 years ago

samuel-phan commented 10 years ago

I cannot move the cursor with arrow keys after opening a .gpg file.

How to reproduce :

echo "hello world" > foo
gpg -c foo

Enter passphrase twice. Then :

vim foo.gpg

It asks for the passphrase, enter it. Once the file is decrypted in vim, the arrow keys don't move the cursor anymore. If you click on the left arrow key, you will get the error message :

E388: Couldn't find definition

Environment :

CentOS 6.5 : 2.6.32-431.17.1.el6.x86_64

VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Apr  5 2012 10:17:30)                                                                                                                                                                           
Included patches: 1-411                                                                                                                                                                                                                     
Modified by <bugzilla@redhat.com>                                                                                                                                                                                                           
Compiled by <bugzilla@redhat.com>                                                                                                                                                                                                           
Huge version without GUI.  Features included (+) or not (-):                                                                                                                                                                                
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent                                                                                                                                                                
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments                                                                                                                                                               
+cryptv +cscope +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic                                                                                                                                                                       
+emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path                                                                                                                                                                
+float +folding -footer +fork() +gettext -hangul_input +iconv +insert_expand                                                                                                                                                                
+jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap                                                                                                                                                              
+menu +mksession +modify_fname +mouse -mouseshape +mouse_dec +mouse_gpm                                                                                                                                                                     
-mouse_jsbterm +mouse_netterm -mouse_sysmouse +mouse_xterm +multi_byte                                                                                                                                                                      
+multi_lang -mzscheme -netbeans_intg -osfiletype +path_extra +perl +postscript                                                                                                                                                              
+printer +profile +python +quickfix +reltime +rightleft -ruby +scrollbind                                                                                                                                                                   
+signs +smartindent -sniff +startuptime +statusline -sun_workshop +syntax                                                                                                                                                                   
+tag_binary +tag_old_static -tag_any_white -tcl +terminfo +termresponse                                                                                                                                                                     
+textobjects +title -toolbar +user_commands +vertsplit +virtualedit +visual                                                                                                                                                                 
+visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup                                                                                                                                                                 
-X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save                                                                                                                                                                                      
   system vimrc file: "/etc/vimrc"                                                                                                                                                                                                          
     user vimrc file: "$HOME/.vimrc"                                                                                                                                                                                                        
      user exrc file: "$HOME/.exrc"                                                                                                                                                                                                         
  fall-back for $VIM: "/usr/share/vim"                                                                                                                                                                                                      
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall  -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64  -D_FORTIFY_SOURCE=1    -D_REENTRANT -D_GNU_SOURCE  -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -I/usr/lib64/perl5/CORE  -I/usr/include/python2.6 -pthread                                                                                             
Linking: gcc   -Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE   -L/usr/local/lib -o vim       -lselinux  -lncurses -lacl -lgpm   -Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE  -fstack-protector  -L/usr/lib64/perl5/CORE -lperl -lresolv -lutil -lc -L/usr/lib64/python2.6/config -lpython2.6 -lutil -lm -Xlinker -export-dynamic

If I set :

:set term=xterm

the arrow keys work again. Maybe it comes from the passphrase popup in the terminal, because I've also tried in a full MATE GUI environement, and the popup asking for passphrase is a MATE graphical one (not in the terminal like in CentOS) and there is no issue with arrow keys afterwards.

Any clue ?

jamessan commented 10 years ago

I've been able to confirm the behavior with Vim 7.4.273. Using xterm, I've been able to determine that the root cause is the terminal switching away from the alternate screen (which disables Application Cursor Keys (and Application Keypad)) and not switching back after the password prompt has completed.

  1. Run vim in an xterm
  2. Ctrl+MiddleClick and Show Alternate Screen will be checked
  3. :e foo.gpg and proceed through password dialog
  4. Ctrl+MiddleClick and Show Alternate Screen will be unchecked

Now to determine if this is a Vim bug or if it's something related to how the plugin loads the encrypted file.

jamessan commented 10 years ago

Actually, this looks like a bug in pinentry-curses. That doesn't seem to have been forwarded upstream. I'll see if I can get them to take a look at it.

I have a possible workaround that I can commit if that doesn't go anywhere soon.

jamessan commented 10 years ago

I'm not too keen on the workaround I had, and in talking to some other people more familiar with terminal programming, they seem to think this is Vim's fault for not restoring typical terminal settings before running the external command. I'll poke around with that idea some.

samuel-phan commented 10 years ago

Just for info:

On Linux Mint 17 (Ubuntu 14.04), the pb seems to be fixed:

$ dpkg --list | grep curses
ii  libncurses5:amd64                           5.9+20140118-1ubuntu1                               amd64        shared libraries for terminal handling
ii  libncurses5:i386                            5.9+20140118-1ubuntu1                               i386         shared libraries for terminal handling
ii  libncursesw5:amd64                          5.9+20140118-1ubuntu1                               amd64        shared libraries for terminal handling (wide character support)
ii  libncursesw5:i386                           5.9+20140118-1ubuntu1                               i386         shared libraries for terminal handling (wide character support)
ii  mtr-tiny                                    0.85-2                                              amd64        Full screen ncurses traceroute tool
ii  ncurses-base                                5.9+20140118-1ubuntu1                               all          basic terminal type definitions
ii  ncurses-bin                                 5.9+20140118-1ubuntu1                               amd64        terminal-related programs and man pages

On CentOS 7, the pb is still here:

$ rpm -qa | grep curses
ncurses-base-5.9-13.20130511.el7.noarch
ncurses-libs-5.9-13.20130511.el7.x86_64
ncurses-5.9-13.20130511.el7.x86_64
jamessan commented 10 years ago

Is there any difference in Vim version on those systems?

samuel-phan commented 10 years ago

On Linux Mint 17 (Ubuntu 14.04):

$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2 2014 19:39:47)
Included patches: 1-52
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by buildd@
Huge version with GTK2-GNOME GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
+balloon_eval    +float           +mouse_urxvt     -tag_any_white
+browse          +folding         +mouse_xterm     +tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
+clientserver    -hangul_input    +netbeans_intg   +title
+clipboard       +iconv           +path_extra      +toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con_gui  +lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      +X11
+dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     +xim
+emacs_tags      +mouseshape      -sniff           +xsmp_interact
+eval            +mouse_dec       +startuptime     +xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    +xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/harfbuzz   -pthread -DORBIT2=1 -D_REENTRANT -I/usr/include/libgnomeui-2.0 -I/usr/include/libart-2.0 -I/usr/include/gconf/2 -I/usr/include/gnome-keyring-1 -I/usr/include/libgnome-2.0 -I/usr/include/libbonoboui-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/gtk-2.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/x86_64-linux-gnu/gnome-vfs-2.0/include -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/orbit-2.0 -I/usr/include/libbonobo-2.0 -I/usr/include/bonobo-activation-2.0 -I/usr/include/libxml2 -I/usr/include/pango-1.0 -I/usr/include/gail-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/cairo -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/libpng12     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1     -I/usr/include/tcl8.6  -D_REENTRANT=1  -D_THREAD_SAFE=1  -D_LARGEFILE64_SOURCE=1  
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lgobject-2.0 -lglib-2.0 -lfreetype     -lgnomeui-2 -lSM -lICE -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lfreetype -lgconf-2 -lgthread-2.0 -lgmodule-2.0 -lgobject-2.0 -lglib-2.0   -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl/5.18/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions  -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lieee -lm -lruby-1.9.1 -lpthread -lrt -ldl -lcrypt -lm  -L/usr/lib   

On CentOS 7:

$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 10 2014 06:55:55)
Included patches: 1-160
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
-clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python/dyn      +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            +ruby/dyn        +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim74"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -L. -Wl,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE  -Wl,-z,relro  -L/usr/local/lib -Wl,--as-needed -o vim        -lm -lnsl  -lselinux  -lncurses -lacl -lattr -lgpm -ldl   -Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE  -fstack-protector  -L/usr/lib64/perl5/CORE -lperl -lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
jamessan commented 10 years ago

What about :set t_ti? in both?

samuel-phan commented 10 years ago

I don't understand what is the t_ti. Where should I put it ? In my .vimrc ?

Anyway, I've tried to put it in my .vimrc :

set t_ti

or to type it after the GPG passphrase prompt, it doesn't fix the bug on CentOS7 (I didn't test on Mint, since the issue seems to be fixed).

jamessan commented 10 years ago

Just run the command :set t_ti? from within Vim on both systems and post the output.

samuel-phan commented 10 years ago

On Linux Mint (in graphic mode, thus graphical passphrase prompt):

t_ti=^[[?1049h

In full console mode (Ctrl+Alt+F1), the t_ti is empty:

t_ti=

On CentOS 7 (connection to the VM via SSH):

t_ti=^[[?1049h
jamessan commented 10 years ago

On Linux Mint (in graphic mode, thus graphical passphrase prompt):

Gvim will never have the problem being discussed here because it's purely a terminal issue.

In full console mode (Ctrl+Alt+F1), the t_ti is empty: ... On CentOS 7 (connection to the VM via SSH):

Do either of these work properly?

samuel-phan commented 10 years ago

On Linux Mint 17, in full console mode (Ctrl+Alt+F1), the t_ti is empty and it works: I can move the cursor and save.

t_ti=

On Linux Mint 17, through an SSH connection without X11 forwarding (-x), thus having a ncurses passphrase prompt, it works as well : I can move the cursor and save.

t_ti=^[[?1049h

On CentOS 7, in full console mode, the t_ti is empty and it doesn't work.

t_ti=

I can move the cursor, but I can't save. When I enter :w, nothing happens, VIM seems not to respond anymore (eg when I press ESC, it prints ^[, etc.). I have to Ctrl+C to stop it, and exit by :q!. The reason seems to come from an unresponsive process /usr/bin/pinentry-curses that I cannot kill (SIGTERM). I need to kill it with a SIGKILL.

It is precisely when I try to save :w that the pinentry-curses spawns. If I open the file, enter the passphrase and quit right away, there is no pinentry-curses process, and I have no bug.

InAnimaTe commented 9 years ago

Just ran into this as well. :(

My vim starts with term=screen256-color when opening both normal files and encrypted files. With encrypted files, when I set term=xterm, my arrow keys work properly.

t_ti=^[[?1049h

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 3 2013 16:53:31)

jamessan commented 9 years ago

If I had a fix, I would have committed it. :) It looks like the simplest thing may be to just commit the workaround for now and try to figure out the bigger problem later.

blueyed commented 9 years ago

For reference: setting &term=&term triggers a bug in Vim, which breaks the X clipboard handling: https://groups.google.com/d/topic/vim_dev/flxuSDNp14I/discussion