How to get the Home & End keys working in remote Linux shells & terminals

Have you ever SSH'ed onto a remote linux server only to find that your Home and End keys don't take you to the start and end of the line and instead give you a rather unhelpful "~"?

One solution is to use CTRL-A instead of Home and CTRL-E instead of End but I wanted to solve it properly.

The linux command line is managed by readline. The configuration file for controlling key bindings (amongst other things) is /etc/inputrc. In Ubuntu this file contains a number of commented out sections relating to the Home and End keys. To find out which keycodes are being sent to readline when Home & End are pressed I used od - a stdin dump utility which can display ASCII characters or backslash escapes:

$ od -c

<Home key pressed> ^[[7~
<End key pressed> ^[[8~

The key bits here are the 7 and 8, these need to be entered at the very end of /etc/inputrc as follows:
"\e[7~": beginning-of-line
"\e[8~": end-of-line
After you've made these changes logout and back in again and now your Home & End keys should be working perfectly!

Technorati Tags: , , , , , ,


Lennart Rolland said...

Thanks a lot!

I read a lot of other howtos on this, but most were conserned with Mac OS/X and/or putty.

And the ones that spoke of regular ssh on a linux box only talked about setting the correct TERM variable (export TERM=linux was the fix-all solution they said.)

I really liked the od-c idea. i used od alot before, however i wasnt aware about the -c option.

So.. Thanks again!

abeacock said...

Glad it got you working Lennart, and thanks so much for posting back saying that you found it useful. Comments like this cause me to keep on blogging!