This post is very old and likely contains information that is no longer accurate and links which no longer work. Proceed with caution.
So I was typing away in an ssh window today when for the billionth time I had
hit the END key expecting the cursor to jump to the end of the line, and it just
printed a ~
. As always, I just erased the character and then held down the arrow
until I was at the end of the line. However, seeing as it was the billionth
time I decided to figure out how to make it actually do what I want.
Not that I didn’t really know how to make it do what I want, I’ve just always been too lazy to actually look up the escape codes and such for the home and end keys, and then actually create the entries to fix it. So for the benefit of any other fellow lazy people, here’s what you need to do:
Create ~/.inputrc
and put this in it:
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\eOH": beginning-of-line
"\eOF": end-of-line
"\e[H": beginning-of-line
"\e[F": end-of-line
That should cover most of the bases terminal-wise.
And to make sure that home/end work in Vi, this is what I added to .exrc
:
map [CTRL-V] [HOME] ^
map [CTRL-V] [END] $
When I say [CTRL-V]
I mean actually press the keys ctrl
and v
, not type
that out, of course.
There are probably better ways to accomplish this, but this worked for me. Feel free to suggest a more elegant solution.
Just a note, using the .exrc
above can break vi
in some consoles (I noticed
it in Konsole under X). So just be careful where it’s used.