views:

2837

answers:

4

I'm running zsh as the default shell on a Ubuntu box, and everything works fine using gnome-terminal (which as far as I know emulates xterm). When I login from a windows box via ssh and putty (which also emulates xterm) suddendly the home/end keys no longer work.

I've been able to solve that adding these lines to my zshrc file...

bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line

...but I'm still wondering what's wrong here. Any idea?

+1  A: 

These bindings simply don't appear to be part of the default bindings set in emacs mode.

executing "where-is beginning-of-line" on my default zsh installation after running "bindkey -e" shows it is only bound to ^a. Perhaps you should ask the zsh developers why :-)

Sec
The default ubuntu install binds them in a global zshrc file, but as far as I can see the bindings don't work for putty.
agnul
A: 

It seems a putty thing. Gnome-terminal sends the codes ^[OH and ^[OF for Home and End respectively, while putty sends ^[[1~ and ^[[4~. There's an option in putty to change the Home/End keys from standard mode to rxvt mode, and that seems to fix the Home key, but not the End key (which now sends ^[Ow). Guess it's time to file a bug report somewhere... :-)

agnul
+5  A: 

I found it's a combination:

One

The ZSH developers do not think that ZSH should define the actions of the Home, End, Del, ... keys.

Debian and Ubuntu fix this by defining the normal actions the average user would expect in the global /etc/zsh/zshrc file. I've pasted the relevant code here: http://pastebin.com/f1d9dd5c6 (it get's messed up when I paste it as code in Stack Overflow). It is the same on Debian and Ubuntu.

So, if you are connecting to a Debian or Ubuntu box, you don't have to do anything. Everything should work automagically (if not, see below).

But... if you are connecting to another box (e.g. FreeBSD), their might be no user friendly default zshrc. The solution is of course to add the lines from the Debian/Ubuntu zshrc to your own .zshrc.

Two

Putty sends xterm as terminal type to the remote host. But messes up somewhere and doesn't send the correct control codes for Home, End, ... that one would expect from an xterm. Or an xterm terminal isn't expected to send those or whatever... (Del key does work in xterm however, if you configure it in ZSH). Also notice that your NUM pad keys act funny in Vim for example with xterm terminal.

The solution is to configure Putty to send another terminal type. I've tried xterm-color and linux. xterm-color fixed the Home/End problem, but the NUM pad was still funny. Setting it to 'linux' fixed both problems.

You can set terminal type in Putty under Connection -> Data. Do not be tempted to set your terminal type in your .zshrc with 'export TERM=linux', that is just wrong. The terminal type should be specified by your terminal app. So that if, for example, you connect from a Mac box with a Mac SSH client it can set it's own terminal type.

Notice that TERM specifies your terminal type and has nothing to do with the host you are connecting to. I can set my terminal type to linux in Putty and connect to FreeBSD servers without problems.

So, fix both these things and you should be fine :)

hopla
Another waay to fix the funny keypad behaviour: Open the session settins, go to `Terminal -> Features` and check the box labelled `Disable application keypad mode`. See here: http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter4.html#config-appkeypad
exhuma
A: 

On the PuTTY configuration dialog, go to Connection -> Data and type linux into the Terminal-type string before connecting.

Adam Pierce