urxvt + zsh not cooperating with HOME and END keys

In other terminals, like xterm and konsole, the HOME and END keys perform the expected function of moving to the beginning or ending of a line, respectively. In urxvt, however, these key-presses resulted either appending a tilde to the end of the line or, if using zsh, converting the last letter of the line to uppercase. I Googled this problem extensively, and found the following solution, which I implemented in .inputrc

Code:
set completion-query-items 100
set completion-ignore-case on
set show-all-if-ambiguous off

set input-meta on
set output-meta on
set convert-meta off
set bell-style none

"\e[2~": paste-from-clipboard
"\e[3~": delete-char
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[7~": beginning-of-line
"\e[8~": end-of-line

This fixed the problem for urxvt + csh, but for zsh, the uppercase problem persists (I noticed that it also enters 'vi mode' after these key-presses because, for instance, x = delete) with the following bind setup in .zshrc:

Code:
*xterm*|(u)rxvt|(u|dt|k|E)term)
		bindkey '\e[1~' beginning-of-line
		bindkey '\e[3~' delete-char
		bindkey '\e[4~' end-of-line
		bindkey '\177' backward-delete-char
		bindkey '\e[2~' overwrite-mode
 
		bindkey "\e[7~" beginning-of-line
		bindkey "\e[H" beginning-of-line
		#bindkey "\e[2~" transpose-words
		bindkey "\e[8~" end-of-line
		bindkey "\e[F" end-of-line
		bindkey "\eOH" beginning-of-line
		bindkey "\eOF" end-of-line
		
		bindkey "^R" history-incremental-search-backward

Any suggestions?
 
Try running [cmd=""]cat[/cmd], press Home,End,.... keys and paste exactly what you get to your .zshrc
 
I get:

Code:
^[[7~^
for HOME

... and:

Code:
^[[8~

for END.

Which are already in my .zshrc (see above):

Code:
bindkey "\e[7~" beginning-of-line

bindkey "\e[8~" end-of-line
 
Well, works here... with:
Code:
# Created by newuser for 4.3.10

bindkey "^[[7~" beginning-of-line
bindkey "^[[8~" end-of-line
 
Thanks. I appended those to my list of binds in .zshrc, but still seeing the same behavior in urxvt :(
 
I solved this issue by setting the following in my .vimrc

Code:
set backspace=start,eol,indent
map <ESC>[8~    <End>
map <ESC>[7~    <Home>
imap <ESC>[8~    <End>
imap <ESC>[7~    <Home>
 
Try to force urxvt obey termcap(5) like xterm -kt tcap or fix your termcap file. IOW, Ctrl+V Home should match output from$ tput kh | od -a
It'll avoid having to invent workarounds for various ncurses applications like the one above for vim.

You can then bind keys in zsh like this
$ bindkey $(echotc kh) beginning-of-line
Such keybindings should work equally well under syscons, screen/tmux, xterm/urxvt, jfbterm even if raw escape sequences for function keys differ between them.
 
john_doe said:
Try to force urxvt obey termcap(5) like xterm -kt tcap or fix your termcap file. IOW, Ctrl+V Home should match output from$ tput kh | od -a
It'll avoid having to invent workarounds for various ncurses applications like the one above for vim.

You can then bind keys in zsh like this
$ bindkey $(echotc kh) beginning-of-line
Such keybindings should work equally well under syscons, screen/tmux, xterm/urxvt, jfbterm even if raw escape sequences for function keys differ between them.

Ok, let's 'pretend' that I'm dumb here, for a second ;) What exactly are you proposing to do? Your advice looks very useful, but I'm just not sure how to follow it.

Ctrl+V Home (in urxvt+zsh) produces this:

Code:
^[[7~

... while $ tput kh | od -a produces:

Code:
0000000  esc   [   7   ~                                                
0000004

urxvt doesn't seem to take '-kt tcap', and:

$ $ bindkey $(echotc kh) beginning-of-line

... produces:

Code:
zsh: bad pattern: ^[[7~

Interestingly, the same error message appears after hitting carriage return after CTRL+V Home... so yeah, I don't know what to do next :p
 
purgatori said:
$ bindkey $(echotc kh) beginning-of-line
zsh: bad pattern: ^[[7~
Try enclosing the escape sequence with doublequotes
$ bindkey "$(echotc kh)" beginning-of-line
It works without doublequotes here, though.
Code:
$ zsh -f
$ bindkey $(echotc kh) beginning-of-line
$ bindkey $(echotc kh)
"^[[1~" beginning-of-line
$ bindkey ^[[1~
zsh: bad pattern: ^[[1~
$ zsh --version
zsh 4.3.10 (amd64-portbld-freebsd9.0)
 
john_doe said:
Try enclosing the escape sequence with doublequotes
$ bindkey "$(echotc kh)" beginning-of-line
It works without doublequotes here, though.
Code:
$ zsh -f
$ bindkey $(echotc kh) beginning-of-line
$ bindkey $(echotc kh)
"^[[1~" beginning-of-line
$ bindkey ^[[1~
zsh: bad pattern: ^[[1~
$ zsh --version
zsh 4.3.10 (amd64-portbld-freebsd9.0)

Using quotes seems to work :) How do I make the change permanent, though? I tried putting the same line in my .zshrc, but it doesn't seem to have the same effect -- also, how do I do this for the other keys, like END, DEL, etc.?

########

EDIT: After consulting the zsh-wiki, it appears that I have found a solution to my problem. I replaced the bindings previously defined in my .zshrc with the $terminfo solution offered here, and now HOME, END, and DEL are all behaving as expected :) I don't understand how or why this fixed the problem, but I'm content that it has.

Thanks to everyone in this thread who took the time to offer their assistance.
 
Have similar problem, but with /bin/csh,
my /etc/csh.cshrc keybindings doesn't work with x11/rxvt-unicode (but they are working fine in x11/xterm or x11/stjerm).
Code:
bindkey '^[[3~'     delete-char           # delete key
bindkey '^[[1;5D'   backward-word         # ctrl+left
bindkey '^[[1;5C'   forward-word          # ctrl+right
bindkey '^[[3;5~'   delete-word           # ctrl+delete
("Delete" key is working fine, unlike ctrl+left and ctrl+right)

Maybe somebody has a solution?
 
Last edited by a moderator:
Back
Top