zsh-users
 help / color / mirror / code / Atom feed
* Key bindings not working under screen
@ 2011-02-15 10:55 Thorsten Kampe
  2011-02-15 11:16 ` Thorsten Kampe
  2011-02-15 15:44 ` Bart Schaefer
  0 siblings, 2 replies; 11+ messages in thread
From: Thorsten Kampe @ 2011-02-15 10:55 UTC (permalink / raw)
  To: zsh-users

Hello,

I would like to ask for assistance trying to solve a problem with zsh 
under screen where key bindings are not working (for instance
"bindkey '^[-' copy-prev-shell-word" in .zshrc).

This is the problem: in my .zshrc (and .bashrc) I set editor variables 
to JED (if installed) or to Vim:

#
type jed &> /dev/null && DEFAULT_EDITOR=jed || DEFAULT_EDITOR=vim
export EDITOR=$DEFAULT_EDITOR \
       VISUAL=$DEFAULT_EDITOR
#

On systems where JED is not installed (-> DEFAULT_EDITOR=vim) I can 
observe this:

% bindkey | wc -l
147
% bindkey | grep copy-prev-shell-word
"^[-" copy-prev-shell-word
% screen
% bindkey | wc -l
131
% bindkey | grep copy-prev-shell-word
%

I've renamed my .screenrc but the issue remains. Interestingly it only 
happens when I set $EDITOR *and* $VISUAL in .zshrc, only under screen 
and only with zsh (not bash).

Can someone shed some light about the connection between $EDITOR, 
$VISUAL, zsh and screen?


Thorsten
[zsh 4.3.11 on Cygwin (XP, 7 and 2008 R2) and on Gentoo Linux,
GNU screen 4.0.3]


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-15 10:55 Key bindings not working under screen Thorsten Kampe
@ 2011-02-15 11:16 ` Thorsten Kampe
  2011-02-15 15:49   ` Bart Schaefer
  2011-02-15 15:44 ` Bart Schaefer
  1 sibling, 1 reply; 11+ messages in thread
From: Thorsten Kampe @ 2011-02-15 11:16 UTC (permalink / raw)
  To: zsh-users

* Thorsten Kampe (Tue, 15 Feb 2011 11:55:01 +0100)
> Can someone shed some light about the connection between $EDITOR, 
> $VISUAL, zsh and screen?

I've kind of worked around the issue now by changing
#
type jed &> /dev/null && DEFAULT_EDITOR=jed || DEFAULT_EDITOR=vim
export EDITOR=$DEFAULT_EDITOR \
       VISUAL=$DEFAULT_EDITOR
#
to...
#
type jed &> /dev/null && DEFAULT_EDITOR=jed
export EDITOR=$DEFAULT_EDITOR \
       VISUAL=$DEFAULT_EDITOR
#

"vi" is the default anyway and setting it to "vim" was intended to have 
a full featured Vim as editor and not a compatibility restricted vi 
('Start Vim  in Vi mode, just like the executable was called "vi".')

Thorsten


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-15 10:55 Key bindings not working under screen Thorsten Kampe
  2011-02-15 11:16 ` Thorsten Kampe
@ 2011-02-15 15:44 ` Bart Schaefer
  2011-02-15 18:59   ` Thorsten Kampe
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2011-02-15 15:44 UTC (permalink / raw)
  To: zsh-users

On Feb 15, 11:55am, Thorsten Kampe wrote:
}
} On systems where JED is not installed (-> DEFAULT_EDITOR=vim) I can 
} observe this:
} 
} % bindkey | wc -l
} 147
} % bindkey | grep copy-prev-shell-word
} "^[-" copy-prev-shell-word
} % screen
} % bindkey | wc -l
} 131
} % bindkey | grep copy-prev-shell-word
} %
} 
} I've renamed my .screenrc but the issue remains. Interestingly it only 
} happens when I set $EDITOR *and* $VISUAL in .zshrc, only under screen 
} and only with zsh (not bash).
} 
} Can someone shed some light about the connection between $EDITOR, 
} $VISUAL, zsh and screen?

Zsh attempts to initialize the ZLE mode based on VISUAL if it is set
and EDITOR if it VISUAL is not.  If whichever of those is chosen looks
like a variant of "vi" then ZLE initializes with vi-style key bindings,
otherwise it initializes with emacs-style key bindings.

Probably what's happening is that when you log in, VISUAL and EDITOR
are not set, and ZLE initializes in emacs mode.  When you then start
screen, those variables are in the environment and ZLE initializes in
vi mode.

I further suspect that some of your bindkey settings are always ending
up in the emacs keymap, even when ZLE is in vi mode.  Have you tried
capturing the bindkey output in a file in each case and diffing them?


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-15 11:16 ` Thorsten Kampe
@ 2011-02-15 15:49   ` Bart Schaefer
  2011-02-15 18:19     ` Thorsten Kampe
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2011-02-15 15:49 UTC (permalink / raw)
  To: zsh-users

Hmm, just saw this after sending previous reply ...

On Feb 15, 12:16pm, Thorsten Kampe wrote:
}
} I've kind of worked around the issue now by changing
} to...
} #
} type jed &> /dev/null && DEFAULT_EDITOR=jed
} export EDITOR=$DEFAULT_EDITOR \
}        VISUAL=$DEFAULT_EDITOR
} #
} 
} "vi" is the default anyway

Really?  The above would fit my theory from the first reply if in fact
there is no value for VISUAL/EDITOR, but if either of them is "vi" by
default then ZLE should be picking that up and starting in viins all
the time, regardless of screen, and we need to look elsewhere for the
problem.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-15 15:49   ` Bart Schaefer
@ 2011-02-15 18:19     ` Thorsten Kampe
  0 siblings, 0 replies; 11+ messages in thread
From: Thorsten Kampe @ 2011-02-15 18:19 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer (Tue, 15 Feb 2011 07:49:22 -0800)
> On Feb 15, 12:16pm, Thorsten Kampe wrote:
> }
> } I've kind of worked around the issue now by changing
> } to...
> } #
> } type jed &> /dev/null && DEFAULT_EDITOR=jed
> } export EDITOR=$DEFAULT_EDITOR \
> }        VISUAL=$DEFAULT_EDITOR
> } #
> } 
> } "vi" is the default anyway
> 
> Really?  The above would fit my theory from the first reply if in fact
> there is no value for VISUAL/EDITOR, but if either of them is "vi" by
> default then ZLE should be picking that up and starting in viins all
> the time, regardless of screen, and we need to look elsewhere for the
> problem.

I meant that most Linux distributions have vi as their default editor, 
so whenever you something or someone uses an editor without having 
anything specifically configured, it will probably be vi.

Thorsten



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-15 15:44 ` Bart Schaefer
@ 2011-02-15 18:59   ` Thorsten Kampe
  2011-02-16  3:51     ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Thorsten Kampe @ 2011-02-15 18:59 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer (Tue, 15 Feb 2011 07:44:53 -0800)
> On Feb 15, 11:55am, Thorsten Kampe wrote:
> } On systems where JED is not installed (-> DEFAULT_EDITOR=vim) I can 
> } observe this:
> } 
> } % bindkey | wc -l
> } 147
> } % bindkey | grep copy-prev-shell-word
> } "^[-" copy-prev-shell-word
> } % screen
> } % bindkey | wc -l
> } 131
> } % bindkey | grep copy-prev-shell-word
> } %
> } 
> } I've renamed my .screenrc but the issue remains. Interestingly it only 
> } happens when I set $EDITOR *and* $VISUAL in .zshrc, only under screen 
> } and only with zsh (not bash).
> } 
> } Can someone shed some light about the connection between $EDITOR, 
> } $VISUAL, zsh and screen?
> 
> Zsh attempts to initialize the ZLE mode based on VISUAL if it is set
> and EDITOR if it VISUAL is not.  If whichever of those is chosen looks
> like a variant of "vi" then ZLE initializes with vi-style key bindings,
> otherwise it initializes with emacs-style key bindings.
> 
> Probably what's happening is that when you log in, VISUAL and EDITOR
> are not set, and ZLE initializes in emacs mode.

I actually setopt emacs and no_vi in my .zshrc (but before setting 
VISUAL and EDITOR).

> When you then start screen, those variables are in the environment and
> ZLE initializes in vi mode.
> 
> I further suspect that some of your bindkey settings are always ending
> up in the emacs keymap, even when ZLE is in vi mode.  Have you tried
> capturing the bindkey output in a file in each case and diffing them?

"^I" complete-word -> expand-or-complete
"^[-" copy-prev-shell-word -> neg-argument

"^[O5C" forward-word [deleted]
"^[O5D" backward-word [deleted]

"^[Oc" forward-word [deleted]
"^[Od" backward-word [deleted]

"^[[1;5C" forward-word [deleted]
"^[[1;5D" backward-word [deleted]
"^[[1~" beginning-of-line [deleted]
"^[[3~" delete-char [deleted]
"^[[4~" end-of-line [deleted]
"^[[7~" beginning-of-line [deleted]
"^[[8~" end-of-line [deleted]

"^[[A" history-beginning-search-backward -> up-line-or-history
"^[[B" history-beginning-search-forward -> down-line-or-history

"^[[F" end-of-line [deleted]
"^[[H" beginning-of-line [deleted]
"^[[a" up-line-or-beginning-search [deleted]
"^[[b" down-line-or-beginning-search [deleted]

"^[q" push-line-or-edit -> push-line

" " global-alias-space [deleted]
"!"-"~" self-insert -> " "-"~" self-insert

As far as I can see, these are all from my .zshrc (the deleted ones and 
the ones before the "->"):

##
bindkey '^i'      complete-word
bindkey '^[q'     push-line-or-edit
bindkey '^[-'     copy-prev-shell-word
bindkey '\e[3~'   delete-char
bindkey '\e[A'    history-beginning-search-backward
bindkey '\e[B'    history-beginning-search-forward

# xterm/rxvt ("od -c")               # [Ctrl][V]
bindkey '\eOd'    backward-word      # '^[Od'
bindkey '\eOc'    forward-word       # '^[Oc'
bindkey '\e[7~'   beginning-of-line  # '^[[7~'
bindkey '\e[8~'   end-of-line        # '^[[8~'

# Konsole
bindkey '\e[1;5D' backward-word
bindkey '\e[1;5C' forward-word
bindkey '\e[H'    beginning-of-line
bindkey '\e[F'    end-of-line

# GNOME Terminal
bindkey '\eO5D'   backward-word
bindkey '\eO5C'   forward-word

autoload up-line-or-beginning-search \
         down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey '\e[a'  up-line-or-beginning-search
bindkey '\e[b'  down-line-or-beginning-search

# Cygwin and Linux Console return the same keycode for [Ctrl][Key],
# shifted and unshifted
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line

# Bart Schaefer
autoload -Uz match-words-by-style
global-alias-space()
    { emulate -LR zsh
      match-words-by-style -w shell
      local ga=$matched_words[2]
      if [[ -n $ga ]]; then
          matched_words[2]="${${galiases[$ga]}:-$ga}"
          LBUFFER="${(j::)matched_words[1,3]}"
      fi
      zle .self-insert;}

zle -N global-alias-space
bindkey ' ' global-alias-space

accept-line()
    { emulate -LR zsh
      match-words-by-style -w shell
      local ga=$matched_words[2]
      if [[ -n $ga && ( -n $matched_words[4] || -z $matched_words[5] ) 
]]; then
          matched_words[2]="${${galiases[$ga]}:-$ga}"
          LBUFFER="${(j::)matched_words[1,3]}"
      fi
      zle .accept-line;}

zle -N accept-line
##


Thorsten


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-15 18:59   ` Thorsten Kampe
@ 2011-02-16  3:51     ` Bart Schaefer
  2011-02-16 11:41       ` Thorsten Kampe
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2011-02-16  3:51 UTC (permalink / raw)
  To: zsh-users

On Feb 15,  7:59pm, Thorsten Kampe wrote:
}
} > I further suspect that some of your bindkey settings are always ending
} > up in the emacs keymap, even when ZLE is in vi mode.  Have you tried
} > capturing the bindkey output in a file in each case and diffing them?
} 
} As far as I can see, these are all from my .zshrc (the deleted ones and 
} the ones before the "->"):

That would appear to mean that sourcing your .zshrc file is stopping
before reaching the end.  Try something like

# at the top of .zshrc
exec 2> /tmp/zshrc$$
setopt xtrace

# at the bottom of .zshrc
exec 2>&1
setopt noxtrace

See if it ever reaches that last, for one thing.  Either way examine the
trace file to see if your bindkey commands are ever being executed.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-16  3:51     ` Bart Schaefer
@ 2011-02-16 11:41       ` Thorsten Kampe
  2011-02-16 17:01         ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Thorsten Kampe @ 2011-02-16 11:41 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer (Tue, 15 Feb 2011 19:51:21 -0800)
> On Feb 15,  7:59pm, Thorsten Kampe wrote:
> } > I further suspect that some of your bindkey settings are always > 
> } > ending
> } > up in the emacs keymap, even when ZLE is in vi mode.  Have you tried
> } > capturing the bindkey output in a file in each case and diffing them?
> } 
> } As far as I can see, these are all from my .zshrc (the deleted ones and 
> } the ones before the "->"):
> 
> That would appear to mean that sourcing your .zshrc file is stopping
> before reaching the end.  Try something like
> 
> # at the top of .zshrc
> exec 2> /tmp/zshrc$$
> setopt xtrace
> 
> # at the bottom of .zshrc
> exec 2>&1
> setopt noxtrace
> 
> See if it ever reaches that last, for one thing.  Either way examine the
> trace file to see if your bindkey commands are ever being executed.

It reaches the end ("setopt noxtrace") in both cases (screen call in 
.zlogin and without) and the generated log files in $TMP (zshrcnnnn) are 
exactly the same...

