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: , , , , , ,

0 Comments: