Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Key bindings in Zsh?



On Aug 26,  9:30am, Brian P. Barnes wrote:
} Subject: Key bindings in Zsh?
}
} My insert/delete/home/end/pgup/pgdn keys do not work in Zsh. They either
} give me a squiggle ('~'), a beep or do the wrong thing:
}     Insert, pgup, pgdn -> ~
}     home, end                 -> beep

What exactly do you think they should do?

Zsh has generally avoided the issue of bindings for things like the arrow
keys, the keypad, and function keys because terminals and keyboards vary
so widely and termcap/terminfo have historically been untrustworthy.  The
vt100-compatible arrow-key bindings are all that's ever been bound by
default.

There has been some discussion of initializing more from the terminal
databases, but the question of what they should mean remains -- what is
a "page" at a command line prompt?  Does "Home" go all the way to the
beginning of the history, or (as you seem to expect) just to beginning
of line?  Etc.

}     delete                        -> backspace

That one's intentional; many keyboards have delete and backspace swapped,
so zsh has always made them behave identically.

} The keys work in other tools I use including Vim and Netscape so I don't
} think I want to alter my Xmodmap.

Zsh is not an X11 program and does not receive X11 keyboard events; it
gets whatever sequence of characters the terminal or terminal emulator
decides to send it.  So your X mappings and what Netscape does are both
largely irrelevant.

} The Zsh manual makes a glancing reference to "use zle -N" in reference
} to using user-defined widgets implemented as shell functions to execute
} key mapping.  There appears to be no documentation for this function

Which zsh manual?  The texinfo doc for 3.1.6 has an entire section "The
zle Module" devoted to this, in which you'd have discovered that what you
want is not "zle" anyway, but rather "bindkey".  If you're using 3.0.6 or
earlier, you want the section "Shell Builtin Commands", but 3.0 doc should
not mention "zle -N" at all.

In both cases, the set of actions (widgets) that can be bound to keys are
described in the "Zsh Line Editor" section.

You could also have tried searching the archives of this mailing list at
<http://www.zsh.org/mla/>.

} I tried adding the following to my .zshrc file: `zle -N END end-of-line`

That creates a new zle "widget" named END which calls the function named
end-of-line when the key to which it is bound is pressed.  It doesn't bind
it to any key, though: you need "bindkey" for that.

You probably want something in .zshrc like

	case $TERM in
	xterm)
	    bindkey '\eOH' beginning-of-line
	    bindkey '\eOF' end-of-line
	    bindkey '\e[2~' overwrite-mode
	    bindkey '\e[5~' beginning-of-buffer-or-history
	    bindkey '\e[6~' end-of-buffer-or-history
	    ;;
	aixterm)
	    # similar commands but with aixterm sequences
	    ;;
	# and so on for other terminal types
	esac


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author