Thorsten


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-16 11:41       ` Thorsten Kampe
@ 2011-02-16 17:01         ` Bart Schaefer
  2011-02-25 16:56           ` Thorsten Kampe
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2011-02-16 17:01 UTC (permalink / raw)
  To: zsh-users

On Feb 16, 12:41pm, Thorsten Kampe wrote:
} Subject: Re: Key bindings not working under screen
}
} > # at the top of .zshrc
} > exec 2> /tmp/zshrc$$
} > setopt xtrace
} 
} It reaches the end ("setopt noxtrace") in both cases (screen call in 
} .zlogin and without) and the generated log files in $TMP (zshrcnnnn) are 
} exactly the same...

Then it's time to look for something in /etc/zlogin or ~/.zlogin that
may be causing it (assuming screen starts zsh as a login shell).  If
that's not the problem the only thing I could suggest is to create a
verbose shell function wrapper for bindkey, something like

    zmodload -i zsh/parameter
    bindkey() {
      print -u2 -- "$functrace[@]": bindkey "$@"
      builtin bindkey "$@"
    }

and install that very early, perhaps in ~/.zshenv.

-- 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-16 17:01         ` Bart Schaefer
@ 2011-02-25 16:56           ` Thorsten Kampe
  2011-02-26 20:09             ` Hemant Borole
  0 siblings, 1 reply; 11+ messages in thread
From: Thorsten Kampe @ 2011-02-25 16:56 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer (Wed, 16 Feb 2011 09:01:21 -0800)
> 
> On Feb 16, 12:41pm, Thorsten Kampe wrote:
> } Subject: Re: Key bindings not working under screen
> }
> } > # at the top of .zshrc
> } > exec 2> /tmp/zshrc$$
> } > setopt xtrace
> } 
> } It reaches the end ("setopt noxtrace") in both cases (screen call in 
> } .zlogin and without) and the generated log files in $TMP (zshrcnnnn) are 
> } exactly the same...
> 
> Then it's time to look for something in /etc/zlogin or ~/.zlogin that
> may be causing it (assuming screen starts zsh as a login shell).  If
> that's not the problem the only thing I could suggest is to create a
> verbose shell function wrapper for bindkey, something like
> 
>     zmodload -i zsh/parameter
>     bindkey() {
>       print -u2 -- "$functrace[@]": bindkey "$@"
>       builtin bindkey "$@"
>     }
> 
> and install that very early, perhaps in ~/.zshenv.

I decided not to continue at this point since not setting EDITOR to vim 
fixes the issue.

Thanks, Thorsten


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Key bindings not working under screen
  2011-02-25 16:56           ` Thorsten Kampe
@ 2011-02-26 20:09             ` Hemant Borole
  0 siblings, 0 replies; 11+ messages in thread
From: Hemant Borole @ 2011-02-26 20:09 UTC (permalink / raw)
  To: Thorsten Kampe; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1357 bytes --]

move $HOME/.zsh* to some place. logout and log back in. Let the zsh config
rerun and then everything appears to work, with the EDITOR set to vi in
.zshrc


On Fri, Feb 25, 2011 at 8:56 AM, Thorsten Kampe
<thorsten@thorstenkampe.de>wrote:

> * Bart Schaefer (Wed, 16 Feb 2011 09:01:21 -0800)
> >
> > On Feb 16, 12:41pm, Thorsten Kampe wrote:
> > } Subject: Re: Key bindings not working under screen
> > }
> > } > # at the top of .zshrc
> > } > exec 2> /tmp/zshrc$$
> > } > setopt xtrace
> > }
> > } It reaches the end ("setopt noxtrace") in both cases (screen call in
> > } .zlogin and without) and the generated log files in $TMP (zshrcnnnn)
> are
> > } exactly the same...
> >
> > Then it's time to look for something in /etc/zlogin or ~/.zlogin that
> > may be causing it (assuming screen starts zsh as a login shell).  If
> > that's not the problem the only thing I could suggest is to create a
> > verbose shell function wrapper for bindkey, something like
> >
> >     zmodload -i zsh/parameter
> >     bindkey() {
> >       print -u2 -- "$functrace[@]": bindkey "$@"
> >       builtin bindkey "$@"
> >     }
> >
> > and install that very early, perhaps in ~/.zshenv.
>
> I decided not to continue at this point since not setting EDITOR to vim
> fixes the issue.
>
> Thanks, Thorsten
>
>


-- 
Hemant Borolé

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-02-26 20:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-15 10:55 Key bindings not working under screen Thorsten Kampe
2011-02-15 11:16 ` Thorsten Kampe
2011-02-15 15:49   ` Bart Schaefer
2011-02-15 18:19     ` Thorsten Kampe
2011-02-15 15:44 ` Bart Schaefer
2011-02-15 18:59   ` Thorsten Kampe
2011-02-16  3:51     ` Bart Schaefer
2011-02-16 11:41       ` Thorsten Kampe
2011-02-16 17:01         ` Bart Schaefer
2011-02-25 16:56           ` Thorsten Kampe
2011-02-26 20:09             ` Hemant Borole

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).