Home and End keys not working
Why don't my Home and End keys work in terminals?
A: This is a common problem that seems to have multiple causes. There may be issues with the readline library, but it seems that the default
/etc/inputrc fixes these, at least in emacs mode.
The problem still seems to exist with ncurses based applications including less, nano, and centericq (to name but a few). These do not appear to use the readline library, or do not use the inputrc mappings.
The solution seems to be to have the proper setting of the
TERM variable. This may take some experimenting by looking in the /usr/share/terminfo/* directories. Each entry is a potential setting of the
In xterm setting
TERM=xterm-color DOES NOT solve the Home/End issues. This is often the default
TERM setting people recommend.
TERM=xterm-xfree86 seems to solve the problem. If you use the linux console instead of a terminal emulator, setting
TERM=linux seems to solve the problem. You can do this each time you start a terminal, or export it in your
Other terminals, including konsole, and rxvt have several entries in the terminfo database that you may need to experiment with. If you find a suitable
TERM setting for your favourite terminal, please enter it into this wiki file.
If you use a resource-based terminal such as xterm, rxvt, and aterm, another (better) way of solving the problem is to add
xterm*termName: xterm-xfree86 to your
~/.Xdefaults, and to add
xrdb ~/.Xdefaults to your
If you use KDE's Konsole, you can open the
Settings -> Configure Konsole menu item, click the
Session tab, select
Shell from the
Session list, and change the value of the
$TERM textfield to
Xorg users can try to set the
$TERM value to
xterm-xf86-v40. This one fix the home/end keys and prevent display corruption on nano and maybe other apps.
However, some urxvt (rxvt-unicode) users might still have problems after that. Adding the following to
~/.Xdefaults solves the problem
URxvt*keysym.Home: \e[1~ URxvt*keysym.End: \e[4~
In order to get the
END keys work properly in
less when using
TERM environmental variable must be set to
rxvt. You can test this on the fly by typing.
$ export TERM=rxvt-color $ export COLORTERM=rxvt
The above is what worked in my particular situation. I originally had the
COLORTERM environmental variable set to
rxvt. I believe it is set that way by installation of rxvt through pacman by default. So it may not be necessary to set that. It may even be superfluous. I'm am not sure. So I would recommend that you expirement to see if it's truly necessary. For me, what got the keys working right was the changing of
You may want to first check to see what your current environmental variables are for this.
$ printenv | grep TERM
If that doesn't work then you may want to try using
lesskey to instruct
less how handle the keys (in theory shouldn't be necessary since less uses these keys by default, unless of course, you want them binded to something other than their default actions). This was another step that I had done prior to all of the above. It may not have been necessary and did not seem to get the keys working until the
TERM environmental variable was set how I outlined here.
If this ends up working for you and you decide you want to make it permanent, so that whenever you open up
rxvt, then it must be added to an appropriate bash init script. One example of this is by adding it to your
$ echo 'export TERM=rxvt' >> ~/.bashrc
This should append it to the file. Another way is to open up the file with your favorite editor and edit manually (safer method that prevents possible clobbering from a typo etc.). This example is user specific and will set that variable whenever you open up an
rxvt terminal in X. Some may prefer to have it act more globally so, that as new users are added, it will be in effect for them as well. reference the bash man page for details of how to do that. However, doing so may prove to be cumbersome in cases where you use more than one type of terminal emulator program in X. This is unknown to me since I use rxvt almost exclusively. However, if you're using different terminal emulators in X, placing the above lines in your .bashrc file may not be ideal either depending upon what the other terminals in question need for their environmental variables. So it may be desirable to expirement with all of your consoles and terminals before making it permanent so that they all still exhibit the desired behavior and that this change isn't the cause of grief down road after you have forgotten that you changed one of your bash init scripts.