You are not logged in.

#1 2011-01-12 19:41:46

misc
Member
From: Bavaria, Germany
Registered: 2010-03-22
Posts: 115

key codes / bindkey / zsh

Regarding e. g. the key codes (like "\e[5D") given in this section of zsh's ArchWiki page. How can one find out which actual keys they represent (and vice versa)? dumpkeys for instance does not appear to yield all of them, or at least not in that format.

Last edited by misc (2011-01-14 19:55:59)

Offline

#2 2011-01-12 20:36:34

Lachkater
Member
From: Germany
Registered: 2008-02-04
Posts: 40

Re: key codes / bindkey / zsh

Press CTRL+v and then a key and you get that keys keycode.

Offline

#3 2011-01-13 00:38:08

misc
Member
From: Bavaria, Germany
Registered: 2010-03-22
Posts: 115

Re: key codes / bindkey / zsh

Lachkater wrote:

Press CTRL+v and then a key and you get that keys keycode.

That does not work with certain keys (alt, shift etc.), though. Thanks still.

Offline

#4 2011-01-13 02:40:29

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: key codes / bindkey / zsh

1) escape sequences may differ by terminal
2) i do not think any terminal has sequences for alt, shift, etc.
3) nice hat

Last edited by fsckd (2011-01-13 02:41:00)


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#5 2011-01-13 22:55:05

misc
Member
From: Bavaria, Germany
Registered: 2010-03-22
Posts: 115

Re: key codes / bindkey / zsh

1) So… no way to find out which keys the sequences as given e. g. in the wiki represent? (Couldn't somebody who uses them just write it down, please?)

I have urxvt as terminal; the extra sequences with "For rxvt" as comment lead me to think that the rest must be compatible.

2) kk

3) Thanks!

Offline

#6 2011-01-14 16:02:27

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: key codes / bindkey / zsh

There is a database but it's sort of incomplete. These things are called terminal capabilities and can be accessed from a curses library (e.g. ncurses) or using tput if in a shell script. I use the utility infocmp to see the entries for a specific terminal. For example, `infocmp xterm`.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#7 2011-01-14 19:28:48

thestinger
Package Maintainer (PM)
From: Toronto, Canada
Registered: 2010-01-23
Posts: 478

Re: key codes / bindkey / zsh

The clean way to do it is to use man terminfo and then use zsh's terminfo feature.

example:

if [[ -n $terminfo[khome] ]]; then
    bindkey          "$terminfo[khome]" vi-beginning-of-line
    bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
fi

This works for pretty much every terminal, but xterm has application/cursor modes and zsh won't follow that by default, but you can fix xterm with something like this:

# make zsh/terminfo work for terms with application and cursor modes
case "$TERM" in
    xterm*)
        zle-line-init() { zle-keymap-select; echoti smkx }
        zle-line-finish() { echoti rmkx }
        zle -N zle-line-init
        zle -N zle-line-finish
    ;;
esac

Last edited by thestinger (2011-01-14 19:29:25)

Offline

#8 2011-01-16 13:08:12

misc
Member
From: Bavaria, Germany
Registered: 2010-03-22
Posts: 115

Re: key codes / bindkey / zsh

Thanks everybody for the answers. I still don't fully know how to interpret the sequences in the wiki, but should be able to set up the keys in my zshrc (there's also an article on bindkeys in the ZshWiki) appropriately.

Offline

#9 2011-01-17 23:43:50

m4co
Member
Registered: 2009-12-29
Posts: 117
Website

Re: key codes / bindkey / zsh

I just got this tip at #archlinux from fryguy:

$ cat
<hit the key you want here>

copy the code and it works


Don't panic !

Offline

Board footer

Powered by FluxBB